Converting RAW audio data to WAV with scripting

后端 未结 7 1726
梦毁少年i
梦毁少年i 2020-12-15 18:43

I have a large number of .RAW audio files (unsigned 8-bit PCM with no-endianness) which I want to convert to .WAV files. What command-line tool (windows or linux) can I use

相关标签:
7条回答
  • 2020-12-15 19:20

    Let's use Sox, it's available pretty much everywhere.

    On mac:

    brew install sox
    

    On Ubuntu (tested 18.04):

    sudo apt update && sudo apt install sox -y
    

    I tend to use 16k SR, 16-bit precision with encoding 16-bit Signed Integer PCM so will use those defaults. My files are .raw but could also be .pcm etc.

    # assume you're in the directory with the raw wavs - we'll make a new wavs directory to put the converted ones
    mkdir -p wavs
    
    # 1-liner
    for f in *.raw; do sox -r 16000 -e signed -b 16 -c 1 "$f" wavs/"${f%.*}.wav"; done
    

    To check that the wav files have their header, use soxi:

    rob@tp:~/wavs$ soxi test.wav 
    
    Input File     : 'test.wav'
    Channels       : 1
    Sample Rate    : 16000
    Precision      : 16-bit
    Duration       : 00:00:12.62 = 201984 samples ~ 946.8 CDDA sectors
    File Size      : 404k
    Bit Rate       : 256k
    
    0 讨论(0)
提交回复
热议问题