【问题标题】:How to translate C# syntax into Matlab?如何将 C# 语法翻译成 Matlab?
【发布时间】: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&lt;InstalledVoice&gt;,这将对您有所帮助:How can I work with IEnumerable<T> return types when working with the .NET Interface in MATLAB?
  • 相关:stackoverflow.com/q/6614040/103167stackoverflow.com/q/6388688/103167 不幸的是,看起来所有的答案都有些混乱。您可能想要编写一个实用函数来跳 GetEnumerator() 舞蹈。

标签: c# .net matlab


【解决方案1】:

为了最终获得所有可用的声音并选择不同的声音,我做了以下工作:

resultEnumerable = NET.explicitCast(result,'System.Collections.IEnumerable');
resultEnumerator = resultEnumerable.GetEnumerator();
resultEnumerator = NET.explicitCast(resultEnumerator, 'System.Collections.IEnumerator');
while (resultEnumerator.MoveNext)
    v1=resultEnumerator.Current;
    v1.VoiceInfo.Name
end

objspeech.SelectVoice(v1)

我的 v1 是“Microsoft Zira Desktop”,所以objspeech.SelectVoice('Microsoft Zira Desktop') 工作。奇怪的是,在 Windows 设置中,我安装并运行了 Microsoft David、Mark 和 Zira,但只有 David 和 Zira 可以通过 .NET 访问。

【讨论】:

  • 您的 UX Stackoverflow 帐户发生了什么变化?
  • @Confused 我在 Workplace SE 上被 doxxed 了,不得不删除很多东西。
  • Strewth。很抱歉听到这个消息。这似乎有点……不对。
  • 我经常被 Graphic Design SE 禁止使用,有时也被 UX 禁止使用。他们似乎不喜欢我表达自己的方式。它一点也不困扰我。但是doxxing...我不知道该说什么。大错特错。
猜你喜欢
  • 2011-04-27
  • 1970-01-01
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-17
  • 1970-01-01
相关资源
最近更新 更多