3

I have a small Python library for audio experimentation, and currently the library writes raw wave data to the disk, which I can then feed into something like afplay to play the sound.

I'm curious, however, if I can play audio right from memory. I tried creating a named pipe (since afplay requires a filename as it's first argument), but unfortunately it is throwing the error Error: AudioFileOpen failed ('typ?').

Is there an easy way to stream audio from a named pipe? Is there a better way to accomplish what I am trying to do?

Jordan Scales
  • 2,687
  • 4
  • 28
  • 37

1 Answers1

4

You can use SoX's play or FFmpeg's ffplay.

Example with sox:

yourcommand | play -t wav  -

The argument to -t depends on the type audio output your command does.

Example for ffplay:

yourcommand | ffplay -

Similarly with named pipes:

mkfifo /tmp/fifo
yourcommand > /tmp/fifo

sox -t wav /tmp/fifo  ## on another shell or terminal
konsolebox
  • 72,135
  • 12
  • 99
  • 105