Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX equivalent of piping sound to linux's aplay

Tags:

macos

audio

On Ubuntu I am able to use aplay to play sound generated live from a script by piping the output of my script to aplay's stdin :

./generate_sound.py | aplay -r 2000 -c2 -f MU_LAW
cat sample.wav | aplay

Is there a way to do the same from terminal in OSX? I think afplay doesn't support this ...

Maybe someone knows another OSX command line sound player that would do the trick?

like image 385
sebpiq Avatar asked Jan 15 '16 10:01

sebpiq


1 Answers

I had high hopes for redirection/piping, but afplay /dev/stdin <<< $(generate_sound.py) failed for all the formats I tried. Sadly afplay doesn't let you specify the format, and so it tries instead to sniff it which probably involves seeking which doesn't work with pipes.

I think you'd better find another command line player. sox seems like a good candidate. And! It's installable via homebrew: brew install sox and you can pipe data to it like so:

cat whatever.raw | play -t raw -e floating-point -b 32 -c 2 -r 44100 -

like image 186
Rhythmic Fistman Avatar answered Oct 06 '22 18:10

Rhythmic Fistman