C# 在Unity中使用Windows语音识别API

C# 在Unity中使用Windows语音识别API,c#,.net,unity3d,dll,C#,.net,Unity3d,Dll,我试图将System.Speech.dll添加到Unity项目中,但我得到System.BadImageFormatException。我使用的是64位Windows 10。构建设置是为x86_64设置的,我使用的脚本运行时版本是“.Net 4.x等效版本” 我从“程序文件(x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6”中获取的.dll。有趣的是,在微软的Visual Studio中,它实际上检测到了那个dll,我

我试图将System.Speech.dll添加到Unity项目中,但我得到System.BadImageFormatException。我使用的是64位Windows 10。构建设置是为x86_64设置的,我使用的脚本运行时版本是“.Net 4.x等效版本”


我从“程序文件(x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6”中获取的.dll。有趣的是,在微软的Visual Studio中,它实际上检测到了那个dll,我可以编写:使用System.Speech,但Unity不想接受那个.dll。我浏览了不同的帖子,但没有一篇对我有用。非常感谢您的帮助。

您不需要
System.Speech.dll
,因为它使用的是Mono,所以会带来很多问题。只需导入
UnityEngine.Windows.Speech
名称空间,就可以了。这需要Unity 5.4.0b2及以上版本才能在Windows上工作

您有不同类型的spech API,如、、和。文档中有许多关于如何使用每一个的示例

以下是来自文档的示例:

[SerializeField]
private string[] m_Keywords;

private KeywordRecognizer m_Recognizer;

void Start()
{
    m_Recognizer = new KeywordRecognizer(m_Keywords);
    m_Recognizer.OnPhraseRecognized += OnPhraseRecognized;
    m_Recognizer.Start();
}

private void OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
    StringBuilder builder = new StringBuilder();
    builder.AppendFormat("{0} ({1}){2}", args.text, args.confidence, Environment.NewLine);
    builder.AppendFormat("\tTimestamp: {0}{1}", args.phraseStartTime, Environment.NewLine);
    builder.AppendFormat("\tDuration: {0} seconds{1}", args.phraseDuration.TotalSeconds, Environment.NewLine);
    Debug.Log(builder.ToString());
}

这仅适用于Windows,因为您的目标是Windows-64位。有关其他平台,请参阅文章。

UnityEngine.Windows.Speech仅支持语音识别,不支持语音合成。System.Speech同时支持这两种功能。@Haydn如果是这样的话,请创建自己的插件。我链接到了另一篇文章,该文章的API是用来使用系统的。语音是唯一一个有Viseme信息的,并且是免费的。这就是我为什么要用它的原因。我尝试使用插件中的System.Speech,但unity只是禁用了插件。