Ejemplo n.º 1
0
        public TextoVozViewModel()
        {
            textoVoz = new TextoVoz()
            {
                Volumen = .75f,
                Pitch   = 1.0f
            };

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

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

                    await TextToSpeech.SpeakAsync(Texto, settings);
                }
                catch (Exception ex)
                {
                }
            });
        }
Ejemplo n.º 2
0
        public static async Task SpeakAsync(string text, Locale locale)
        {
            var settings = new SpeakSettings
            {
                Pitch  = 1.0f,
                Volume = 0.75f,
                Locale = locale
            };

            await TextToSpeech.SpeakAsync(text, settings);
        }
Ejemplo n.º 3
0
        void OnSpeak(bool multiple)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            cts = new CancellationTokenSource();

            SpeakSettings settings = null;

            if (AdvancedSettings)
            {
                settings = new SpeakSettings
                {
                    Volume = Volume,
                    Pitch  = Pitch,
                    Locale = selectedLocale
                };
            }

            Task speaks = null;

            if (multiple)
            {
                speaks = Task.WhenAll(
                    TextToSpeech.SpeakAsync(Text + " 1 ", settings, cancelToken: cts.Token),
                    TextToSpeech.SpeakAsync(Text + " 2 ", settings, cancelToken: cts.Token),
                    TextToSpeech.SpeakAsync(Text + " 3 ", settings, cancelToken: cts.Token));
            }
            else
            {
                speaks = TextToSpeech.SpeakAsync(Text, settings, cts.Token);
            }

            // use ContinueWith so we don't have to catch the cancelled exceptions
            speaks.ContinueWith(t => IsBusy = false);
        }