我有大量的.RAW音频文件(无符号8位PCM格式且没有字节序),我想将它们转换成.WAV文件。我可以使用哪个命令行工具(在Windows或Linux下)快速转换它们?
我的朋友向我推荐了SoX,这个工具非常好用。所使用的语法如下:sox -r 44100 -e unsigned -b 8 -c 1 <RAW_FILE> <TARGET_FILE>
sox -t auto -w -s -r 8000 -c 1 {input_file} {output_file}
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])
采样率为48K,单声道,精度为16位。
$ mplayer \
-quiet \
-vo null \
-vc dummy \
-af volume=0,resample=44100:0:1 \
-ao pcm:waveheader:file="file.wav" "file.raw"
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
或者使用命令行工具“sox”。sox -r 48000 -t sw -e signed -c 1 -b 16 a.pcm new.wav
让我们使用Sox,它几乎在所有地方都可用。
在Mac上:
brew install sox
sudo apt update && sudo apt install sox -y
我倾向于使用16k SR、16位精度和编码为16位带符号整数PCM的默认设置。我的文件是.raw格式,也可以是.pcm等。
# 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
要检查wav文件是否有头部,请使用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
.raw
结尾。 - Chris Stryczynski