3

I built a Telegram chatbot using python-telegram-bot library. The problem is with send voice message from the bot to the user. The voice message plays fine on Android but it doesn't on IOS and MacOS. Here is the code where I convert the audio file and send the voice message.

subprocess.call(["ffmpeg", "-n", "-i", telegram_username+"_response_audio.mp3", "-acodec", "aac", "-ac", "2", "-ar", "44100", telegram_username+"_response_audio.aac"])
await update.message.reply_voice(voice=open(telegram_username+"_response_audio.aac", 'rb'), reply_to_message_id=message_id, duration=audio_duration)

Here is what I tried to fix it:

  • Since Telegram uses ogg/oga as default audio file format. So I tried to convert it into ogg format before sending the voice. But that didn't help.
  • I also tried different audio formats and codecs. Nothing worked.

Would be grateful if someone point me in the right directions. Thanks

  • What exactly do you mean by "voice message does not play fine on iOS/macOS"? Do you get a specific error message? What happens instead? – CallMeStag Feb 05 '23 at 17:16
  • It just keeps loading the audio file – Zeeshan Ghazanfar Feb 05 '23 at 20:10
  • it = the client/TG app? Have you checked the return value of `update.message.reply_voice(…)`? If that gives a porper `Message` object, then it sounds like a client issue to me … – CallMeStag Feb 06 '23 at 16:32
  • 1
    Have you found the solution? I've stuck with the same issue. I send voice as OGG after conversion from WAV, but on some clients (doesn't work on IOS and one Mac, and works on another Mac, one Linux and two Androids). As well in contrast to usual voice messages I can not see the spectrogram over such voice messages. – user2570027 Feb 27 '23 at 14:44

0 Answers0