cronokirby/alchemy

Voice.play_file/2 does not have sound when playing the same file more than 1 time.

wkpatrick opened this issue · 2 comments

If you have a bot connect to the voice channel and play a sound from a file, it will correctly play it, light up under voice activity, etc. If you tell it to play that same file, the following happens:

  • The file is correctly read and decoded.
  • The packets are sent to the voice gateway.
  • The voice activity lights up for the correct amount of time.
  • The audio does not come through.
  • There are no errors thrown.

You can play a different file and it will correctly play it the first time, but will run into the same issue if you attempt to play it a second time. Playing a different file does not fix the issue for the previous file.

The only way ive found to remedy this is to force the bot to disconnect from the voice channel.

I believe this also happens with play_url. I will do some more testing later.

Any help yall can provide is appreciated.

@wkpatrick it seems that the Process is not killed after the file ends, I mean, it does not know that the file had ended and maybe you have to add a command to execute Structs.Voice.stop_audio/1. I'm not sure though, have you managed to deal with this issue?

I have been unable to find the root cause of the issue. Executing Voice.stop_audio/1 before playing the next sound does not do anything, the issue still persists.

As a temporary work around, I have the bot disconnect from the voice channel and reconnect before playing the audio, which works perfectly.

Another symptom of this issue, is that when playing one sound after another, there is a ~1 second period where there is no sound, but the bot has lit up, and the sound does play roughly 1 second through the audio file.

For reference, here is (most of) the code for how my bot handles playing sounds

    Logger.debug("Stopping audio")
    Alchemy.Voice.stop_audio(voice_state.guild_id)
    Logger.debug("Leaving guild")
    Alchemy.Voice.leave(voice_state.guild_id)
    Logger.debug("sleeping for 300 ms")
    :timer.sleep(300)
    Logger.debug("Joining guild")
    Alchemy.Voice.join(voice_state.guild_id, voice_state.channel_id)
    Alchemy.Voice.play_iodata(voice_state.guild_id, sound_file.body)