【发布时间】:2019-03-29 04:49:08
【问题描述】:
我正在为项目的一部分进行文本转语音,Matlab 有一些功能可以引入 .NET 程序集,but with very limited documentation。我无法调用一些方法来改变声音。 Microsoft's SystemSpeech documentation implies that this should work,但是当我尝试时出现此错误:
objspeech.SelectVoice('Anna')
Message: Cannot set voice. No matching voice is installed or the voice was
disabled.
Source: System.Speech
HelpLink:
这是我的代码的最小工作版本:
NET.addAssembly('System.Speech');
objspeech = System.Speech.Synthesis.SpeechSynthesizer;
% objspeech.SelectVoice('Anna');
objspeech.Volume = 100;
SpeakAsync(objspeech, 'Hello World');
唯一的失败是 SelectVoice。我不知道如何改变它。运行 objspeech.GetInstalledVoices 返回:
ReadOnlyCollection<System*Speech*Synthesis*InstalledVoice> with properties:
Count: 2
有人知道为什么 SelectVoice 不起作用吗?
【问题讨论】:
-
SelectVoice会工作。你打电话给SelectVoiceByHints。两个不同的函数,需要不同的参数。 -
我意识到这一点。 SelectVoice 不像宣传的那样工作 - 微软说在 C# 中你可以说 SelectVoice("Anna") 并且它会改变声音,但是 Matlab 会抛出与我在尝试时为 SelectVoiceByHints 添加的错误相同的错误。
-
您显示的唯一错误是调用
SelectVoiceByHints。错误是正确的,您为SelectVoiceByHints传递了错误的参数。SelectVoice接受字符串参数,SelectVoiceByHints不接受。如果您在尝试调用SelectVoice时遇到错误,请显示该确切错误。 -
哦,看,这是一个完全不同的错误信息。您确切地知道为什么
SelectVoice不起作用。您的问题实际上是关于如何查看从GetInstalledVoices返回的数据。由于它的类型为IEnumerable<InstalledVoice>,这将对您有所帮助:How can I work with IEnumerable<T> return types when working with the .NET Interface in MATLAB? -
相关:stackoverflow.com/q/6614040/103167 和 stackoverflow.com/q/6388688/103167 不幸的是,看起来所有的答案都有些混乱。您可能想要编写一个实用函数来跳
GetEnumerator()舞蹈。