Beispiel #1
0
        /// <summary>
        /// This starts the service listening and it will invoke the callback for any recognized text.
        /// OnSynthesize() 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(OnSynthesize callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            if (isListening)
            {
                return(false);
            }
            if (!CreateListenConnector())
            {
                return(false);
            }

            Dictionary <string, string> customHeaders = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> kvp in customRequestHeaders)
            {
                customHeaders.Add(kvp.Key, kvp.Value);
            }

            if (customHeaders != null && listenSocket != null)
            {
                foreach (KeyValuePair <string, string> kvp in customHeaders)
                {
                    listenSocket.Headers.Add(kvp.Key, kvp.Value);
                }
            }

            isListening    = true;
            listenCallback = callback;

            return(true);
        }
Beispiel #2
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();

            listenTexts.Clear();
            listenCallback = null;

            return(true);
        }