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 to convert these quickly?
7 Answers
I was pointed to SoX by a friend, which did the trick. The syntax used was
sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE>

- 649
- 1
- 6
- 6
-
SoX is fantastic. It's a command line tool so it's very straightforward to script, though the number of options can be a bit overwhelming at first. – Dan Bechard Mar 12 '18 at 21:16
-
1Seem the 'raw' file must end in `.raw`. – Chris Stryczynski Jul 28 '18 at 21:03
-
Or you have to explicitly say `-t raw`. – Mormegil Apr 04 '23 at 13:54
I found sox to be incredibly fast and reliable. I use it for a dictation solution I put together with Asterisk. If you are using sox though, be aware that you should be aware of what the source encoding is. I found this to be my initial hangup with the project I did
For my implementation I use this:
sox -t auto -w -s -r 8000 -c 1 {input_file} {output_file}

- 807
- 10
- 10

- 8,185
- 2
- 35
- 51
audioconvert
is pretty standard (I think)
mencoder
isn't available by standard in totally-free linux distributions, but can convert to about anything

- 50,022
- 18
- 110
- 131
If you have a file name.txt which contains all the raw audio file names, then with python you can convert a batch of raw files to batch of wav.
from subprocess import call
file = "name.txt"
with open(file,'rU') as f:
for name in f:
name = name[:len(name)-4]
name1 = './'+name+'raw' #input
name2 = './'+name+'wav' #output
call(["sox","-r","48000", "-t", "sw", "-e", "signed", "-c", "1", "-b", "16", name1, name2])
sample rate 48K,mono channel, precision 16 bit.

- 2,680
- 6
- 43
- 84
-
1small but deadly typo, you're missing a "." before 'raw' and 'wav'. Also be careful as sometimes files have extension ".RAW" (I'm specifically talking about the Radio Music SD card) and AFAIK the arguments of sox are case sensitive – Stefano Feb 24 '21 at 14:14
You can use node-lame
var Lame = require("node-lame").Lame;
const decoder = new Lame({
output: "./new.wav",
raw: true,
bitwidth:16,
sfreq:48,
mode: "m"
}).setFile("./a.pcm");
decoder.decode().then(() => {
console.log("decoded successfully.");
}).catch(error => {
console.log("Error: "+error);
});
https://www.npmjs.com/package/node-lame
Or using "sox" CLI tool
sox -r 48000 -t sw -e signed -c 1 -b 16 a.pcm new.wav

- 1,110
- 12
- 15
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

- 1,389
- 11
- 19