Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export (but not save to) an audio file in PyDub?

Tags:

python

pydub

The PyDub library, for me, is pretty much ideal for converting audio formats. I recently used it to write a command line audio converter to convert about 200 audio files, and it saved me having to buy or look for an audio converter that would allow me to queue up songs and other audio files for conversion. But I quickly noticed that it replaced my audio files. Now, for me, this was ideal. This was great. But what if I didn't want PyDub to replace the audio files, but rather duplicate it but in a different format? I could just copy the files into the directory and convert them, but is there no way to do this from within PyDub? I looked into it and I couldn't find a way to do this, nor could I find a question on this, so maybe this isn't a very common thing to do.

Thanks!

like image 872
Eamonn Avatar asked Feb 13 '23 13:02

Eamonn


1 Answers

When you export an audio segment, you can always specify a new name for the file (or use the same name but in a different folder)

from pydub import AudioSegment

song = AudioSegment.from_file("/path/to/file.mp3", format="mp3")
song.export("/path/to/new/filename.mp4", format="mp4")
like image 184
Jiaaro Avatar answered Feb 20 '23 11:02

Jiaaro