How to play a sound from the command line AND direct the output

audioterminal

I am aware of the afplay command to play an audio file. When I do that it plays through the current selected Sound Output. If I have my headphones in, it plays on the headphones. How can I specify that the sound plays over the Built-In Speakers?

In the Sounds System Preferences you can select the Alerts tab and direct the output of the Alert to a specific output. I am looking to do the same but with my own customs sounds triggered by the command line.

Best Answer

If you are looking for your computer to play sounds or words you can use the "say" command on the terminal. Just type

say dog

and the computer responds with dog over whatever speakers you have chosen from the Sound selection under system preferences. Go to system preferences and choose the Sound icon. When that opens you can select options for what plays the sound on your computer. One option is the internal speakers.