diff options
| author | Adam Soltys <[email protected]> | 2023-08-25 22:09:46 +0000 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-08-25 22:09:46 +0000 |
| commit | d7c3b24e06085fa6e7d59ec4f93f4af30edec08f (patch) | |
| tree | ea9730117dd7d4e4683048eeb0be1f162f7bd9d4 /lib | |
| parent | f2b4dfaa13f28a31b0f12bc2ba88b7ec4d484408 (diff) | |
| download | coinos-server-d7c3b24e06085fa6e7d59ec4f93f4af30edec08f.tar.gz coinos-server-d7c3b24e06085fa6e7d59ec4f93f4af30edec08f.zip | |
ffmpeg encode mp3
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/payments.js b/lib/payments.js index ab258b60..fb7d9cc6 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -11,6 +11,7 @@ import dollarsToWords from "dollars-to-words"; import got from "got"; import mqtt from "mqtt"; import { spawn } from "child_process"; +import ffmpeg from 'fluent-ffmpeg'; export const types = { internal: "internal", @@ -180,9 +181,28 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { parseFloat(((amount * p.rate) / 100000000).toFixed(2)) ); - const mimic = spawn("/mimic", ["-t", words, "-voice", "/cmu_us_axb.flitevox", "-o", `/app/data/uploads/${p.id}.wav`]); - const client = mqtt.connect('mqtt://ln.coinos.io', config.mqtt); + const raw = `/app/data/uploads/${p.id}-raw.mp3`; + const out = `/app/data/uploads/${p.id}.mp3`; + const mimic = spawn("/mimic", ["-t", words, "-voice", "/cmu_us_axb.flitevox", "-o", raw]); + + mimic.stdout.on("end", () => { + ffmpeg(raw) + .audioBitrate(128) + .audioFrequency(44100) + .toFormat('mp3') + .on('data', (chunk) => { + client.publish("mp3", chunk); + }) + .on('end', () => { + console.log('File has been re-encoded successfully.'); + }) + .on('error', (err) => { + console.error('Error:', err); + }) + .save(out); + }); + client.on('connect', function () { client.publish(username, `${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`); }); |
