我想在每次检测完句子后将其发送到服务器。
例如,当检测到我说“我该怎么办”。我想将此句子发送到服务器。但是,以下方法在每次尝试组成句子时都会被调用。例如,当我说“我该怎么做”时,它会打印“如何”,“怎么做”,“我怎么做”,是否有一个我可以知道句子结束的地方?
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;
}
}
}
}
}
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
}
}
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句