diff --git a/index.js b/index.js index 675cd43..a68f705 100644 --- a/index.js +++ b/index.js @@ -83,7 +83,7 @@ const decodeTwoTone = (filePath) => { return; } // Proceed with Python process only after FFMPEG conversion is successful - const pythonProcess = spawn("python", ["twotonedec.py", wavFilePath]); + const pythonProcess = spawn("python3.12", ["twotonedec.py", wavFilePath]); let result = ""; pythonProcess.stdout.on("data", (data) => { @@ -152,62 +152,62 @@ conn.on("message", (data) => { console.log(`New Call ${globalSystems[parsed[1].system][parsed[1].talkgroup].name} call #${parsed[1].id}`); const tgName = globalSystems[parsed[1].system][parsed[1].talkgroup].name; fs.writeFileSync(`./temp/${parsed[1].audioName}`, Buffer.from(parsed[1].audio.data)); - // decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => { - // console.log(`Two-tone detection result for ${tgName}:`, result); - // // Two tone result will be array of objects for each detected twotone activation. .detected is array of two frequencies, one for each tone. Create a counter for each pair of frequencies detected. Make a message to send to discord with the tone names, so if 2 copies of RC EMS are sent, send "RC EMS (2x)" instead. For multiple, send "RC EMS (2x), RC Fire (1x)" etc. - // const toneCounts = {}; - // for (const activation of result) { - // const detected = activation.detected; - // const key = `${detected[0]}:${detected[1]}`; - // if (toneCounts[key]) { - // toneCounts[key]++; - // } else { - // toneCounts[key] = 1; - // } - // } - // const toneMessages = []; - // for (const key in toneCounts) { - // const name = knownTones[key] || key; - // const count = toneCounts[key]; - // toneMessages.push(count > 1 ? `${name} (${count}x)` : name); - // } - // const message = toneMessages.join(", "); - // console.log(`Two-tone summary for ${tgName}:`, message); - // hook.send({ - // // Username is tg name - // username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, - // content: `${message}`, - // // Upload audio file - // files: [{ - // attachment: `./temp/${parsed[1].audioName}`, - // name: parsed[1].audioName - // }] - // }).then(() => { - // // Delete the audio file after sending to Discord - // fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { - // if (err) { - // console.error(`Error deleting audio file: ${err}`); - // } - // }); - // }) - // }); // TwoTone breaks on my server. Will fix later (I think i need py 3.12 not 3.13) - hook.send({ - // Username is tg name - username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, - // content: `${message}`, - // Upload audio file - files: [{ - attachment: `./temp/${parsed[1].audioName}`, - name: parsed[1].audioName - }] - }).then(() => { - // Delete the audio file after sending to Discord - fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { - if (err) { - console.error(`Error deleting audio file: ${err}`); + decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => { + console.log(`Two-tone detection result for ${tgName}:`, result); + // Two tone result will be array of objects for each detected twotone activation. .detected is array of two frequencies, one for each tone. Create a counter for each pair of frequencies detected. Make a message to send to discord with the tone names, so if 2 copies of RC EMS are sent, send "RC EMS (2x)" instead. For multiple, send "RC EMS (2x), RC Fire (1x)" etc. + const toneCounts = {}; + for (const activation of result) { + const detected = activation.detected; + const key = `${detected[0]}:${detected[1]}`; + if (toneCounts[key]) { + toneCounts[key]++; + } else { + toneCounts[key] = 1; } - }); - }) + } + const toneMessages = []; + for (const key in toneCounts) { + const name = knownTones[key] || key; + const count = toneCounts[key]; + toneMessages.push(count > 1 ? `${name} (${count}x)` : name); + } + const message = toneMessages.join(", "); + console.log(`Two-tone summary for ${tgName}:`, message); + hook.send({ + // Username is tg name + username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, + content: `${message}`, + // Upload audio file + files: [{ + attachment: `./temp/${parsed[1].audioName}`, + name: parsed[1].audioName + }] + }).then(() => { + // Delete the audio file after sending to Discord + fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { + if (err) { + console.error(`Error deleting audio file: ${err}`); + } + }); + }) + }); // TwoTone breaks on my server. Will fix later (I think i need py 3.12 not 3.13) + // hook.send({ + // // Username is tg name + // username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, + // // content: `${message}`, + // // Upload audio file + // files: [{ + // attachment: `./temp/${parsed[1].audioName}`, + // name: parsed[1].audioName + // }] + // }).then(() => { + // // Delete the audio file after sending to Discord + // fs.unlink(`./temp/${parsed[1].audioName}`, (err) => { + // if (err) { + // console.error(`Error deleting audio file: ${err}`); + // } + // }); + // }) break; default: console.log("Unknown message:", JSON.stringify(parsed));