4

I want to send to server the sentence every time it finishes detecting a sentence.

For example, when it detects I speak "How do I do". I want to send this sentence to the server. However, the following method is called every time it tries to form up a sentence. For example, when I speak "How do I do", it will print "how", "how do", "how do I do", is there a place I can know a sentence is finished?

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;
                }
            }       
        }   
    }
}
Joshua Smith
  • 6,561
  • 1
  • 30
  • 28
weijia_yu
  • 965
  • 4
  • 14
  • 31
  • This seems to be the code that is run _after_ a sentence has been recognized, but you seem to want help with recognizing? Show us where this event is raised! (disclaimer: I'm not familiar with the watson cognitive) – Fredrik Schön Mar 06 '17 at 08:29

1 Answers1

5

There is a final property in the response object.

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
                    }
                }
            }       
        }   
    }
}
taj
  • 1,128
  • 1
  • 9
  • 23