본문 바로가기

WebRTC

SoX 명령어 cheat sheet

Today the command line audio utility sox gave me some head aches while I was working on some sample files for a listening test I prepare for my current research. I actually just needed to convert a stereo 44.1kHz floating point WAV file to 48kHz, split it into single mono files (one for each channel), convert the mono files to raw PCM, process some filter on the raw files, convert them back to mono WAVs, merge the mono files back to stereo again and convert back to 44.1kHz. To accomplish this, I used these commands, which were neither well documented, nor correctly referred to by most of the blogs I’ve read today.

 

wav파일의 정보를 출력하는 명령어 --i :

sox --i infile.wav

//result
Input File     : 'infile.wav'
Channels       : 2
Sample Rate    : 48000
Precision      : 16-bit
Duration       : 00:00:01.81 = 86880 samples ~ 135.75 CDDA sectors
File Size      : 348k
Bit Rate       : 1.54M
Sample Encoding: 16-bit Signed Integer PCM

 

sample rate 를 48khz로 변경하는 명령어 -r (nothing special):

sox infile.wav -r 48k outfile.wav

 

stereo file을 두개의 mono 파일로 분리하는 명령어 (left and right channel):

These commands split the stereo file into two mono files (left and right channel):

sox infile.wav outfile.l.wav remix 1 sox infile.wav outfile.r.wav remix 2

 

스테레오파일을 모노파일로 mix-down(remix) 하는 명령어:

The following commands create a mono mix-down of a stereo file:

sox infile.wav outfile.wav remix 1,2 sox infile.wav outfile.wav remix 1-2

 

wav 파일을 16bit signed integer ( short ) 형태의 48khz mono raw 파일로 변환하는 명령어:

The following command converts a wav file to a raw 16-bit signed integer mono file with 48kHz:

sox infile.wav -b 16 -e signed-integer -c 1 -r 48k -t raw outfile.raw

 

raw 파일을 wav로 변경하는 명령어 (-t raw 필수):

The following command converts a raw file back to WAV (option -t raw is mandatory!):

sox -b 16 -e signed-integer  -c 1 -r 48k -t raw infile.wav outfile.wav

 

두 개의 모노 파일을 하나의 스테레오 wav 파일로 합치는 명령어:

The following command merges the two mono files into one stereo WAV file (order: left, right):

sox -M input.l.wav input.r.wav output.wav

 

n sample 부터 n+k sample trim 명령어(ex 10sample ~ 110sample):

sox input.wav input_cut.wav trim 10s 100s

추가 좋은 커맨드, 오디오 관련 정보 제공 명령어:

오디오 신호 특징을 제공해줌 gain, mean 값 등

Another nice command, not too intrusively documented is the following:

which allows scripts to read audio signal attributes like overall gain, mean values etc. from audio files and use them afterward e. g. for normalization, dc-offset compensation, etc.

sox audiofile.wav -n stat

//result
Samples read:            173760
Length (seconds):      1.810000
Scaled by:         2147483647.0
Maximum amplitude:     0.390778
Minimum amplitude:    -0.259674
Midline amplitude:     0.065552
Mean    norm:          0.004081
Mean    amplitude:     0.000002
RMS     amplitude:     0.005308
Maximum delta:         0.650452
Minimum delta:         0.000000
Mean    delta:         0.003707
RMS     delta:         0.005155
Rough   frequency:         7418
Volume adjustment:        2.559

 

 

The main problem for me today was the flag ‘-t raw’, which is not stated as mandatory in the sox manpage for raw file, but it actually is! Anyhow, the remaining part is pretty straight forward :)

 

 

출처 https://www.nesono.com/node/275

'WebRTC' 카테고리의 다른 글

audioproc_f argument 200907  (0) 2020.09.07
WebRTC 실제 테스트  (0) 2020.07.30
aec_dump 관련 내용  (0) 2020.07.16
webRTC aec3 pipline  (0) 2020.06.16
chromium echo cancellation 테스트  (0) 2020.06.05