Resample audio file from terminal
Asked Answered
S

1

5

I currently have a list of file for which I need to change the sample rate for.

I'recently been aware that this is possible using sox But when I try do it, I keep on getting a error message that sox wav: Premature EOF on .wav input file And causes the audio file to be empty.. it seems like that sox is not able to resample an audio file which input = output... which I kinda need, if I have to convert a whole directory of audio files...

Currently used commands:

~/kaldi-trunk/egs/yesno/s5_k_added$ sox 0_0_0_0_1_1_1_1.wav -r 8000 0_0_0_0_1_1_1_1.wav 
sox WARN wav: Premature EOF on .wav input file
:~/kaldi-trunk/egs/yesno/s5_k_added$ play 0_0_0_0_1_1_1_1.wav 

0_0_0_0_1_1_1_1.wav:

 File Size: 44        
  Encoding: Signed PCM    
  Channels: 1 @ 16-bit   
Samplerate: 8000Hz       
Replaygain: off         
  Duration: unknown      

In:0.00% 00:00:00.00 [00:00:00.00] Out:0     [      |      ]        Clip:0    
Done.

How do I resample a directory of audio files?

Steeple answered 6/8, 2017 at 23:28 Comment(2)
Could you post the full command and arguments you are currently using?Somerville
full command posted @SomervilleSteeple
S
9

Try changing the output file name, possible putting it in a different directory if you want to keep the same file name.

For example:

sox 0_0_0_0_1_1_1_1.wav -r 8000 ./out/0_0_0_0_1_1_1_1.wav

I believe sox is attempting to read the file while it is actively changing it, sometimes sox does not create a temporary file to output into.

EDIT: If you have a directory of files you all want to change, use this:

$ mkdir out
$ for file in *; do sox ${file} -r 8000 ./out/${file}; done
Somerville answered 6/8, 2017 at 23:46 Comment(1)
But i need to do it in a directory of waves files.. as I stated above.. I know this is an issue? but is there a way I still do it as easy as this...Steeple

© 2022 - 2024 — McMap. All rights reserved.