Starting airplay from command line, to send output of 'Say' Mac OS X command to airplay

Solution 1:

I was playing with this a couple of weeks ago.

To send to my Apple Tv via airplay I used

 say -r160 -a "AirPlay" "Hover over a Method name while holding down the Option key until a question mark  appears"

One thing I noticed at the time was that I sometimes would have to run a second command to switch the audio back to the computer.

 say -r160 -a "AirPlay" "Hover over a Method";say -r160 -a "Built-in Output" "I am back"

*update Just tested using the numbers and they work just as well in place of the device name.

Solution 2:

Yes - I am not getting this to work and conclude that it's not your or my setup, but perhaps a bug or deficient documentation in the man page. The way this is supposed to work is that you simply execute the say command and point the output to the desired device.

 say -a 37 hi
 say -a 47 hi

On my MacBook Pro, I have 37 for AirPlay, 47 for internal speakers and 64 for the DisplayPort cinema display speakers. Devices 47 and 64 work correctly, but when I send any audio to AirPlay (either before or after selecting one of the several AppleTV and AirPlay receivers that are otherwise workable) - the say command errors with error -50.

 Setting audio output device failed: -50

I agree this would be fun to use and have filed a bug with Apple. Let's see if they can point us to a missing step or if it's really just needing for the say program to get a patch.

After seeing the other answer by markhunte, I tried using say -a "AirPlay" "hello" and it worked for me to have AirPlay output spoken. Once that command was run, the -a 37 works now too. I'm now curious if it's just something that is fragile or the text somehow gets things connected better.