Adding another protection to try to avoid multiple recordings of the same audio happening

This commit is contained in:
Bradley Bickford 2024-01-07 16:23:42 -05:00
parent 6012351b3e
commit 6c6c2655f2

View File

@ -137,6 +137,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => {
if (receiver.speaking.listenerCount("start") == 0) { if (receiver.speaking.listenerCount("start") == 0) {
receiver.speaking.on("start", (user_id) => { receiver.speaking.on("start", (user_id) => {
if(!receiver.subscriptions.has(user_id)) {
receiver.subscribe(user_id, { receiver.subscribe(user_id, {
end: { end: {
behavior: EndBehaviorType.AfterSilence, behavior: EndBehaviorType.AfterSilence,
@ -153,14 +154,16 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => {
} }
})) }))
.pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`)) .pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`))
} else {
logger.warn(`Attempted to create new user subscriber for ${user_id} even though one already exists, receiver arm if statement protected against this`)
}
}) })
receiver.speaking.on("end", (user_id) => { receiver.speaking.on("end", (user_id) => {
logger.info(`User ${user_id} stopped speaking`) logger.info(`User ${user_id} stopped speaking`)
}) })
} else { } else {
logger.info("Attempted to create a new start and end listener for users who are speaking for some reason, receiver armor if statement protected against this") logger.warn("Attempted to create a new start and end listener for users who are speaking for some reason, receiver armor if statement protected against this")
} }
} catch (error) { } catch (error) {
logger.error(error) logger.error(error)