启动时停止 .mp3 的 Powershell 脚本 [英] Powershell script on startup stopping .mp3

查看:40
本文介绍了启动时停止 .mp3 的 Powershell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在启动 PC 时遇到问题,系统语音完成后 .mp3 文件停止.我希望它运行的时间长一点.语法如下.

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-Type -AssemblyName presentationCore
$mediaPlayer = New-Object system.windows.media.mediaplayer
$mediaPlayer.open('C:\Users\avery\Videos\01 - Highway To Hell.mp3')
$mediaPlayer.Play()

Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$tts.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.')'

它运行得很好,我只是不知道为什么它会停止.当我在 Powershell ISE 中运行它时,它会继续播放 .mp3,但在启动时它会提前停止.我想添加一个论点来播放更长的时间,或者诱使它认为演讲更长.

It runs perfectly I'm just not sure why it stops short. When I run it in Powershell ISE it continues to play the .mp3 but on startup it stops early. I'd like to add an argument to play it longer, or trick it into thinking the speech is longer.

谢谢.

推荐答案

睡眠直到媒体播放器控件的当前位置达到歌曲的总时长:

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

这篇关于启动时停止 .mp3 的 Powershell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