Jordan Scales
Jordan Scales

Reputation: 2717

Stream audio from named pipe

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?

Upvotes: 3

Views: 4478

Answers (1)

konsolebox
konsolebox

Reputation: 75498

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

Upvotes: 4

Related Questions