Converting RAW audio data to WAV with scripting

拜拜、爱过 提交于 2019-12-29 05:07:06

问题


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?


回答1:


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>




回答2:


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}



回答3:


MPlayer should be able to convert your audio;

$ mplayer \
  -quiet \
  -vo null \
  -vc dummy \
  -af volume=0,resample=44100:0:1 \
  -ao pcm:waveheader:file="file.wav" "file.raw"

It's available in most linux distributions package managers.




回答4:


audioconvert is pretty standard (I think)

mencoder isn't available by standard in totally-free linux distributions, but can convert to about anything




回答5:


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.




回答6:


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


来源:https://stackoverflow.com/questions/2059014/converting-raw-audio-data-to-wav-with-scripting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!