Reputation: 1465
Please, help to choose solution for converting any mp3 file to special .wav - I'm a newbie with Linux command line tools, so It's hard for me right now.
I need to get wav with 16khz mono 16bit sound properties from any mp3 file. I was trying
ffmpeg -i 111.mp3 -ab 16k out.wav,
but I got wav with the same rate as mp3 (22k).
Please, help to construct right command line
Upvotes: 62
Views: 89071
Reputation: 2624
Use this example:
import os
from pydub import AudioSegment
import numpy as np
from tqdm import tqdm
for src in tqdm (mp3_files):
des = src.replace('.mp3','.wav')
try:
sound = AudioSegment.from_mp3(src)
sound.set_channels(1)
sound = sound.set_frame_rate(16000)
sound = sound.set_channels(1)
sound.export(des, format="wav")
except:
print(src)
continue
Upvotes: 4
Reputation: 1493
kdazzle's solution is almost there - it still output a stereo wav, here is a slightly modified version that generate mono:
ffmpeg -i 111.mp3 -acodec pcm_s16le -ac 1 -ar 16000 out.wav
also, if this is for pre-processing speech data for sphinx 4 see here: Convert audio files for CMU Sphinx 4 input
Upvotes: 130