我想要一些能够说出 foobar 中当前播放曲目名称的东西,我能想到的最好的办法是使用 WSH 面板启动 powershell 文本到语音脚本,但是我无法在 WSH 面板中获取曲目名称..我的 WSH 面板脚本如下所示:
function on_playback_starting(cmd, is_paused) {
var track_path = fb.TitleFormat("%title%");
WSH = new ActiveXObject("WScript.Shell");
WSH.run("powershell.exe -noexit -ExecutionPolicy ByPass -f c:\\users\\jrg26\\documents\\windowspowershell\\text2speech.ps1 \"test " + track_path+" test part 2\"");
}
它说出测试“测试”和“测试第 2 部分”,但没有说出曲目名称。它甚至没有传递它,因为我已将脚本设置为回显参数,并且它只为每首歌曲显示“测试测试第 2 部分”。那么我该如何以我尝试的方式传递曲目名称呢?
答案1
我还有一个小问题,修复后忘了回答。谢谢,希望有人觉得它有用:
朗读艺术家+专辑+曲目名称,清理文本以免朗读不必要的内容:
function replace_it(str)
{
str = str.replace(",","(")
str = str.replace("-","(")
str = str.replace(")","(")
str = str.replace("[","(")
str = str.replace("]","(")
str = str.replace("\\","(")
str = str.replace("/","(")
str = str.replace(":","(")
var str_index = str.indexOf("(")
if (str_index != -1)
{
str = str.substring(0,str_index)
}
return str
}
function on_playback_new_track(metadb) {
WSH = new ActiveXObject("WScript.Shell");
var artist = fb.TitleFormat("%artist%").Eval(true)
var album = fb.TitleFormat("%album%").Eval(true)
var track_name = fb.TitleFormat("%Title%").Eval(true);
artist = replace_it(artist)
album = replace_it(album)
track_name = replace_it(track_name)
track_path="Artist "+artist+" Album " +album+" track name "+ track_name
fb.Pause()
WSH.run("powershell.exe -nologo -NonInteractive -ExecutionPolicy ByPass -WindowStyle Hidden -f c:\\users\\jrg26\\documents\\windowspowershell\\text2speech.ps1 \"" + track_path + "\"",0,true);
fb.play()
}
还有 powershell 脚本,以防有人想要这个解决方案:
if ($args.count -gt 0)
{
echo $args[0]
Add-Type -AssemblyName System.speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.Speak($args[0])
}
您还可以增加或降低语音速率。输入 $speak|get-member,在添加类型并创建对象后获取属性和方法的列表:
Rate Property int Rate {get;set;}
Voice Property System.Speech.Synthesis.VoiceInfo Voice {get;}
Volume Property int Volume {get;set;}
SelectVoice Method void SelectVoice(string name)
SelectVoiceByHints Method void SelectVoiceByHints(System.Speech.Synthesis.VoiceGender gender),
$speak.rate = -5
将比率更改为 -5,从 -10 变为 10。
$speak.selectvoicebyhints("female")
改为美国女声。