예제 #1
0
        private void OnLuisUtteranceResultUpdated(object sender, LuisUtteranceResultEventArgs e)
        {
            Application.Current.Dispatcher.Invoke(async() =>
            {
                StringBuilder sb = new StringBuilder(ResultText);

                _requiresResponse = e.RequiresReply;

                sb.AppendFormat("Status: {0}\n", e.Status);
                sb.AppendFormat("Summary: {0}\n\n", e.Message);

                sb.AppendFormat("Action: {0}\n", e.ActionName);
                sb.AppendFormat("Action triggered: {0}\n\n", e.ActionExecuted);

                if (e.ActionExecuted)
                {
                    await TriggerActionExectution(e.ActionName, e.ActionValue);
                }

                if (e.RequiresReply && !string.IsNullOrEmpty(e.DialogResponse))
                {
                    await _ttsClient.SpeakAsync(e.DialogResponse, CancellationToken.None);
                    sb.AppendFormat("Response: {0}\n", e.DialogResponse);
                    sb.Append("Reply in the left textfield");

                    RecordUtterance(sender);
                }

                ResultText = sb.ToString();
            });
        }
        private async void Button_Clicked(object sender, EventArgs e)
        {
            ((Button)sender).IsEnabled = false;
            if (App.opened.Count() < 90)
            {
                lblOldNumber.Text = lblCurrentNumber.Text;
                int nextnumber = generaterandomuniquenumber();
                lblCurrentNumber.Text = nextnumber.ToString();

                SpeechOptions options = new SpeechOptions()
                {
                    Pitch = 0.7f
                };
                string speektext = "Number is" + nextnumber;

                await TextToSpeech.SpeakAsync(speektext, options);

                var   ButtonName = "Lbl" + nextnumber;
                Label lblname    = (Label)FindByName(ButtonName);
                lblname.SetDynamicResource(VisualElement.StyleProperty, "orangeButton");
            }
            else
            {
                await DisplayAlert("Message", "Game Done, All numbers Called", "Ok");

                reset();
            }
            ((Button)sender).IsEnabled = true;
        }
        public async void Upload(byte[] bytes, string fileName)
        {
            ASCIIEncoding      encoding       = new ASCIIEncoding();
            Uri                webService     = new Uri("http://e60a6b3c.ngrok.io/handshake");
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, webService);

            requestMessage.Headers.ExpectContinue = false;
            MultipartFormDataContent multiPartContent = new MultipartFormDataContent("----MyGreatBoundary");
            ByteArrayContent         byteArrayContent = new ByteArrayContent(bytes);

            byteArrayContent.Headers.Add("Content-Type", "multipart/form-data");
            multiPartContent.Add(byteArrayContent, "file", fileName);
            requestMessage.Content = multiPartContent;
            HttpClient httpClient = new HttpClient();
            Task <HttpResponseMessage> httpRequest  = httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, CancellationToken.None);
            HttpResponseMessage        httpResponse = httpRequest.Result;
            string b = await httpResponse.Content.ReadAsStringAsync();

            string location = httpResponse.Headers.Location.ToString();
            await TextToSpeech.SpeakAsync(location);

            //var x = await httpResponse.Content.ReadAsStreamAsync();
            //var hp = new WebClient();
            //var htp = hp.DownloadData("http://eb9826b0.ngrok.io/speech.mp3");
            //File.WriteAllBytes("somefile.mp3", htp);
            //var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
            //player.Load("somefile.mp3");
            //player.Play();
        }
예제 #4
0
 public void SpeakNowDefaultSettings2(string text)
 {
     TextToSpeech.SpeakAsync(text).ContinueWith((t) =>
     {
         // Logic that will run after utterance finishes.
     }, TaskScheduler.FromCurrentSynchronizationContext());
 }
