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?
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 -
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With