Assets/Watson/Scripts/Services/SpeechToText/SpeechToText.cs
/// <summary>
/// This function should be invoked with the AudioData input after StartListening() method has been invoked.
/// The user should continue to invoke this function until they are ready to call StopListening(), typically
/// microphone input is sent to this function.
/// </summary>
/// <param name="clip">A AudioData object containing the AudioClip and max level found in the clip.</param>
This function should be invoked with the AudioData input after StartListening() method has been invoked.
The user should continue to invoke this function until they are ready to call StopListening(), typically
microphone input is sent to this function.
This function should be invoked with the AudioData input after StartListening () method has been invoked . The user should continue to invoke this function until they are ready to call StopListening () typically microphone input is sent to this function .
public void OnListen(AudioData clip)
        {
            if (m_IsListening)
            {
                if (m_RecordingHZ < 0)
                {
                    m_RecordingHZ = clip.Clip.frequency;
                    SendStart();
                }
                if (!DetectSilence || clip.MaxLevel >= m_SilenceThreshold)
                {
                    if (m_ListenActive)
                    {
                        m_ListenSocket.Send(new WSConnector.BinaryMessage(AudioClipUtil.GetL16(clip.Clip)));
                        m_AudioSent = true;
                    }
                    else
                    {
                        m_ListenRecordings.Enqueue(clip);
                        if (m_ListenRecordings.Count > MAX_QUEUED_RECORDINGS)
                        {
                            Log.Error("SpeechToText", "Recording queue is full.");
                            StopListening();
                            if (OnError != null)
                                OnError("Recording queue is full.");
                        }
                    }
                }
                else if (m_AudioSent)
                {
                    SendStop();
                    m_AudioSent = false;
                }
                if (!m_ListenActive && (DateTime.Now - m_LastStartSent).TotalSeconds > LISTEN_TIMEOUT)
                {
                    Log.Error("SpeechToText", "Failed to enter listening state.");
                    StopListening();
                    if (OnError != null)
                        OnError("Failed to enter listening state.");
                }
            }
        }
public void OnListen ( AudioData clip ) { if ( m_IsListening ) { if ( m_RecordingHZ < 0 ) { m_RecordingHZ = clip . Clip . frequency ; SendStart ( ) ; } if ( ! DetectSilence || clip . MaxLevel >= m_SilenceThreshold ) { if ( m_ListenActive ) { m_ListenSocket . Send ( new WSConnector . BinaryMessage ( AudioClipUtil . GetL16 ( clip . Clip ) ) ) ; m_AudioSent = true ; } else { m_ListenRecordings . Enqueue ( clip ) ; if ( m_ListenRecordings . Count > MAX_QUEUED_RECORDINGS ) { Log . Error ( " " , " " ) ; StopListening ( ) ; if ( OnError != null ) OnError ( " " ) ; } } } else if ( m_AudioSent ) { SendStop ( ) ; m_AudioSent = false ; } if ( ! m_ListenActive && ( DateTime . Now - m_LastStartSent ) . TotalSeconds > LISTEN_TIMEOUT ) { Log . Error ( " " , " " ) ; StopListening ( ) ; if ( OnError != null ) OnError ( " " ) ; } } }
This function should be invoked with the AudioData input after StartListening() method has been invoked.
This function should be invoked with the AudioData input after StartListening () method has been invoked .
// we have not received the "listening" state yet from the server, so just queue // the audio clips until that happens. // check the length of this queue and do something if it gets too full. // After sending start, we should get into the listening state within the amount of time specified // by LISTEN_TIMEOUT. If not, then stop listening and record the error.
clip
AudioData
A AudioData object containing the AudioClip and max level found in the clip.
A AudioData object containing the AudioClip and max level found in the clip .