SoundPlay

Plays a sound, video, or other supported file type.

SoundPlay Filename , Wait

Note: Which file types can be played depends on the platform and, on Linux, on which audio player is installed. See Linux and macOS below.

Parameters

Filename

Type: String

The name of the file to be played, which is assumed to be in A_WorkingDir if an absolute path isn't specified.

To produce standard system sounds, specify an asterisk followed by a number as shown below (note that the Wait parameter has no effect in this mode):

Wait

Type: Integer (boolean) or String

If blank or omitted, it defaults to 0 (false). Otherwise, specify one of the following values:

0 (false): The current thread will move on to the next statement(s) while the file is playing.

1 (true) or Wait: The current thread waits until the file is finished playing before continuing. Even while waiting, new threads can be launched via hotkey, custom menu item, or timer.

Known limitation: If the Wait parameter is not used, the system might consider the playing file to be "in use" until the script closes or until another file is played (even a nonexistent file).

Error Handling

An exception is thrown on failure.

Remarks

All Windows systems should be able to play .wav files. However, other file types (.mp3, .avi, etc.) might not be playable if the right codecs or features aren't installed on the system.

Due to a quirk in Windows, .wav files with a path longer than 127 characters will not be played. To work around this, use other file types such as .mp3 (with a path length of up to 255 characters) or use 8.3 short paths (see A_LoopFileShortPath how to retrieve such paths).

If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play. On some systems, certain file types might stop playing even when an entirely separate script plays a new file.

To stop a file that is currently playing, use SoundPlay on a nonexistent filename as in this example: try SoundPlay "Nonexistent.avi".

If the script is exited, any currently-playing file that it started will stop.

Linux

Playback is delegated to the first installed player that can decode the file: paplay or aplay for uncompressed and libsndfile formats (WAV, FLAC, Ogg, AIFF, AU), otherwise ffplay, mpv, gst-play-1.0 or mpg123. A file a player cannot decode is never handed to it, so compressed formats such as .mp3 require one of the latter. If no suitable player is installed, an error naming them is thrown.

The standard sounds come from the freedesktop sound theme (usually the sound-theme-freedesktop package). When it is not installed, a synthesized beep is played instead.

macOS

Playback uses afplay, which handles the formats CoreAudio supports, including WAV, AIFF, CAF, MP3 and M4A.

The standard sounds come from /System/Library/Sounds, falling back to a synthesized beep if the chosen sound is missing.

SoundBeep, Sound Functions, MsgBox, Threads

Examples

Plays a .wav file located in the Windows directory.

SoundPlay A_WinDir "\Media\ding.wav"

Generates a simple beep.

SoundPlay "*-1"