我正在尝试统一测试语音识别程序。我正在使用UnityEngine.Windows.Speech.KeywordRecognizer。但是,每当我运行该程序时,都会出现以下错误:
MissingMethodException:尝试访问一个 缺少方法。 UnityEngine.Windows.Speech.KeywordRecognizer..ctor (System.String []关键字,UnityEngine.Windows.Speech.ConfidenceLevel minimumConfidence)(在 /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()(位于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,并且无论如何我的图像都向一个方向移动我所说的话。
答案 0 :(得分:0)
自从您提到MacOS以来,我很遗憾地告诉您,您使用的API方法仅适用于Windows 10。
摘自文档:Keyword recognizer is currently functional only on Windows 10.
来源:https://docs.unity3d.com/ScriptReference/Windows.Speech.KeywordRecognizer.html