Assets/Watson/Scripts/Services/SpeechToText/SpeechToText.cs
/// <summary>
/// This function POSTs the given audio clip the recognize function and convert speech into text. This function should be used
/// only on AudioClips under 4MB once they have been converted into WAV format. Use the StartListening() for continuous
/// recognition of text.
/// </summary>
/// <param name="clip">The AudioClip object.</param>
/// <param name="callback">A callback to invoke with the results.</param>
/// <returns></returns>
This function POSTs the given audio clip the recognize function and convert speech into text. This function should be used
only on AudioClips under 4MB once they have been converted into WAV format. Use the StartListening() for continuous
recognition of text.
This function POSTs the given audio clip the recognize function and convert speech into text . This function should be used only on AudioClips under 4MB once they have been converted into WAV format . Use the StartListening () for continuous recognition of text .
public bool Recognize(AudioClip clip, OnRecognize callback)
        {
            if (clip == null)
                throw new ArgumentNullException("clip");
            if (callback == null)
                throw new ArgumentNullException("callback");
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/recognize");
            if (connector == null)
                return false;
            RecognizeRequest req = new RecognizeRequest();
            req.Clip = clip;
            req.Callback = callback;
            req.Headers["Content-Type"] = "audio/wav";
            req.Send = WaveFile.CreateWAV(clip);
            if (req.Send.Length > MAX_RECOGNIZE_CLIP_SIZE)
            {
                Log.Error("SpeechToText", "AudioClip is too large for Recognize().");
                return false;
            }
            req.Parameters["model"] = m_RecognizeModel;
            req.Parameters["continuous"] = "false";
            req.Parameters["max_alternatives"] = m_MaxAlternatives.ToString();
            req.Parameters["timestamps"] = m_Timestamps ? "true" : "false";
            req.Parameters["word_confidence"] = m_WordConfidence ? "true" : "false";
            req.OnResponse = OnRecognizeResponse;
            return connector.Send(req);
        }
public bool Recognize ( AudioClip clip , OnRecognize callback ) { if ( clip == null ) throw new ArgumentNullException ( " " ) ; if ( callback == null ) throw new ArgumentNullException ( " " ) ; RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , " " ) ; if ( connector == null ) return false ; RecognizeRequest req = new RecognizeRequest ( ) ; req . Clip = clip ; req . Callback = callback ; req . Headers [ " " ] = " " ; req . Send = WaveFile . CreateWAV ( clip ) ; if ( req . Send . Length > MAX_RECOGNIZE_CLIP_SIZE ) { Log . Error ( " " , " " ) ; return false ; } req . Parameters [ " " ] = m_RecognizeModel ; req . Parameters [ " " ] = " " ; req . Parameters [ " " ] = m_MaxAlternatives . ToString ( ) ; req . Parameters [ " " ] = m_Timestamps ? " " : " " ; req . Parameters [ " " ] = m_WordConfidence ? " " : " " ; req . OnResponse = OnRecognizeResponse ; return connector . Send ( req ) ; }
This function POSTs the given audio clip the recognize function and convert speech into text.
This function POSTs the given audio clip the recognize function and convert speech into text .
None
clip
AudioClip
The AudioClip object.
The AudioClip object .
callback
OnRecognize
A callback to invoke with the results.
A callback to invoke with the results .