If you want to play a sound from the macOS command line, you can make use of the afplay command. Simply follow the steps below:

  1. Open the Terminal application on your Mac.
  2. Type the following command: afplay file.mp3
  3. Replace file.mp3 with the path to the sound file you want to play.

Additionally, here are some more options for the afplay command that you can experiment with:

  • Play a sound file and wait until playback ends:

    afplay path/to/file
    
  • Play a sound file at 2x speed (adjust the playback rate):

    afplay --rate 2 path/to/file
    
  • Play a sound file at half speed:

    afplay --rate 0.5 path/to/file
    
  • Play only the first N seconds of a sound file:

    afplay --time seconds path/to/file
    

If you prefer to have your Mac speak instead of playing a sound file, you can accomplish this using the say command. Here’s how you can do it:

  1. Open the Terminal application on your Mac.
  2. Type the following command: say "test"
  3. Replace "test" with the text you want your Mac to speak.

You can even customize the voice used by the say command. For example, if you want your Mac to speak with a voice named “Fred,” you can use the following command:

say -v Fred "Isn't it nice to have a computer that will talk to you?"

That’s it! Now you can easily play sounds or make your Mac talk from the macOS command line. Happy commanding!