示例#1
0
        /// <summary>
        /// Invoke this function stop this service from listening.
        /// </summary>
        /// <returns>Returns true on success, false on failure.</returns>
        public bool StopListening()
        {
            if (!_isListening)
            {
                return(false);
            }

            _isListening = false;
            CloseListenConnector();

            if (_keepAliveRoutine != 0)
            {
                Runnable.Stop(_keepAliveRoutine);
                _keepAliveRoutine = 0;
            }

            _listenRecordings.Clear();
            _prefixClips.Clear();
            _listenCallback = null;
            _recordingHZ    = -1;

            Debug.Log("Stop Listening");
            CurrentStatus = LexiconSpeechStatus.Stopped;

            return(true);
        }
示例#2
0
        /// <summary>
        /// This starts the service listening and it will invoke the callback for any recognized speech.
        /// OnListen() must be called by the user to queue audio data to send to the service.
        /// StopListening() should be called when you want to stop listening.
        /// </summary>
        /// <param name="callback">All recognize results are passed to this callback.</param>
        /// <param name="speakerLabelCallback">Speaker label goes through this callback if it arrives separately from recognize result.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        public bool StartListening(OnRecognize callback, OnRecognizeSpeaker speakerLabelCallback = null)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (_isListening)
            {
                return(false);
            }
            if (!CreateListenConnector())
            {
                return(false);
            }

            _isListening    = true;
            _listenCallback = callback;
            if (speakerLabelCallback != null)
            {
                _speakerLabelCallback = speakerLabelCallback;
            }
            //_keepAliveRoutine = Runnable.Run(KeepAlive());
            _lastKeepAlive          = DateTime.Now;
            _sendStopAfterListening = false;

            return(true);
        }
示例#3
0
        /// <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>
        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));
        }
示例#4
0
        /// <summary>
        /// This starts the service listening and it will invoke the callback for any recognized speech.
        /// OnListen() must be called by the user to queue audio data to send to the service.
        /// StopListening() should be called when you want to stop listening.
        /// </summary>
        /// <param name="callback">All recognize results are passed to this callback.</param>
        /// <returns>Returns true on success, false on failure.</returns>
        public bool StartListening(OnRecognize callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (m_IsListening)
            {
                return(false);
            }
            if (!CreateListenConnector())
            {
                return(false);
            }

            m_IsListening      = true;
            m_ListenCallback   = callback;
            m_KeepAliveRoutine = Runnable.Run(KeepAlive());
            m_LastKeepAlive    = DateTime.Now;

            return(true);
        }
示例#5
0
        /// <summary>
        /// Invoke this function stop this service from listening.
        /// </summary>
        /// <returns>Returns true on success, false on failure.</returns>
        public bool StopListening()
        {
            if (!m_IsListening)
            {
                return(false);
            }

            m_IsListening = false;
            CloseListenConnector();

            if (m_KeepAliveRoutine != 0)
            {
                Runnable.Stop(m_KeepAliveRoutine);
                m_KeepAliveRoutine = 0;
            }

            m_ListenRecordings.Clear();
            m_ListenCallback = null;
            m_RecordingHZ    = -1;

            return(true);
        }