Example #1
0
        void OnSocketMessage(object sender, MessageEventArgs e)
        {
            var parser  = new MessageParser(e.Data);
            var message = parser.GetObject();

            // All events are fired from the main thread
            Dispatcher.Enqueue(() => {
                OnGetMessage.TryInvoke(message);
                switch (parser.Path.ToLower())
                {
                case "turn.start":
                    OnTurnStart.TryInvoke(message as TurnStartMessage);
                    break;

                case "turn.end":
                    m_Socket.Send(BingUtils.TurnEndAcknowledgement());
                    m_Buffer = new byte[0];
                    OnTurnEnd.TryInvoke(message as TurnEndMessage);

                    Status = BingStatus.Disconnecting;
                    m_Socket.CloseAsync(() => {
                        Connect();
                    });
                    break;

                case "speech.enddetected":
                    OnSpeechEndDetected.TryInvoke(message as SpeechEndDetectedMessage);
                    break;

                case "speech.phrase":
                    OnSpeechPhrase.TryInvoke(message as SpeechPhraseMessage);
                    break;

                case "speech.hypothesis":
                    OnSpeechHypothesis.TryInvoke(message as SpeechHypothesisMessage);
                    break;

                case "speech.startdetected":
                    OnSpeechStartDetected.TryInvoke(message as SpeechStartDetectedMessage);
                    break;

                case "speech.fragment":
                    OnSpeechFragment.TryInvoke(message as SpeechFragmentMessage);
                    break;
                }
            });
        }