-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp32wav.py
31 lines (24 loc) · 1.09 KB
/
mp32wav.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os, glob, eyed3, ntpath, shutil
import scipy.io.wavfile as wavfile
# remember to "brew install libav" in terminal beforehand
def convertDirMP3ToWav(dirName, Fs, nC, useMp3TagsAsName = False):
'''
Referred to the PyAudioAnalysis project on Github
This function converts the MP3 files stored in a folder to WAV.
ARGUMENTS:
- dirName: the path of the folder where the MP3s are stored
- Fs: the sampling rate of the generated WAV files
- nC: the number of channesl of the generated WAV files
- useMp3TagsAsName: True if the WAV filename is generated on MP3 tags
'''
types = (dirName+os.sep+'*.mp3',) # the tuple of file types
filesToProcess = []
# tag = eyeD3.Tag()
for files in types:
filesToProcess.extend(glob.glob(files))
for f in filesToProcess:
wavFileName = f.replace(".mp3",".wav")
command = "avconv -i \"" + f + "\" -ar " +str(Fs) + " -ac " + str(nC) + " \"" + wavFileName + "\"";
print command
os.system(command.decode('unicode_escape').encode('ascii','ignore').replace("\0",""))
convertDirMP3ToWav("/Users/IrisYupingRen/Downloads/inputpath", 44100, 2)