How to determine if sentence-in-text sentence detection (Unity IBM Watson sdk) is complete?

I want to send an offer to the server every time it finishes detecting the offer.

For example, when he discovers, I say "How do I do this." I want to send this offer to the server. However, the following method is called every time it tries to make a sentence. For example, when I say “How can I do this,” it will print “how,” “how to do this,” “how to do this,” is there a place where I can know that the sentence is complete?

private void OnRecognize(SpeechRecognitionEvent result)
{
    m_ResultOutput.SendData(new SpeechToTextData(result));

    if (result != null && result.results.Length > 0)
    {
        if (m_Transcript != null)
             m_Transcript.text = "";

        foreach (var res in result.results)
        {
            foreach (var alt in res.alternatives)
            {
                string text = alt.transcript;

                if (m_Transcript != null)
                {
                        //   print(text);

                        //m_Transcript.text += string.Format("{0} ({1}, {2:0.00})\n",
                        //    text, res.final ? "Final" : "Interim", alt.confidence);

                        m_Transcript.text = text;
                }
            }       
        }   
    }
}
+4
source share
1 answer

There is a property in the response object final.

private void OnRecognize(SpeechRecognitionEvent result)
{
    m_ResultOutput.SendData(new SpeechToTextData(result));

    if (result != null && result.results.Length > 0)
    {
        if (m_Transcript != null)
             m_Transcript.text = "";

        foreach (var res in result.results)
        {
            foreach (var alt in res.alternatives)
            {
                string text = alt.transcript;

                if (m_Transcript != null)
                {
                    // print(text);

                    //m_Transcript.text += string.Format("{0} ({1}, {2:0.00})\n",
                    //  text, res.final ? "Final" : "Interim", alt.confidence);

                    if(res.final)
                    {
                        m_Transcript.text = text;
                        //  do something with the final transcription
                    }
                }
            }       
        }   
    }
}
+4

Source: https://habr.com/ru/post/1671567/


All Articles