I\'m running into an issue when I boot my PC the .mp3 file stops once the system speech is completed. I\'d like it to run a little longer. Syntax below.
\'Add-Ty
Untested, but you probably could insert a wait loop after starting to play the mp3, to see if the music has finished or not. Something like:
$mediaPlayer = New-Object system.windows.media.mediaplayer
$mediaPlayer.open('C:\Users\avery\Videos\01 - Highway To Hell.mp3')
$mediaPlayer.Play()
while (!($mediaPlayer.MediaEnded)) {
Start-Sleep -Milliseconds 500
}
$mediaPlayer.Close()
Sleep until to current position of the media player control reaches the total duration of the song:
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName System.Speech
$mp = New-Object System.Windows.Media.MediaPlayer
$mp.Open('C:\Users\avery\Videos\01 - Highway To Hell.mp3')
$mp.Play()
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.Rate = -2 # -10 to 10; -10 is slowest, 10 is fastest
$speak.Speak('Welcome home sir. You will need to pay attention the entire duration. With every
passing hour I will monitor your actions. Enjoy your time sir. Thank you for your time today and I
hope you accomplish everything you set your mind to. The world is your oyster.')
# Sleep until the songs over
do{
Write-Host "Waiting for the song to end..."
Start-Sleep -Seconds 1
}while($mp.NaturalDuration.HasTimeSpan -and $mp.Position -lt $mp.NaturalDuration.TimeSpan)
Write-Host "Done!"