【发布时间】:2020-02-06 00:49:24
【问题描述】:
我正在尝试统一使用语音识别程序。我正在使用 UnityEngine.Windows.Speech.KeywordRecognizer。但是,每当我运行程序时,都会收到以下错误:
MissingMethodException: 试图访问一个 缺少方法。 UnityEngine.Windows.Speech.KeywordRecognizer..ctor (System.String[] 关键字,UnityEngine.Windows.Speech.ConfidenceLevel 最低置信度)(在 /Users/builduser/buildslave/unity/build/Runtime/Export/Windows/Speech.cs:221) UnityEngine.Windows.Speech.KeywordRecognizer..ctor (System.String[] 关键字)(在 /Users/builduser/buildslave/unity/build/Runtime/Export/Windows/Speech.cs:201) VoiceRecognition.Start () (at Assets/VoiceRecognition.cs:23)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Windows.Speech;
using UnityEngine.UI;
public class VoiceRecognition : MonoBehaviour
{
public string[] keywords = { "right", "left", "up", "down" };
public ConfidenceLevel confidence = ConfidenceLevel.Low;
public float speed = 1;
public Text results;
public Image target;
private KeywordRecognizer recognizer;
protected string word = "right";
private void Start()
{
if (keywords != null)
{
recognizer = new KeywordRecognizer(keywords, confidence); #Source of error
recognizer.OnPhraseRecognized += Recognizer_OnPhraseRecognized;
recognizer.Start();
}
}
private void Recognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
word = args.text;
results.text = "You said: <b>" + word + "</b>";
}
#Code to move image
private void Update()
{
var x = target.transform.position.x;
var y = target.transform.position.y;
switch (word)
{
case "up":
y += speed;
break;
case "down":
y -= speed;
break;
case "left":
x -= speed;
break;
case "right":
x += speed;
break;
}
target.transform.position = new Vector3(x, y, 0);
}
private void OnApplicationQuit()
{
if (recognizer != null && recognizer.IsRunning)
{
recognizer.OnPhraseRecognized -= Recognizer_OnPhraseRecognized;
recognizer.Stop();
}
}
}
当用户说“右”、“左”、“上”或“下”时,我希望能够移动图像,但我不断收到 MissingMethodException,并且我的图像一直向一个方向移动,无论如何我告诉它的。
【问题讨论】:
-
这是哪个版本的 unity?
-
@BugFinder,我在我的 Mac 上使用 Unity 版本 2018.3.8f1。
-
好吧,对不起,我的 Windows 机器上没有发生这种情况 - 我没有要检查的 mac。
-
好的。感谢您的帮助!
标签: c# unity3d voice-recognition