Use FFmpeg to audio format and sample rate
ImportOSImportstringImportsubprocess as SP#Full path of FFmpegFfmpeg_bin ="/users/karl/documents/python/audio/tool/ffmpeg"#Full path of SourceDirSourceDir ="/users/karl/documents/python/audio/"#Full path of TargetDirTargetDir ="/users/karl/documents/python/newdir/"#Sample FrequencySF = 11025#Extension Settingext ='mp3'defconvert (SourceDir, TargetDir, SF, ext):if notSourcedir.endswith ('/'): SourceDir+='/' if notTargetdir.endswith ('/'): TargetDir+='/' if notos.path.exists (TargetDir): Os.mkdir (targetDir) files=Os.listdir (SourceDir) forFinchFiles:ifF.endswith ('wav'): Command=[Ffmpeg_bin,'- I.', SourceDir +F,'-ar', str (SF), TargetDir + Os.path.splitext (f) [0] +'.'+ext]PrintCommand Pipe= sp. Popen (command, stdout = sp.) PIPE, bufsize = 10**8) Convert (SourceDir, TargetDir, SF, ext)
[Audio processing] FFmpeg to audio format and sample rate