-
-
Save asheroto/63e56848eae5af3b7d670a9a7014eee7 to your computer and use it in GitHub Desktop.
Play sound in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Native sound player (wav only) | |
$player = New-Object System.Media.SoundPlayer "$env:windir\Media\notify.wav" | |
$player.Play() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows Media Player (mp3, wav, any common format) | |
Add-Type -AssemblyName presentationCore | |
$mediaPlayer = New-Object System.Windows.Media.MediaPlayer | |
$mediaPlayer.open("C:\Path\To\Your\Sound.mp3") | |
# Give time to load the file | |
Start-Sleep -Seconds 1 | |
# Set duration of sound to var | |
$duration = $mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds | |
# Play sound | |
$mediaPlayer.Play() | |
# Wait until duration has elapsed | |
Start-Sleep -Seconds $duration | |
# Stop and close | |
$mediaPlayer.Stop() | |
$mediaPlayer.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment