How to convert MP3 to WAV in Python

前端 未结 3 1440
无人及你
无人及你 2020-12-05 02:09

If I have an MP3 file how can I convert it to a WAV file? (preferably, using a pure python approach)

相关标签:
3条回答
  • 2020-12-05 02:56

    Install the module pydub. This is an audio manipulation module for Python. This module can open many multimedia audio and video formats. You can install this module with pip.

    pip install pydub
    

    If you have not installed ffmpeg yet, install it. You can use your package manager to do that.

    For Ubuntu / Debian Linux:

    apt-get install ffmpeg
    

    When ready, execute the below code:

    from os import path
    from pydub import AudioSegment
    
    # files                                                                         
    src = "transcript.mp3"
    dst = "test.wav"
    
    # convert wav to mp3                                                            
    sound = AudioSegment.from_mp3(src)
    sound.export(dst, format="wav")
    

    Check this link for details.

    0 讨论(0)
  • 2020-12-05 02:57

    This is working for me:

    import subprocess
    subprocess.call(['ffmpeg', '-i', 'audio.mp3',
                       'audio.wav'])
    
    0 讨论(0)
  • 2020-12-05 03:11

    I maintain an open source library, pydub, which can help you out with that.

    from pydub import AudioSegment
    sound = AudioSegment.from_mp3("/path/to/file.mp3")
    sound.export("/output/path/file.wav", format="wav")
    

    One caveat: it uses ffmpeg to handle audio format conversions (except for wav files, which python handles natively).

    note: you probably shouldn't do this conversion on GAE :/ even if it did support ffmpeg. EC2 would be a good match for the job though

    0 讨论(0)
提交回复
热议问题