我希望能够为我的文本转语音输出选择替代语音。
\n我正在使用 ComObject SAPI.SPVoice,但我发现我无法更改实际使用的语音。
\n(顺便说一句 - 我正在使用 SAPI.SPVoice,因为它适用于 Windows 10 上的 PowerShell Core 和 PowerShell Desktop)
${PromptTTS} = New-Object -ComObject SAPI.SPVoice\nRun Code Online (Sandbox Code Playgroud)\n\n\xe2\x9d\xaf $PromptTTS | gm\nRun Code Online (Sandbox Code Playgroud)\n\n TypeName: System.__ComObject#{269316d8-57bd-11d2-9eee-00c04f797396}\n\nName MemberType Definition\n---- ---------- ----------\nDisplayUI Method void DisplayUI (int hWndParent, string Title, string TypeOfUI, Variant ExtraData)\nGetAudioOutputs Method ISpeechObjectTokens GetAudioOutputs (string RequiredAttributes, string OptionalAttributes)\nGetVoices Method ISpeechObjectTokens GetVoices (string RequiredAttributes, string OptionalAttributes)\nIsUISupported Method bool IsUISupported (string TypeOfUI, Variant ExtraData)\nPause Method void Pause ()\nResume Method void Resume ()\nSkip Method int Skip (string Type, int …Run Code Online (Sandbox Code Playgroud) 我在 WindowsPowerShell 和 PowerShell 中都有相同的 profile.ps1。它包括调用 Windows Text-To-Speech 的命令,但是,这些命令在 PowerShell 7 中运行时会失败。
当我尝试使用我使用以下代码创建的 $PomrptTTS 对象时会发生错误:
Add-Type -AssemblyName System.speech
$PromptTTS = New-Object System.Speech.Synthesis.SpeechSynthesizer
Run Code Online (Sandbox Code Playgroud)
在 PowerShell 7 中,任何访问或使用我的 $PormptTTS 对象的尝试都会产生以下结果:
SetValueInvocationException: ....\profile.ps1:82
Line |
82 | $PromptTTS.Rate = 0 ; $PromptTTS.Speak("Time for the $((Get-Date).DayofWeek) shuffle")
| ~~~~~~~~~~~~~~~~~~~
| Exception setting "Rate": "Object reference not set to an instance of an object."
MethodInvocationException: ....\profile.ps1:82
Line |
82 | … e = 0 ; $PromptTTS.Speak("Time for the $((Get-Date).DayofWeek) shuffle")
| ~~~~~~~~~~~~~~~~~~~~
| Exception calling …Run Code Online (Sandbox Code Playgroud)