aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js24
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}`);
});