Skip to content

Instantly share code, notes, and snippets.

@PSingletary
Created December 6, 2019 20:56
Show Gist options
  • Select an option

  • Save PSingletary/e1e1ae7fe618ff382fbc5b9d3eb5b25b to your computer and use it in GitHub Desktop.

Select an option

Save PSingletary/e1e1ae7fe618ff382fbc5b9d3eb5b25b to your computer and use it in GitHub Desktop.
2014-12-23 a quick script to make a windows speak then play random music
Add-Type -AssemblyName presentationCore
Add-Type -AssemblyName System.speech
$mediaPlayer = New-Object system.windows.media.mediaplayer
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$files = Get-ChildItem -path $path -include *.mp3 -recurse
#$speak.Rate = -10 # -10 to 10; -10 is slowest, 10 is fastest`
$speak.Speak("Ho Ho Ho")
$mediaPlayer.open([uri]"$(Get-Random -InputObject $files)")
$mediaPlayer.Play()
#Start-Sleep -Seconds 30
Start-Sleep -seconds 2 # need to wait for mediaPlayer to determine file duration
Start-Sleep -seconds $mediaPlayer.NaturalDuration.TimeSpan.TotalSeconds
$mediaPlayer.Stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment