How to convert Telegram voice in a wave file in python

后端 未结 2 422
长发绾君心
长发绾君心 2021-01-25 02:34

I\'m trying to save a Telegram voice file in a wave audio file using soundfile library:

def ReceiveVoice(bot, update, user_data):

   voice = bot.getFile(update.         


        
相关标签:
2条回答
  • 2021-01-25 03:02

    You could try to use ffmpeg to convert from ogg to wav by executing the following command line using python's module subprocess.

    import subprocess
    src_filename = 'captured.ogg'
    dest_filename = 'output.wav'
    
    process = subprocess.run(['ffmpeg', '-i', src_filename, dest_filename])
    if process.returncode != 0:
        raise Exception("Something went wrong")
    
    0 讨论(0)
  • 2021-01-25 03:12

    Try this

    import soundfile as sf
    data, samplerate = sf.read(input_ogg)
    sf.write(output_wav, data, samplerate)
    
    0 讨论(0)
提交回复
热议问题