Skip to main content

How to Create a Notification Sound Along with Text Display in Batch Script

Visual alerts are often not enough, especially if a script is running in the background or during a long-duration process where the user has stepped away from their computer. An Auditory Notification (a beep, chime, or sound effect) can immediately signal when an error occurs, when a lengthy backup is complete, or when user input is required.

In this guide, we will demonstrate how to generate notification sounds using both native Batch techniques and PowerShell sound capabilities.

Method 1: The Classic "System Beep" (ASCII BEL)

The simplest sound a Batch script can make is the system beep. This is generated by outputting the BEL character (ASCII 7) to the console.

Implementation

Since the BEL character is a non-printable control character that cannot be reliably typed or preserved in most text editors, the most portable approach is to generate it within the script:

@echo off

echo TASK COMPLETE!

:: Generate and play the BEL character using a PowerShell helper
:: This avoids the need to embed non-printable characters in the source file
for /F %%b in ('powershell -nologo -noprofile -command "[char]7"') do set "BEL=%%b"
echo %BEL%

pause

Alternatively, if your script already uses PowerShell for the beep, Method 2 provides more control over the sound.

info

About the BEL character: The traditional approach of typing Alt+7 on the numeric keypad to insert a ^G character works in some editors, but many modern editors (VS Code, Notepad++, Sublime Text) strip or corrupt non-printable control characters when saving. The PowerShell approach above generates the character at runtime, making the script portable regardless of which editor is used.

Method 2: The Professional Notification Chime (PowerShell)

For more control over the sound, you can call PowerShell to play a console beep at a specific frequency or play a standard Windows notification sound file.

Implementation Script

@echo off
setlocal

echo [OK] Synchronization Finished.

:: Option A: Play a console beep at 800 Hz for 200ms
powershell -nologo -noprofile -command "[Console]::Beep(800, 200)"

:: Option B: Play a standard Windows notification sound file
:: Always check the file exists first, as stripped-down Windows Server
:: installations may not include the Media folder
if exist "C:\Windows\Media\notify.wav" (
powershell -nologo -noprofile -command ^
"(New-Object Media.SoundPlayer 'C:\Windows\Media\notify.wav').PlaySync()"
) else (
echo [NOTE] Sound file not found. Using console beep instead.
powershell -nologo -noprofile -command "[Console]::Beep(800, 200)"
)

endlocal
pause

Comparing the two options:

  • [Console]::Beep(800, 200): Generates a tone through the system speaker or audio device. Works on all Windows systems. The first parameter is frequency in Hz (pitch), the second is duration in milliseconds.
  • Media.SoundPlayer: Plays a .wav audio file through the default audio output. Produces a more pleasant sound but depends on the file existing on the system.

Method 3: The "Custom Melody" (Beep Frequencies)

If you want to create a specific "Success" melody (e.g., three rising tones) or an "Error" alert, you can chain multiple [Console]::Beep calls with different frequencies.

@echo off

echo ACCESS GRANTED

:: Success melody: C5 (523 Hz), E5 (659 Hz), G5 (784 Hz) - a major chord
powershell -nologo -noprofile -command ^
"[Console]::Beep(523, 150);" ^
"[Console]::Beep(659, 150);" ^
"[Console]::Beep(784, 300)"

pause
@echo off

echo ACCESS DENIED

:: Error alert: Two short low tones
powershell -nologo -noprofile -command ^
"[Console]::Beep(300, 200);" ^
"Start-Sleep -Milliseconds 100;" ^
"[Console]::Beep(200, 400)"

pause

Method 4: The Speech Notification (Text-to-Speech)

Sometimes a sound is not clear enough. You can make your Batch script actually speak to the user using the Windows Text-to-Speech (TTS) engine.

@echo off
setlocal enabledelayedexpansion

set "msg=The backup process has finished with three errors."

echo !msg!

:: Use the .NET SpeechSynthesizer to speak the message
:: The message is passed via a temporary variable to avoid
:: special character issues in the PowerShell command string
powershell -nologo -noprofile -command ^
"Add-Type -AssemblyName System.Speech;" ^
"$synth = New-Object System.Speech.Synthesis.SpeechSynthesizer;" ^
"$synth.Speak('%msg%')"

endlocal
pause
warning

Special characters in TTS messages: If the message variable contains characters that have special meaning in PowerShell strings (such as single quotes ', double quotes ", dollar signs $, or backticks `), the Speak() call may fail or produce unexpected results. For messages with complex content, consider writing the text to a temporary file and reading it from PowerShell instead.

When to Use Audio Notifications

  • Long Processes: When a script takes more than 1 minute to run, a chime tells the user they can return to their workstation.
  • Errors: A distinctive low-pitched tone is the fastest way to signal that a script has failed or requires attention.
  • Completion Alerts: A pleasant rising melody confirms that a backup, deployment, or build has finished successfully.

Best Practices

  1. Don't Spam: Never put a beep inside a fast loop. This creates an extremely annoying buzzing sound that may cause users to mute their systems permanently.
  2. Provide a Silent Mode: If possible, include a /silent flag in your script that disables audio cues for users who are in quiet environments:
    set "silent=0"
    if /i "%~1"=="/silent" set "silent=1"
    :: Later in the script:
    if !silent! equ 0 (
    powershell -nologo -noprofile -command "[Console]::Beep(800, 200)"
    )
  3. Check for Sound Files: If playing a specific .wav file, always verify it exists with if exist before attempting playback. Stripped-down Windows Server installations often do not include the C:\Windows\Media folder.
  4. Use Distinct Sounds: Use different tones or melodies for different events (success vs. error vs. warning) so users can identify the situation by sound alone without looking at the screen.

Conclusion

Combining audio notifications with text displays transforms your Batch script into a multi-sensory tool. Whether you use a simple console beep for quick alerts or a PowerShell-powered voice notification for detailed reports, you ensure that your automation results are heard as well as seen, significantly improving the responsiveness and reliability of your workflows.