首页 文章

在Unity中使用Windows语音识别API

提问于
浏览
1

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

那个.dll我从“Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.6”中得到它 . 有趣的是在MS Visual Studio中它实际上检测到dll和我可以写:使用System.Speech但Unity不想接受.dll . 我看了不同的帖子,但没有任何对我有用 . 任何帮助赞赏 .

1 回答

  • 1

    你不需要 System.Speech.dll ,它有很多问题,因为它使用Mono . 只需导入 UnityEngine.Windows.Speech 命名空间就可以了 . 这需要Unity 5.4.0b2及更高版本才能在Windows上运行 .

    您有不同类型的spech API,例如DictationRecognizerGrammarRecognizerKeywordRecognizerPhraseRecognitionSystemPhraseRecognizer . 该文档有很多关于如何使用每个例子的例子 .

    以下是doc中KeywordRecognizer的示例:

    [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,因为您的目标是Window-64位 . 对于其他平台,请参阅this post .

相关问题