Merge multiple .raw file into single wav file using Sox - audio

Does any one know how to merge multiple raw audio file into single wav file. I am using Sox but any other tools also fine.
I am trying below commands, but i know something wrong here
sox -r 16000 -b 16 -c 1 -e signed-integer file1.raw file2.raw out.wav
I am missing something ?

You need to specify all input file parameters per file (as RAW obviously does not have a header). Your initial guess was same as mine: that -r 16000 -b 16 -c 1 -e signed-integer applies to both file1.raw and file2.raw. It doesn't.
Here's how it should be done:
sox -r 16000 -b 16 -c 1 -e signed-integer file1.raw -r 16000 -b 16 -c 1 -e signed-integer file2.raw out.wav
You might want to add option -m for merge.

Related

arecord | split to wav or ogg

I have the following script on linux:
arecord -t raw -f S16_LE -r 44100 -c 1 | split -d -b 882000 --filter='flac - -f --endian little --sign signed --channels 1 --bps 2 --sample-rate 44100 -s -o "${FILE}.flac"'
this script records audio at 44100 fs, 1 channel, then flac files with 882000 bytes, ie 10 seconds of audio at 44100 sample rate are created and saved. The audios are 2 mb, is there any way I can do this but save it in wav or ogg format?
Flac files, not having loss, take up a lot of memory space, I want to reduce that with another format
You can use lame instead flac:
arecord -t raw -f S16_LE -r 44100 -c 1 | split -d -b 882000 --filter='lame -r -s 44.1 - "${FILE}.mp3"'

Sox Is Throwing A Random Error: Option A Isn't Recognized

I am running this command:
sox -t mp3 $(ls -1 /home/pi/Desktop/Music/*.mp3|sort -R) -t wav -r 44100 - | sudo ./pi_fm_rds -freq 104.5 -audio - -ps ZSFM -rt ZSFM
This is the result:
sox WARN getopt: option `A' not recognized
sox FAIL sox: invalid option
When I was running this command sox worked fine:
sox -t mp3 /home/pi/Desktop/Music/*.mp3 -t wav -r 44100 - | sudo ./pi_fm_rds -freq 104.5 -audio - -ps ZSFM -rt ZSFM
The new command is to have sox shuffle through the files in a directory randomly, but its giving me this wierd error. How can I make it work? I've done tons of research, but I can't find anything about 'option A' anywhere.
The problem was the whitespace in file names - all I had to do was change, for example, 'dasa berta.mp3' to 'dasaberta.mp3'. One of the file names had 'A' in it, and the terminal took it as a separate command. It wasn't a sox problem, it was a me-using-terminal-problem.

Play an MP3 file as it's being written

I'm saving an fm station to an mp3 file using rtl_fm and sox.
rtl_fm to capture the signal and sox to transcode it to mp3.
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 | sox -traw -r8k -es -b16 -c1 -V1 - -tmp3 - | sox -tmp3 - some_file.mp3
Then I'm trying to play that file in a second terminal, as the mp3 is being written using:
play -t mp3 some_file.mp3
The problem is that it only plays up until the time the mp3 had at the time the play command was invoked.
How do I get it to play the appended mp3 over time, while it's being written?
EDIT:
Running on Raspberry Pi 3 (Raspian Jessie), NooElec R820T SDR
There are a couple of things here. I don't think sox supports "tailing" a file, but I know mplayer does. However, in order to have better control over the pipeline, using gstreamer might be the way to go, as it has a parallel event stream built into its effects pipeline.
If you want to stick with sox, I would first get rid of the redundant second invocation of sox, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
sox -ts16 -r8k -c1 -V1 - some_file.mp3
And in order to play the stream while transcoding it, you could multiplex it with tee, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
tee >(sox -ts16 -r8k -c1 -V1 - some_file.mp3) |
play -ts16 -r8k -c1 -
Or if you want them to be separate processes:
# Save stream to a file
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 > some_file.s16
# Encode stream
sox -ts16 -r8k -c1 -V1 some_file.s16 some_file.mp3
# Start playing the file at 10 seconds in
tail -c+$((8000 * 10)) -f some_file.s16 |
play -ts16 -r8k -c1 -

Streaming a file off a server

I am trying to stream the recorded audio from my raspberry pis to my desktop computer which handles pocketsphinx phenomenally. I can pipe the audio using
arecord -D plughw:1,0 -r 16000 -f S16_LE | ssh -C user#192.168.86.101 sox - test.wav
And then run it using
pocketsphinx_continuous -dict ~/4568.dic -lm ~/4568.lm -infile ~/test.wav
But once it reaches the end of the file, it stops, even though the file is still writing. Is there a way to keep it open?
Use named pipe instead of a regular file. Also you can file an issue at github.com/cmusphinx/pocketsphinx requesting that pocketsphinx_continious should be able to read from stdin. And of course you're welcome to submit such a patch.
To anyone else finding this,
arecord -D plughw:1,0 -r 16000 -f S16_LE | ssh -C user#192.168.86.101 pocketsphinx_continuous -infile /dev/stdin
is how to do it

How do I add RIFF header to MP3 files programatically?

More information about what I want to do here; http://www.studiodust.com/riffmp3.html
I want a way so that my control panel (made with Perl and Webmin) can do this automatically. Right now I have to rely on system calls and have a binary for Linux. Is there a library that does it for Perl or some other language?
What's the best way of doing this?
I know nothing about RIFF files or their structure, uses, etc. But did you try searching CPAN? The first result looks pretty promising.
The website I reference had the answer I needed. I didn't know they made a linux variant.
I have the following script for the exact thing you asked about.
#!/bin/bash
echo "$1"
ffmpeg -y -i "$1" -f wav out.wav > /dev/null 2>&1 && \
normalize-audio -q out.wav && \
lame --silent -a -m m --cbr -b 64 -q 0 out.wav out.mp3 && \
ffmpeg -y -i out.mp3 -f wav -acodec copy "$1" > /dev/null 2>&1 && \
echo "done."
rm out.wav out.mp3
Just edit the parameters to lame or just use the ffmpeg call and you're set.

Resources