3

I have a program which uses FIFO files for interacting with the user. An audio call can be made directing the output of arecord to one of the program's FIFO files:

arecord -r 48000 -c 1 -f S16_LE > call_in

An audio call can be answered by directing the output of one of the program's FIFO files to aplay:

aplay -r 48000 -c 1 -f S16_LE - < call_out

How could an audio file be used in place of the first command, the one used to make a call? Let's say I want to play "sound.wav" into that call_in file, how could it be done?

  • 1
    Note that the WAV format contains a header with the total size of the file, so this format is not suitable for streaming or piping (unless both sides agree to ignore it, which arecord doesn't - it will attempt to fill the header on closing, and the seek will fail). So use -t raw (then you must specify parameters) or -t au (Sun sound format). – dirkt Feb 17 '18 at 6:48
  • @dirkt Hey, thanks for the suggestion. I tried using a command like aplay -c 1 -f S16_LE -t au sound.wav > call_in, but what ended working was ffmpeg -i sound.wav -ar 48000 -f s16le -acodec pcm_s16le pipe:1 > call_in. Thanks for your help. – BlandCorporation Feb 26 '18 at 22:30
  • Um, sound.wav is obviously a wav file, and not au format, so that can't work ... you'll have to both record and play in the same format. Using ffmpeg this way is the same as using raw format. But if it works, it works ... – dirkt Feb 27 '18 at 9:38
1

If arecord's input is your sound card, then I suggest: aplay sound.wav & arecord call_in

aplay should play your message. The & allows the next command, arecord, to immediately execute, which should start recording what aplay is sending to your sound card.

Actually, arecord call_in & aplay sound.wav would probably be better, so you can be sure you're recording before the message plays.

0

Assuming the output of arecord is functionally like the contents of the wav file (i.e., they're the same media format), you could just do:

cat sound.wav > call_in

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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