K
Kord2w ago
Peffern

Does receiveVoice still work?

I am working on an old voice bot I made a couple years ago and it seems like something in Kord is crashing as soon as there's any voice data from the server. I know it was considered experimental, but is it supposed to be able to work currently?
12 Replies
Peffern
Peffern2w ago
adding that I'm not even doing anything to process the voice streams yet. Just adding the receiveVoice = true is enough to crash it
LustigerLurch
LustigerLurch2w ago
hm, i haven't worked with voice much, maybe @Lost or @viztea can help
Lost
Lost2w ago
can you show your setup. what do you mean by crashing. you have any logs?
Peffern
Peffern2w ago
I'm not good with android studio so if there's a logcat query that will find anything relevant, I haven't found it. What info from my setup would you like to see?
Lost
Lost2w ago
android studio? is this an android app? not sure what a logcat query is. assuming you have a logging framework setup, you should be getting logs printed to the console. i am asking to see your code that makes kord "crash". what is crashing btw.
Peffern
Peffern2w ago
sorry, I forgot this isn't strictly an android library, I was being dumb. I can provide more context now: - I want to host a discord bot on android - I am deploying the code from android studio to my phone and running it there. I have the USB debugging logs for everything running in my phone which is difficult to parse out just the ones from this application. (I can put more time into figuring this out if it would help). - The thing that is crashing is the android application that is running the bot code. -some code:
voiceConn = channel.connect {
// receiveVoice = true
audioProvider {
getUplinkFrames(buffer, buffer.size)
val data = codec.encode(buffer)
if (data == null) AudioFrame.SILENCE else AudioFrame.fromData(data)
}
}
voiceConn = channel.connect {
// receiveVoice = true
audioProvider {
getUplinkFrames(buffer, buffer.size)
val data = codec.encode(buffer)
if (data == null) AudioFrame.SILENCE else AudioFrame.fromData(data)
}
}
this is where I initialize my voice connection from a voice channel. I intend to both send and receive audio. As you can see here the sending is working fine. When I uncomment the receiveVoice line, it works as normal until any other member in the same voice channel as the bot makes any sound, at which point the android application exits for reasons I don't know yet, see above.
Lost
Lost2w ago
fair enough. logs would be helpful, but im not sure if voice has ever been tested on android. i dont have the time at the moment to look into it, but i suppose there could be something with initializing the incoming socket due to whatever android limitations there are. just a guess rn
Peffern
Peffern2w ago
I know for a fact that it used to work. I made a prototype of this bot a year or so ago. So it's possible that something changed with the discord API but it isn't (or wasn't) a fundamental incompatibility.
Lost
Lost2w ago
ill try to look into it later. gotta fly
Peffern
Peffern2w ago
yeah I'll try to get better logs and see if I can present something I may have been too hasty. It may actually be a problem with how I'm handling the incoming streams:
voiceConn!!.streams.incomingAudioFrames.collect {
val frame = it.second
val data = codec.decode(frame.data)
if (data != null) {
provideDownlinkData(data, data.size)
}
}
voiceConn!!.streams.incomingAudioFrames.collect {
val frame = it.second
val data = codec.decode(frame.data)
if (data != null) {
provideDownlinkData(data, data.size)
}
}
this runs in a separate coroutine. does that look right? is .collect a problem? Okay i was going in completely the wrong direction. As far as I can tell Kord works beautifully for my use case. The cause was actually a crappy Opus codec. Switching to Concentus appears to have fixed the problem. Sorry for wasting your time. actually maybe i was hasty:
FATAL EXCEPTION: DefaultDispatcher-worker-8
Process: [removed], PID: 22979
java.lang.IllegalStateException: 512 bytes remaining. tried to write 659 bytes
at dev.kord.voice.io.MutableByteArrayCursor.writeByteArray(ByteArrayCursors.kt:55)
at dev.kord.voice.encryption.XSalsa20Poly1305Encryption.open(XSalsa20Poly1305Encryption.kt:48)
at dev.kord.voice.encryption.XSalsa20Poly1305Codec.decrypt(XSalsa20Poly1305Codec.kt:26)
at dev.kord.voice.streams.DefaultStreamsKt$decrypt$$inlined$mapNotNull$1$2.emit(Emitters.kt:230)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$filter$2$2.emit(Emitters.kt:223)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$mapNotNull$1$2.emit(Emitters.kt:225)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$filter$1$2.emit(Emitters.kt:223)
at kotlinx.coroutines.flow.SharedFlowImpl.collect$suspendImpl(SharedFlow.kt:383)
at kotlinx.coroutines.flow.SharedFlowImpl$collect$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [CoroutineName(kord-voice-connection[357353078480961537]), StandaloneCoroutine{Cancelling}@9d42a5e, Dispatchers.Default]
FATAL EXCEPTION: DefaultDispatcher-worker-8
Process: [removed], PID: 22979
java.lang.IllegalStateException: 512 bytes remaining. tried to write 659 bytes
at dev.kord.voice.io.MutableByteArrayCursor.writeByteArray(ByteArrayCursors.kt:55)
at dev.kord.voice.encryption.XSalsa20Poly1305Encryption.open(XSalsa20Poly1305Encryption.kt:48)
at dev.kord.voice.encryption.XSalsa20Poly1305Codec.decrypt(XSalsa20Poly1305Codec.kt:26)
at dev.kord.voice.streams.DefaultStreamsKt$decrypt$$inlined$mapNotNull$1$2.emit(Emitters.kt:230)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$filter$2$2.emit(Emitters.kt:223)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$mapNotNull$1$2.emit(Emitters.kt:225)
at dev.kord.voice.streams.DefaultStreams$listenForIncoming$$inlined$filter$1$2.emit(Emitters.kt:223)
at kotlinx.coroutines.flow.SharedFlowImpl.collect$suspendImpl(SharedFlow.kt:383)
at kotlinx.coroutines.flow.SharedFlowImpl$collect$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [CoroutineName(kord-voice-connection[357353078480961537]), StandaloneCoroutine{Cancelling}@9d42a5e, Dispatchers.Default]
this is on connecting to the voice channel and receiving the first frames. it doesnt appear to be crashing in my code so I do think Kord has something to do with it from my limited understanding of the code it looks like something in the early packet processing where it's decrypting. no idea why. the packets do look legit so I imagine it's something involved in the codec an update: it only seems to happen in one server (guild whatever). I've tried it in a few others and no issue. Seemed to reproduce reliably
Lost
Lost2w ago
discord did an update to voice that deprecates the encryption kord (and most other libs) used. shouldn’t be out until november or something but i wouldn’t be surprised if it’s something to do w that since it’s discord and it’s on the undocumented receiving end. kord will need to be updated according to the new docs and maybe your issue will be resolved along side it as new encryption methods will be implemented. haven’t looked at the stackstrace tho, could be sum else; js started uni. little time on my pc :pained_smile:
Peffern
Peffern2w ago
thanks for the heads up! good luck tracking their useless undocumented APIs
Want results from more Discord servers?
Add your server