예제 #5
0
        private async void VerifyQuestion()
        {
            FindViewById <Button>(Resource.Id.btnVerify).Visibility = ViewStates.Invisible;
            if (editAnswer.Text == textAnswer.Text)
            {
                textAnswer.SetTextColor(Android.Graphics.Color.Green);
                ++questionsAnswered;
                questions[questionIndex].is_answered = true;
                progressAnswered.Progress            = questionsAnswered;
            }
            else
            {
                ++questions[questionIndex].wrong_inputs;
                ++questions[questionIndex].wrong_answers;
                textAnswer.SetTextColor(Android.Graphics.Color.Red);
            }

            textAnswer.Visibility = ViewStates.Visible;
            var settings = new SpeechOptions()
            {
                Locale = locale
            };
            await TextToSpeech.SpeakAsync(textAnswer.Text, settings);

            FindViewById <Button>(Resource.Id.btnVerify).Visibility = ViewStates.Gone;
            FindViewById <Button>(Resource.Id.btnNext).Visibility   = ViewStates.Visible;
        }
 //METODO PARA CONVERTIR A VOZ CUALQUIER TEXTO
 public static async void ConvertirTextoAVoz(string text)
 {
     await TextToSpeech.SpeakAsync(text, new SpeechOptions
     {
         Volume = 1.0f
     });
 }
예제 #7
0
 private void speak()
 {
     if (!string.IsNullOrEmpty(TextToSpeak))
     {
         TextToSpeech.SpeakAsync(TextToSpeak);
     }
 }
예제 #8
0
        public IObservable <string> Question(PromptConfig config) => Observable.FromAsync <string>(async ct =>
        {
            TextToSpeech.SpeakAsync(config.Message, ct);

            var promptTask = this.dialogs.PromptAsync(config, ct);
            var speechTask = this.speech
                             .ListenUntilPause()
                             .ToTask(ct);

            var finishTask = await Task.WhenAny(promptTask, speechTask);
            if (ct.IsCancellationRequested)
            {
                return(null);
            }

            if (finishTask == promptTask)
            {
                return(promptTask.Result.Text);
            }

            if (finishTask == speechTask)
            {
                return(speechTask.Result);
            }

            return(null);
        });
예제 #9
0
        private void AnimationView_OnFinish(object sender, EventArgs e)
        {
            count++;

            text_Count = count.ToString();
            Device.BeginInvokeOnMainThread(() =>
            {
                txtTimer.FontSize = 100;
                txtTimer.Text     = "" + count;
            });


            if (count <= mCount && count != 1)
            {
                TextToSpeech.SpeakAsync(action2, new SpeechOptions
                {
                    Pitch = 0.0f
                });

                TextToSpeech.SpeakAsync(text_Count, new SpeechOptions
                {
                    Pitch = 0.0f
                });

                //after 'release' delay
                Thread.Sleep(delay2);
            }

            Play_Exercise();
        }
