Ejemplo n.º 1
0
        //
        private void Connection_DataReceived(object sender, Samsung.Sap.DataReceivedEventArgs e)
        {
            ShowMessage("Something received from phone");
            string s = Encoding.UTF8.GetString(e.Data);

            ReceivedMessage = s;
            Tizen.Log.Debug(TAG, s);
        }
Ejemplo n.º 2
0
        private static void Connection_DataReceived(object sender, Samsung.Sap.DataReceivedEventArgs e)
        {
            string json = Encoding.UTF8.GetString(e.Data);

            if (json.Contains(Constraints.StopDetailsRsp))
            {
                var response = JsonConvert.DeserializeObject <StopDetailsResponse>(json);
                var page     = new StopDetailsPage(response.Stop);
                (App.Current.MainPage as NavigationPage).PushAsync(page);
            }
            else if (json.Contains(Constraints.StopsListRsp))
            {
                var response = JsonConvert.DeserializeObject <StopsListResponse>(json);

                stopListPage = new StopsListPage(response.Stops);
                (App.Current.MainPage as NavigationPage).PushAsync(stopListPage);
            }
        }
Ejemplo n.º 3
0
        private void Connection_DataReceived(object sender, Samsung.Sap.DataReceivedEventArgs e)
        {
            AssistResponse ar = AssistResponse.Parser.ParseFrom(e.Data);

            if (ar.SpeechResults != null)
            {
                if (ar.SpeechResults.Any() && ar.SpeechResults.First().Stability > 0.01)
                {
                    label.Text = ar.SpeechResults.First().Transcript;

                    if (ar.SpeechResults.First().Stability == 1)
                    {
                        audioRecorder.StopRecording();
                        updateLabel(ar.SpeechResults.First().Transcript);

                        if (File.Exists(filePath))
                        {
                            File.Delete(filePath);
                        }
                        fs = File.Create(filePath);
                    }
                }
            }

            if (ar.DialogStateOut != null && ar.DialogStateOut.SupplementalDisplayText != "")
            {
                updateLabel(ar.DialogStateOut.SupplementalDisplayText);
            }

            if (ar.DialogStateOut != null && ar.DialogStateOut.VolumePercentage != 0)
            {
                int newVolumeLevel = Convert.ToInt32(15 * ar.DialogStateOut.VolumePercentage / 100);
                AudioManager.VolumeController.Level[AudioVolumeType.Media] = newVolumeLevel;
                actionButton.IsEnable = true;
            }

            if (ar.ScreenOut != null)
            {
                updateLabel(ar.ScreenOut.Data.ToStringUtf8());
            }

            if (ar.AudioOut != null && ar.AudioOut.AudioData.Length != 0)
            {
                try
                {
                    fs.Write(ar.AudioOut.AudioData.ToByteArray(), 0, ar.AudioOut.AudioData.Length);
                    if (fs.Length != 0)
                    {
                        fs.Flush();
                    }

                    if (!isPlaying && fs.Length >= 1600)
                    {
                        isPlaying = true;
                        audioPlayer.Play(fs.Name);
                        actionButton.IsEnable        = true;
                        actionButton.BackgroundColor = Color.Red;
                        actionButton.Text            = "Stop";
                    }
                }
                catch (System.ObjectDisposedException)
                {
                    Tizen.Log.Debug("AUDIO RESPONSE", "Tried to write to closed FileStream, Knownbug");
                    return;
                }
            }
        }