c# - 如何将 C# 语法翻译成 Matlab?
问题描述
我正在为项目的一部分进行文本到语音转换,Matlab 有一些功能可以引入 .NET 程序集,但文档非常有限。我无法调用一些方法来改变声音。Microsoft 的 SystemSpeech 文档暗示这应该可以工作,但是当我尝试时出现此错误:
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 不起作用?
解决方案
以下是我为最终获得所有可用声音并选择不同的声音所做的工作:
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 访问。
推荐阅读
- list - 在 C# 中,当列表和枚举类型中的对象没有公共继承或接口时,是否可以删除代码重复?
- c# - 部分实例化
- pandas - 基于另一列的值的列中不同字符串的累积计数
- reactjs - flex: 1, 不能正常工作 react-native
- user-interface - AppleScript - 当从应用程序(而不是从 Finder)提示时,如何设置 finder 窗口提示的目标/路径?
- php - PHP 7.2.11 如何从多维数组中删除重复值
- join - 合并两个文件并保留所有列
- php - 搜索多维数组并从结果中创建一个新数组
- using-statement - 在 using 语句中使用的类型应该可以隐式转换为 IDeisposable
- dart - dart 在另一个文件中显示来自另一个方法的文档