Beispiel #1
0
        private void OnMessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
        {
            try
            {
                if (args.MessageType == SocketMessageType.Utf8)
                {
                    string jsonOutput;
                    using (var dataReader = args.GetDataReader())
                    {
                        dataReader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                        jsonOutput = dataReader.ReadString(dataReader.UnconsumedBufferLength);
                    }

                    var result = JsonConvert.DeserializeObject <SpeechTranslationResult>(jsonOutput);
                    this.onSpeechTranslateResult(result);
                }
                else if (args.MessageType == SocketMessageType.Binary)
                {
                    using (var dataReader = args.GetDataReader())
                    {
                        dataReader.ByteOrder = ByteOrder.LittleEndian;
                        this.onTextToSpeechData(AudioFrameHelper.GetAudioFrame(dataReader));
                    }
                }
            }
            catch (Exception e)
            {
                this.onSpeechTranslateResult(new SpeechTranslationResult()
                {
                    Status = e.Message
                });
            }
        }
Beispiel #2
0
 public void SendAudioFrame(AudioFrame frame)
 {
     AudioFrameHelper.SendAudioFrame(frame, this.dataWriter);
 }