Fixed it. Only works with python 3.12

This commit is contained in:
Christopher Cookman 2026-07-30 10:01:53 -06:00
parent 8ebcf2927d
commit 51f16320c9

View file

@ -83,7 +83,7 @@ const decodeTwoTone = (filePath) => {
return; return;
} }
// Proceed with Python process only after FFMPEG conversion is successful // 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 = ""; let result = "";
pythonProcess.stdout.on("data", (data) => { pythonProcess.stdout.on("data", (data) => {
@ -152,49 +152,31 @@ conn.on("message", (data) => {
console.log(`New Call ${globalSystems[parsed[1].system][parsed[1].talkgroup].name} call #${parsed[1].id}`); 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; const tgName = globalSystems[parsed[1].system][parsed[1].talkgroup].name;
fs.writeFileSync(`./temp/${parsed[1].audioName}`, Buffer.from(parsed[1].audio.data)); fs.writeFileSync(`./temp/${parsed[1].audioName}`, Buffer.from(parsed[1].audio.data));
// decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => { decodeTwoTone(`./temp/${parsed[1].audioName}`).then((result) => {
// console.log(`Two-tone detection result for ${tgName}:`, 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. // 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 = {}; const toneCounts = {};
// for (const activation of result) { for (const activation of result) {
// const detected = activation.detected; const detected = activation.detected;
// const key = `${detected[0]}:${detected[1]}`; const key = `${detected[0]}:${detected[1]}`;
// if (toneCounts[key]) { if (toneCounts[key]) {
// toneCounts[key]++; toneCounts[key]++;
// } else { } else {
// toneCounts[key] = 1; toneCounts[key] = 1;
// } }
// } }
// const toneMessages = []; const toneMessages = [];
// for (const key in toneCounts) { for (const key in toneCounts) {
// const name = knownTones[key] || key; const name = knownTones[key] || key;
// const count = toneCounts[key]; const count = toneCounts[key];
// toneMessages.push(count > 1 ? `${name} (${count}x)` : name); toneMessages.push(count > 1 ? `${name} (${count}x)` : name);
// } }
// const message = toneMessages.join(", "); const message = toneMessages.join(", ");
// console.log(`Two-tone summary for ${tgName}:`, message); 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({ hook.send({
// Username is tg name // Username is tg name
username: globalSystems[parsed[1].system][parsed[1].talkgroup].name, username: globalSystems[parsed[1].system][parsed[1].talkgroup].name,
// content: `${message}`, content: `${message}`,
// Upload audio file // Upload audio file
files: [{ files: [{
attachment: `./temp/${parsed[1].audioName}`, attachment: `./temp/${parsed[1].audioName}`,
@ -208,6 +190,24 @@ conn.on("message", (data) => {
} }
}); });
}) })
}); // 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; break;
default: default:
console.log("Unknown message:", JSON.stringify(parsed)); console.log("Unknown message:", JSON.stringify(parsed));