Search code examples
pythonstreampyaudio

With Python, how can I convert a flac stream to a wav stream?


I know that I can use PyAudio to convert a .flac file to a .wav file. But I'm wondering if I can somehow do it as a stream and not have to save the .wav file?

Currently, I have:

stream = open('84-121123-0000.flac', 'rb')

But I want to convert that stream to a wav file. Any help would be greatly appreciated. Just to be clear, I don't want to save a .wav file. Instead, I want to keep a stream of the wav converted content.


Solution

  • In Linux, you can install ffmpeg:

    sudo apt update
    sudo apt install ffmpeg
    

    In Windows: download ffmpeg at: FFMPEG Download, set up environment variables at Edit the system environment variables , Path, New, C:\ffmpeg\bin\

    Then run in Python:

    import os
    os.system('ffmpeg -i inputfile.flac output.wav')
    

    You can use this output as a temp file, with a 3-5 seconds delay.