예제 #10
0
        private async Task ExecuteGetWeatherCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            try
            {
                WeatherRoot weatherRoot = null;
                var         units       = Units.Metric;

                //Get weather by city
                weatherRoot = await WeatherService.GetWeather(Location.Trim(), units);

                //Get forecast based on cityId
                Forecast = await WeatherService.GetForecast(weatherRoot.CityId, units);

                var unit = "C";
                Temp      = $"Temp: {weatherRoot?.MainWeather?.Temperature ?? 0}°{unit}";
                Condition = $"{weatherRoot.Name}: {weatherRoot?.Weather?[0]?.Description ?? string.Empty}";

                await TextToSpeech.SpeakAsync(Temp + " " + Condition);
            }
            catch (Exception ex)
            {
                Temp = "Nie można pobrać danych";
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #11
0
        public void leer(string titulo, string mensaje)
        {
            TextToSpeech.SpeakAsync(titulo);


            TextToSpeech.SpeakAsync(mensaje);
        }
예제 #12
0
        public TextToSpeechViewModel()
        {
            tts = new TextToSpeechModel()
            {
                Volume = .75f,
                Pitch  = 1.0f
            };

            SpeakCommand = new Command(async() =>
            {
                try
                {
                    var locales = await TextToSpeech.GetLocalesAsync();
                    var locale  = locales.FirstOrDefault();

                    var settings = new SpeechOptions()
                    {
                        Pitch  = Pitch,
                        Volume = Volume,
                        Locale = locale
                    };

                    await TextToSpeech.SpeakAsync(Text, settings);
                }
                catch (Exception ex)
                {
                }
            });
        }
예제 #13
0
        private async Task ReadTodaysBirthdays()
        {
            var today        = DateTime.Now.Date;
            var allBirthdays = await DataStore.GetItemsAsync();

            var todaysBirthdays = allBirthdays.Where(x => x.Birthday.Month == today.Month && x.Birthday.Day == today.Day).ToList();

            var settings = new SpeechOptions()
            {
                Volume = Volume,
                Pitch  = Pitch
            };

            if (todaysBirthdays.Count > 0)
            {
                foreach (var b in todaysBirthdays)
                {
                    await TextToSpeech.SpeakAsync($"Happy Birthday {b.Name}", settings);

                    await Task.Delay(500);
                }
            }
            else
            {
                await TextToSpeech.SpeakAsync($"No Birthdays Today", settings);
            }
        }
        private async void SpeechButton_Clicked(object sender, System.EventArgs e)
        {
            if (!IsSpeech)
            {
                SpeechButton.Text = "\uf04d";
                cts      = new CancellationTokenSource();
                IsSpeech = true;
                await TextToSpeech.SpeakAsync(Property.Description, options, cts.Token);

                if (IsSpeech)
                {
                    IsSpeech          = false;
                    SpeechButton.Text = "\uf04b";
                }
                ;
            }
            else
            {
                if (cts.IsCancellationRequested == false)
                {
                    cts.Cancel();
                }
                IsSpeech          = false;
                SpeechButton.Text = "\uf04b";
            }
        }
 public Func <Task> EngageVoice()
 {
     return(async() =>
     {
         await TextToSpeech.SpeakAsync("Please say Apple into the microphone while holding record.");
     });
 }
예제 #16
0
 private async void Button_Clicked(object sender, EventArgs e)
 {
     await TextToSpeech.SpeakAsync(EntryText.Text, new SpeechOptions
     {
         Volume = (float)slidervolume.Value
     });;
 }
예제 #17
0
        public IObservable <bool> Confirm(ConfirmConfig config) => Observable.FromAsync(async ct =>
        {
            TextToSpeech.SpeakAsync(config.Message, ct);
            var confirmTask = this.dialogs.ConfirmAsync(config, ct);
            var speechTask  = this.speech
                              .ListenForFirstKeyword(config.OkText, config.CancelText)
                              .ToTask(ct);

            var finishTask = await Task.WhenAny(confirmTask, speechTask);
            if (ct.IsCancellationRequested)
            {
                return(false);
            }

            if (finishTask == confirmTask)
            {
                return(confirmTask.Result);
            }

            if (finishTask == speechTask)
            {
                return(speechTask.Result.Equals(config.OkText, StringComparison.OrdinalIgnoreCase));
            }

            return(false);
        });
예제 #18
0
        public void PlayAndCount()
        {
            count++;

            text_Count = count.ToString();
            Device.BeginInvokeOnMainThread(() =>
            {
                txtTimer.FontSize = 100;
                txtTimer.Text     = "" + count;

                if (vibrationOnBool == true)
                {
                    Vibration.Vibrate();
                }
            });


            if (count == 1)
            {
                TextToSpeech.SpeakAsync(text_Count, new SpeechOptions
                {
                    Pitch = 0.0f
                });

                TextToSpeech.SpeakAsync(action1, new SpeechOptions
                {
                    Pitch = 0.0f
                });

                Thread.Sleep(delay2);
            }

            animationView.PlayAnimation();
        }
예제 #19
0
        public string RecommendedOut(int TotalOut)

        //This gets the out from the classes and vocalizes the words
        {
            string strOut    = "";
            int    dartCount = 0;

            OutCalculator clsOutCalc = new OutCalculator(InOutRule.Double);
            List <Dart>   recOut     = clsOutCalc.GetDartsForOut(TotalOut);

            StringBuilder sb = new StringBuilder();

            foreach (Dart mDart in recOut)
            {
                sb.Append(recOut[dartCount].ToString());
                dartCount++;
            }

            string strOutText = sb.ToString();

            //If it's not time to stop
            if (App.numberOfTimes != 0)
            {
                TextToSpeech.SpeakAsync(strOutText);
                App.numberOfTimes--;
            }
            else
            {
                Debug.Print("Heya");
            }

            return(strOut);
        }
예제 #20
0
        public async void SetDisplay(double level, bool charging)
        {
            Color?color  = null;
            var   status = charging ? "Charging" : "DisCharging";

            //var full = BatteryState.Full.ToString();
            if (level > .8f)
            {
                color  = Color.FromHex("#2196F3").MultiplyAlpha(level);
                status = "Full";
                var settings = new SpeechOptions()
                {
                    Volume = .7f,
                    Pitch  = 1
                };
                await TextToSpeech.SpeakAsync("Battery is full", settings);
            }
            else if (level > .3f)
            {
                color = Color.Fuchsia.MultiplyAlpha(1d - level);
            }
            else
            {
                color = Color.Red.MultiplyAlpha(1d - level);
            }
            Label6.TextColor = color.Value;
            Label6.Text      = status;
        }
예제 #21
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();
            await TextToSpeech.SpeakAsync(Route.Text);

            await TextToSpeech.SpeakAsync(Instellingen.Text);
        }
        // delegate for game completed callback
        private async void OnGameCompletedCallbackAsync()
        {
            ViewModel.GameCompleted = true;
            // Game over if less than or equal to zero points
            if (ViewModel.GameScore <= 0)
            {
                ViewModel.SecondsRemaining = 0;
                if (SoundSettingIsOn)
                {
                    await TextToSpeech.SpeakAsync("Sorry but you did not score any points. Please try again.");
                }
                return;
            }

            // get ranking
            bool bOK  = Score.GetScoreRank(ViewModel.GameScore, out int ranking);
            var  rank = new { Score = ViewModel.GameScore, Rank = ranking };

            ViewModel.SignalTilesHtmlPage("OnGameCompleted", rank);
            ViewModel.SignalHeaderHtmlPage("OnGameCompleted", rank);
            // speak completed word
            //if (SoundSettingIsOn)
            //{
            //    switch (Manager.DifficultyLevel)
            //    {
            //        case Defines.GameDifficulty.easy:
            //        case Defines.GameDifficulty.medium:
            //            await TextToSpeech.SpeakAsync("Excellent job. You are a winner!");
            //            break;
            //        case Defines.GameDifficulty.hard:
            //            await TextToSpeech.SpeakAsync("Wow. You are a legand!");
            //            break;
            //    }
            //}
        }
