arecord tstxx will produce a wav file and ffmpeg -i tstxx.mp3 to a file aplay will play.
How can I put them together in one command or if there is a simpler and better way, how to get a compressed output file from arecord?
Bob
On Wed, 3 Feb 2021 12:14:52 -0500 Bob Goodwin bobgoodwin@fastmail.us wrote:
arecord tstxx will produce a wav file and ffmpeg -i tstxx.mp3 to a file aplay will play.
How can I put them together in one command or if there is a simpler and better way, how to get a compressed output file from arecord?
I'm not completely clear on what you are trying to accomplish, but if you are trying to record using aplay and get an mp3 file, you should be able to do this with sox. A command like arecord tstxx | sox -t wav - tstxx.mp3 should do the trick. I haven't tested this, though. aplay can only play voc, raw, wav or au files, so will not be able to play mp3. sox can play, and record, many file types, including mp3. See the man page.
On 2021-02-03 12:45, stan via users wrote:
I'm not completely clear on what you are trying to accomplish, but if you are trying to record using aplay and get an mp3 file, you should be able to do this with sox. A command like arecord tstxx | sox -t wav - tstxx.mp3 should do the trick. I haven't tested this, though. aplay can only play voc, raw, wav or au files, so will not be able to play mp3. sox can play, and record, many file types, including mp3. See the man page.
. I just want to be able to say "hello test" into the mic and create a compresses file, mp3 is convenient. I should be able to test with aplay as I can with the original which is by default a .wav/
arecord tstxx | sox -t wav - tstxx.mp3 dpes not peoduce an output file:
[bobg@WS-1 ~]$ arecord tstxx | sox -t wav - tstxx.mp3 Recording WAVE 'tstxx' : Unsigned 8 bit, Rate 8000 Hz, Mono ^CAborted by signal Interrupt... arecord: pcm_read:2153: read error: Interrupted system call sox FAIL formats: can't open input `-': WAVE: RIFF header not found
[bobg@WS-1 ~]$ ls -al tstxx.mp3 ls: unparsable value for LS_COLORS environment variable ls: cannot access 'tstxx.mp3': No such file or directory
I have been unable to find why it doesn't work?
On Wed, 2021-02-03 at 12:14 -0500, Bob Goodwin wrote:
How can I put them together in one command or if there is a simpler and better way, how to get a compressed output file from arecord?
When you say compressed, do you really mean MP3, or would any compressed audio format suffice? And does it have to be arecord, or a command line tool?
arecord supports .au files, which are/can be compressed files.
And arecord can supposedly be used like this to create a MP3: arecord -f cd -t raw | lame -x -r – out.mp3
Or, like this to create an OGG file: arecord -f cd -t raw | oggenc – -r -o out.ogg
I haven't tested either of these, I just googled: command line mp3 recording linux
Those examples use a pipe to take the output from one program (the first one on the command line) and directly send it to the next one, without first saving it as a file. You should be able to combine the process you previously used over a couple of command lines to record a wav and convert to MP3, in a variety of different ways.
However, MP3 encoding requires a certain amount of data to do its compression trick, so might not be as instantaneous as you think, might require a longer test recording using this method.
And how are you going to stop recording? Does your command line tool cleanly stop and output a useable file when you CTRL+C it? I've only used GUI tools to record (e.g. Audacity), but I realise that's not a practical solution for everyone.
When I googled: command line mp3 recording linux I see another page where they suggest this example: arecord -d 5 -f U8 sample.mp3 Which recorded 5 seconds of 8-bit MP3. But perhaps Fedora's arecord doesn't support MP3?
And apparently ffmpeg can record an audio input. This page details recording to a wav https://trac.ffmpeg.org/wiki/Capture/ALSA but you ought to be able to specify any file format that ffmpeg supports.