Search code examples
pythonmp3google-cloud-platformflacgoogle-speech-api

How to edit the length of a FLAC file in Python?


I am currently using Google's speech API and I a wondering is I can edit the length of the FLAC file that I am inputting into the program. e.g. I have a 7:30 length mp3 with 2 audio channels and I need it to be a 1 channel mono FLAC file with the length of 3 minutes for it to be input into the speech to text API.


Solution

  • Does it have to be done in Python as the headline says? If its OK to do the conversion on a command line you could use a tool like sox. For example:

    sox audio.flac audio-short-mono.flac trim 0 180 remix 1,2
    

    The trim 0 180 option crops the audio to 180 seconds, and remix 1,2 combines the two channels into one.