Powershell script on startup stopping .mp3

前端 未结 2 1843
轮回少年
轮回少年 2021-01-29 04:51

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         


        
2条回答
  •  忘掉有多难
    2021-01-29 05:24

    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!"
    

提交回复
热议问题