How to convert any mp3 file to .wav 16khz mono 16bit
Asked Answered
X

3

61

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

Xiphisternum answered 13/11, 2012 at 9:31 Comment(0)
M
128

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

Mercie answered 29/9, 2013 at 1:53 Comment(6)
will this mix both channels or just split and use the 1st one?Eiland
This will mix the two channels into one - I just confirmed it. BTW, looks like on current Ubuntu 14.10, ffmpeg is now renamed to avconvMercie
if needed, we must balance the channels before the mix as one may become too low volume, but in general it works great!Eiland
Here's some more info on how ffmpeg handles manipulating audio channels: trac.ffmpeg.org/wiki/AudioChannelManipulationSoulless
Can't get this working for some reason, the -ar changes Hz no problem, but -acodec pcm_s16e doesn't seem to do anythingPiegari
looks like current ffmpeg (4.1.3) defaults to pcm_s16le output audio codec - i just tested both versions (with or without -acodec pcm_s16le) and compared the output file formats to be the same. thanks for pointing this out!Mercie
D
11

Try this:

ffmpeg -i 111.mp3 -acodec pcm_s16le -ar 16000 out.wav
Dugas answered 16/12, 2012 at 1:29 Comment(1)
also need to add -ac 1 for mono channelThornie
E
4

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
Equinoctial answered 13/1, 2022 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.