Please describe the problem you are having in as much detail as possible:
Hello, I'm trying to make a live transcription bot using Google Cloud Speech-to-text API. The issue occurs without any warnings, errors, or breakage. It simply does nothing I can interpret. Upon reaching connection.on('speaking', (user, speaking) => {, the issue occurs. I did several hours of prior research and came across several posts from 2019 relating to the same issue, but none were resolved officially from what I can tell.
https://github.com/discordjs/discord.js/issues/3591
https://github.com/discordjs/discord.js/issues/3524
If you follow the link to issue 3524, you will see a variety of solutions provided by users more impatient than I, but all of these are a year old and I can't seem to make them work for me. A popular solution that I saw, but does not work for me, is to make the bot send out audio (or silence) in order to be able to hear a user.
Any and all hints/help/luck would be greatly appreciated.
Include a reproducible code sample here, if possible:
// Place your code here
const connection = await memberVoiceChannel.join()
const receiver = connection.receiver
timer()
connection.on('speaking', (user, speaking) => {
timer()
console.log("--\n\n" + transChannelList + "\n\n--")
if (!speaking) {
return
}
console.log(`I'm listening to ${user.username}`)
const audioStream = receiver.createStream(user, { mode: 'pcm' })
const requestConfig = {
encoding: 'LINEAR16',
sampleRateHertz: 48000,
languageCode: 'en-US'
}
const request = {
config: requestConfig
}
const recognizeStream = googleSpeechClient
.streamingRecognize(request)
.on('error', console.error)
.on('data', response => {
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n')
.toLowerCase()
console.log(`Transcription: ${transcription}`)
if(transChannelList.length > 0){
for(index=0; index<transChannelList.length; index++){
chan = msg.guild.channels.get(transChannelList[index])
chan.send(`${user.username}: ${transcription}`)
}
}
if(transDMList.length > 0){
for(i=0; i<transDMList.length; i++){
mem = msg.guild.members.fetch(transDMList[i])
mem.then(function(member){member.send(`${user.username}: ${transcription}`)})
}
}
})
const convertTo1ChannelStream = new ConvertTo1ChannelStream()
audioStream.pipe(convertTo1ChannelStream).pipe(recognizeStream)
audioStream.on('end', async () => {
console.log('audioStream end')
})
})
Further details:
Relevant client options:
I am having the same issue. I got it to work for a while and now it does not work after no edits on my part. No errors or anything and when I debug the connection, it prints debug: [WS] << {"op":5,"d":{"user_id":<my_id>,"ssrc":1074919,"speaking":1}} so it looks like it is picking up that I am speaking but the event speaking is not firing or getting picked up.
Also, I followed the solution from #3524 and it worked a couple times but now again it is not working. I replaced the youtube link for sound with an mp3 and that is working again.
// Only join if member is part of a voice channel themselves
if (message.member.voice.channel) {
// Join the voice channel the member is currently in
const connection = await message.member.voice.channel.join();
const dispatcher = connection.play(
ytdl("https://www.youtube.com/watch?v=n2EjeMx4bSg", {
range: { start: 0, end: 1 },
})
);
dispatcher.on("start", () => {
console.log("Scribe: Play Starting...");
});
dispatcher.on("finish", () => {
console.log("Scribe: Finished playing!");
});
dispatcher.on("end", (end) => {
console.log("Scribe: End Finished playing!");
});
connection.on("speaking", (user, speaking) => {
console.log("here");
});
Where did the new ConvertTo1ChannelStream come from?
Same problem, sometimes works, sometimes not
Most helpful comment
Same problem, sometimes works, sometimes not