Search code examples
c#unity-game-enginespeech-recognitionibm-watsonspeech-to-text

Using IBM Watson's speech-to-text causes method to be called more than once when keyword is recognized


I am using the IBM Watson Speech-To-Text in my Unity program to recognize speech. In the onRecognize() method, which recognizes speech, I placed an if statement that would call a method if it recognized the keyword "go". Although, when the word "go" is recognized, the method is called twice or three times instead of once like it should, which causes the program to not work the way it should.

I can't think of any solutions, as this is there is not much I can do to change the code.

//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.
}

I expect the following code segment to only call the method once when the word "go" is detected, but instead it is called twice or three times. This causes it to look buggy and not what I'd like. Any help would be appreciated.


Solution

  • Add a check for res.final?

    if (res.final && alt.transcript.Contains("go"))
    {
        anim.Play("move", -1, 0f); //This will play an animation.
    }