Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to convert arecord wav output to flac and it does work in part:

pi@raspberrypi /tmp $ arecord -d4 -f dat -t wav -r 48000 -c 2 |flac -f -o message.flac - --channels=1 --sample-rate=16000

it will create a file that's recognized and played as a valid flac file by mplayer:

pi@raspberrypi /tmp $ mplayer message.flac
==========================================================================
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 48000 Hz, 2 ch, s16le, 125.8 kbit/8.19% (ratio: 15723->192000)
Selected audio codec: [ffflac] afm: ffmpeg (FFmpeg FLAC audio)
==========================================================================

however, I can't figure how to properly tell flac I want a 16kHz 1 channel track as the result. When I use -d instead of plain '-' it will not accept it.

You may ask why I'm not setting arecord channel/rate to the target settings - the answer is that if I do that, the quality of sound captured is horrible, conversion to flac via sox/flac with lower settings works out much better.

I initially wanted to use sox to record flac without having to recode wav to flac but it's giving me a segmentation fault and I couldn't find a way to overcome this yet.

share|improve this question
    
You'll probably have to use sox to change channels/sample rate - I don't think flac can transform audio other than encoding, the options are probably just there to specify the input format (if it's raw w/o headers). –  frostschutz Jan 29 '13 at 21:16
add comment

1 Answer

The flac encoder definitely will not do sample rate / bit depth conversion. However, sox can do this for you on the fly. Try this out:

arecord -d4 -f dat -t wav -r 48000 -c 2 | sox - -b16 -r16k -c1 -t wav - | flac - -o message.flac

Arguments to sox are:

  1. - use stdin
  2. -b16 output bit depth
  3. -r16k output 16kHz sample rate
  4. -c1 output one channel
  5. -t wav specify wav output format
  6. - send result to stdout

Because the input to flac is already 16kHz, there is no need to specify the input sample rate.

Hope this helps!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.