예제 #23
0
 /// <summary>
 /// text to speech
 /// </summary>
 public void SpeakAsync(string text, SpeechOptions settings = null)
 {
     Task.Run(async() =>
     {
         await TextToSpeech.SpeakAsync(text, settings);
     });
 }
예제 #24
0
 private void SpeakButton_Touch(object sender, View.TouchEventArgs e)
 {
     if (e.Event.Action == MotionEventActions.Down)
     {
         TextToSpeech.SpeakAsync(currentWord);
     }
 }
        public async Task SpeakNow()
        {
            cts = new CancellationTokenSource();
            var locales = await TextToSpeech.GetLocalesAsync();

            if (locales != null)
            {
                // Grab the first locale
                var locale = locales.Where(x => x.Language == "en").FirstOrDefault();

                var settings = new SpeechOptions()
                {
                    Volume = (float)0.85,
                    Pitch  = (float)1.0,
                    Locale = locale
                };
                if (!string.IsNullOrEmpty(NotesDescription) && !string.IsNullOrWhiteSpace(NotesDescription))
                {
                    await TextToSpeech.SpeakAsync(NotesDescription, settings, cancelToken : cts.Token);
                }
                else
                {
                    DependencyService.Get <IToast>().Show("Text is Empty");
                }
            }
        }
