我在Unity程序中使用IBM Watson Speech- to -Text来识别语音。在识别语音的onRecognize()方法中,我放置了一个if语句,如果该语句识别出关键字"go“,则该语句将调用一个方法。尽管当"go“这个词被识别出来时,该方法会被调用两到三次,而不是像它应该调用的那样调用一次,这会导致程序不能以它应该的方式工作。
我想不出任何解决方案,因为我不能做太多来改变代码。
//All of this is inside of the onRecognize() method
string text = string.Format("{0} ({1}, {2:0.00})\n", alt.transcript, res.final ? "Final" : "Interim", alt.confidence);
Log.Debug("ExampleStreaming.OnRecognize()", text);
ResultsField.text = text;
//This if statement inside of the onRecognize() method will play an
//animation if it detects the word "go"
if (alt.transcript.Contains("go"))
{
anim.Play("move", -1, 0f); //This will play an animation.
}我希望下面的代码段在检测到单词"go“时只调用该方法一次,而不是调用两到三次。这会导致它看起来像buggy,而不是我想要的。任何帮助都将不胜感激。
发布于 2019-09-07 11:50:02
是否为res.final添加检查?
if (res.final && alt.transcript.Contains("go"))
{
anim.Play("move", -1, 0f); //This will play an animation.
}https://stackoverflow.com/questions/57829649
复制相似问题