예제 #26
0
        private void BtnStartTurn_Click(object sender, System.EventArgs e)
        {
            singleUse = false;
            string strRecommendedOut = "";

            HideKeyboard();

            var txtDartScore = FindViewById <Android.Widget.EditText>(Resource.Id.DartScore);

            txtDartScore.Text = "";

            var txtStartScore = FindViewById <Android.Widget.EditText>(Resource.Id.StartScore);

            if (txtStartScore.Text.Trim() != "")
            {
                bool Result = false;
                Result = int.TryParse(txtStartScore.Text, out startingScore);

                if (true != Result)
                {
                    startingScore     = -1;
                    strRecommendedOut = "Unknown Score";
                }
                else
                {
                    strRecommendedOut = RecommendedOut(startingScore);
                }

                bool mbOK = clsTurn.SetStartingScore(startingScore);

                var txtNewOut = FindViewById <Android.Widget.TextView>(Resource.Id.txtNewScore);
                txtNewOut.Text = txtStartScore.Text + " Left, Darts Remaining: 3";

                var txtOutTurn = FindViewById <Android.Widget.TextView>(Resource.Id.txtOutTurn);
                txtOutTurn.Text = "(" + txtStartScore.Text + ") " + strRecommendedOut;

                currentScore = startingScore;
                clsUIState.CurrentScoreText = txtNewOut.Text;
                clsUIState.DoubleOutText    = txtOutTurn.Text;

                TextToSpeech.SpeakAsync(txtStartScore.Text + " Starting Score");
            }
            else
            {
                Recognizer.StopListening();

                isListeningPaused = false;

                Recognizer.StartListening(SpeechIntent);

                mStreamVolume = mAudioManager.GetStreamVolume(Stream.Music);                 // getting system volume into var for later un-muting

                if (mStreamVolume == 0)
                {
                    mStreamVolume = 9;
                }

                StartTimer();
            }
        }
        private async Task MakePredictionAsync(Stream stream) //Calls Custom Vision
        {
            var imageBytes = GetImageAsByteData(stream);
            var url        = "https://southcentralus.api.cognitive.microsoft.com/customvision/v2.0/Prediction/8dde27e7-f188-4528-8874-087881f4a1c6/image";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Prediction-Key", "<>");

                using (var content = new ByteArrayContent(imageBytes))
                {
                    content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
                    var response = await client.PostAsync(url, content);

                    var responseString = await response.Content.ReadAsStringAsync();

                    var predictions = JsonConvert.DeserializeObject <Response>(responseString);
                    var resp        = predictions.Predictions[0];
                    if (resp.TagId == "2ba3cbf9-a02b-47c1-9f32-a487d6c7cdce")
                    {
                        TextToSpeech.SpeakAsync("Police is on the Way");
                    }
                }
            }
        }
        private async void PlayTTSCommandExecute()
        {
            try
            {
                var locales = await TextToSpeech.GetLocalesAsync();

                // Grab the first locale
                var locale = locales.Where(x => x.Country == "FR").FirstOrDefault();
                if (locale == null)
                {
                    locale = locales.FirstOrDefault();
                }

                var settings = new SpeechOptions()
                {
                    Volume = 1.0f,
                    Pitch  = 1.2f,
                    Locale = locale
                };
                await TextToSpeech.SpeakAsync(CurrentSample.Title, settings);

                Dictionary <string, string> dict = new Dictionary <string, string>();
                dict.Add("File", CurrentSample.File);
                Analytics.TrackEvent("TTSSpokenMP3", dict);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
예제 #29
0
        private async void Submit_Clicked(object sender, EventArgs e)
        {
            await Navigation.PushAsync(new MainPage());


            await TextToSpeech.SpeakAsync("Your order has been submitted");
        }
예제 #30
0
        private async void OnReadDescription(object obj)
        {
            if (SelectedRecipeDescription != string.Empty)
            {
                try
                {
                    var locales = await TextToSpeech.GetLocalesAsync();

                    Locale locale = (Locale)locales.ElementAt(50);
                    if (SelectedRecipeDescription != string.Empty)
                    {
                        await TextToSpeech.SpeakAsync(SelectedRecipeDescription, new SpeechOptions()
                        {
                            Locale = locale
                        });
                    }
                }
                catch (Exception)
                {
                    isMessageVisible = true;
                    CannotReadText   = MessageNames.CannotReadDescription;
                }
            }
            else
            {
                await _dialogService.ShowDialog(MessageNames.RecipeHasNoDescription, "Failure", "Ok");
            }
        }