예제 #1
0
            internal AVSpeechSynthesisVoice GetVoiceForLocaleLanguage()
            {
                var language = Language.GetInstalledLanguages().FirstOrDefault(x => x.Id.StartsWith(Language?.Id.ToLower()))?.Id ?? AVSpeechSynthesisVoice.CurrentLanguageCode;

                var voice = AVSpeechSynthesisVoice.FromLanguage(language);

                if (voice != null)
                {
                    return(voice);
                }

                Log.For(this).Error("Voice not found for language: " + language + ". Using default instead.");
                return(AVSpeechSynthesisVoice.FromLanguage(AVSpeechSynthesisVoice.CurrentLanguageCode));
            }
예제 #2
0
        /// <summary>
        /// Speak the specified msg.
        /// </summary>
        /// <param name="msg">Message.</param>
        public void Speak(string msg)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();

            var speechUtterance = new AVSpeechUtterance(msg)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("fr-FR"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #3
0
        /// <summary>
        /// Speak example from:
        /// http://blog.xamarin.com/make-your-ios-7-app-speak/
        /// </summary>
        public static void Speak(string text)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = volume,
                PitchMultiplier = pitch
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #4
0
        public void Speak(string text)
        {
            var synthesizer = new AVSpeechSynthesizer();

            var utterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.DefaultSpeechRate,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            synthesizer.SpeakUtterance(utterance);
        }
        public void ReadText(string text)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();
            //Voice = AVSpeechSynthesisVoice.FromLanguage("fr-FR")
            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #6
0
        public void TextToTalk(string text)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("pt-BR"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
        public async Task SpeakAsync(string text)
        {
            tcsUtterance = new TaskCompletionSource <bool>();

            synthesizer.DidFinishSpeechUtterance += OnFinishedSpeechUtterance;
            utterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 3,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 1.0f,
                PitchMultiplier = 1.0f,
            };
            synthesizer.SpeakUtterance(utterance);
            await tcsUtterance.Task;
        }
예제 #8
0
        public void Speak(string text, bool queue = false, CrossLocale?crossLocale = default(CrossLocale?), float?pitch = default(float?), float?speakRate = default(float?), float?volume = default(float?))
        {
            _isSpeaking = true;
            var speechRate = UIDevice.CurrentDevice.CheckSystemVersion(8, 0) ? 8 : 4;

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / speechRate,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            _speechSynthesizer.SpeakUtterance(speechUtterance);
        }
        partial void btnSpeak_TouchUpInside(UIButton sender)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();
            var button            = (UIButton)sender;

            var speechUtterance = new AVSpeechUtterance(button.TitleLabel.Text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #10
0
        public void Speak(string text)
        {
            _isSpeaking = true;
            //var speechRate = UIDevice.CurrentDevice.CheckSystemVersion(8, 0) ? 8 : 4;
            var speechUtterance = new AVSpeechUtterance(text)
            {
                //Rate = AVSpeechUtterance.MaximumSpeechRate / speechRate,
                Rate            = AVSpeechUtterance.DefaultSpeechRate,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            _speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #11
0
        public void Speak(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var speechSynthesizer = new AVSpeechSynthesizer();
                var speechUtterance   = new AVSpeechUtterance(text)
                {
                    Rate            = AVSpeechUtterance.MaximumSpeechRate / 3,
                    Voice           = AVSpeechSynthesisVoice.FromLanguage("de-DE"),
                    Volume          = volume,
                    PitchMultiplier = pitch
                };

                speechSynthesizer.SpeakUtterance(speechUtterance);
            }
        }
예제 #12
0
        void Speak(string text)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();

//                        var voices = AVSpeechSynthesisVoice.GetSpeechVoices ();

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("tr-TR"),
                Volume          = volume,
                PitchMultiplier = pitch
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #13
0
        public void Speak(string text)
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                var speechSynthesizer = new AVSpeechSynthesizer();
                var speechUtterance   = new AVSpeechUtterance(text)
                {
                    Rate            = AVSpeechUtterance.MaximumSpeechRate / 3,
                    Voice           = AVSpeechSynthesisVoice.FromLanguage(CultureInfo.CurrentCulture.Name),
                    Volume          = 0.5f,
                    PitchMultiplier = 1.0f
                };

                speechSynthesizer.SpeakUtterance(speechUtterance);
            }
        }
        public void Speak(string text_to_speak)
        {
            AVSpeechSynthesizer speechSynthesizer = new AVSpeechSynthesizer();

            AVSpeechUtterance speechUtterance = new AVSpeechUtterance(text_to_speak)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);

            return;
        }
        /// <summary>
        /// The speak.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="language">The language.</param>
        public void Speak(string text, string language = DEFAULT_LOCALE)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();

            var voice = AVSpeechSynthesisVoice.FromLanguage(language) ?? AVSpeechSynthesisVoice.FromLanguage(DEFAULT_LOCALE);

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage(language),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #16
0
        public void frenchPhraseBookAI(string textToSpeak)
        {
            Console.WriteLine("Hello");

            AVSpeechSynthesizer frenchSpeech = new AVSpeechSynthesizer();

            AVSpeechUtterance frenchVoice = new AVSpeechUtterance(textToSpeak)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 2.2f,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("fr"),
                Volume          = 1.0f,
                PitchMultiplier = 1.0f
            };

            frenchSpeech.SpeakUtterance(frenchVoice);
        }
예제 #17
0
        public Task Speak(string text)
        {
            return(new Task(() =>
            {
                var speechSynthesizer = new AVSpeechSynthesizer();

                var speechUtterance = new AVSpeechUtterance(text)
                {
                    Rate = AVSpeechUtterance.MaximumSpeechRate / 2.5f,
                    Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                    Volume = 0.5f,
                    PitchMultiplier = 1.0f
                };

                speechSynthesizer.SpeakUtterance(speechUtterance);
            }));
        }
예제 #18
0
        private AVSpeechSynthesisVoice GetVoiceForLocaleLanguage(CrossLocale?crossLocale)
        {
            var localCode = crossLocale.HasValue &&
                            !string.IsNullOrWhiteSpace(crossLocale.Value.Language) ?
                            crossLocale.Value.Language :
                            AVSpeechSynthesisVoice.CurrentLanguageCode;

            var voice = AVSpeechSynthesisVoice.FromLanguage(localCode);

            if (voice == null)
            {
                Console.WriteLine("Locale not found for voice: " + localCode + " is not valid. Using default.");
                voice = AVSpeechSynthesisVoice.FromLanguage(AVSpeechSynthesisVoice.CurrentLanguageCode);
            }

            return(voice);
        }
예제 #19
0
        public void SetLanguage(string sLanguage)
        {
            switch (sLanguage)
            {
            case "Japanese":
                this.language = AVSpeechSynthesisVoice.FromLanguage("ja-JP");
                break;

            case "Korean":
                this.language = AVSpeechSynthesisVoice.FromLanguage("ko-KR");
                break;

            default:
                this.language = AVSpeechSynthesisVoice.FromLanguage("en-US");
                break;
            }
        }
        public void Speak(string text)
        {
            if (String.IsNullOrEmpty(text))
            {
                return;
            }
            var speechSynthesizer = new AVSpeechSynthesizer();

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.MaximumSpeechRate / 4,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #21
0
        /// <summary>
        /// Pronounces the provided text
        /// </summary>
        public bool Pronounce(string textToPronounce, string voiceName, double?rateMult, double?pitchMult)
        {
            try
            {
                var speechUtterance = new AVSpeechUtterance(textToPronounce);

                // pick the voice
                Voice voice = null;
                if (string.IsNullOrEmpty(voiceName) == false)
                {
                    voice = GetVoices().Where(i => i.FullName == voiceName).FirstOrDefault();
                }
                if (voice != null)
                {
                    var voices   = AVSpeechSynthesisVoice.GetSpeechVoices().ToList();
                    var voiceObj = voices.Where(i => i.Language == voice.Language).FirstOrDefault();
                    speechUtterance.Voice = voiceObj;
                }

                // rate
                double rate = rateMult != null ? rateMult.Value : UserPreferences.DefaultVoiceRate;
                if (Config.IsIOS && Config.OSVersionMajor < 9)
                {
                    rate *= 0.3;
                }

                // configure
                speechUtterance.Volume          = 1.0f;
                speechUtterance.Rate            = (float)rate;
                speechUtterance.PitchMultiplier = (float)(pitchMult != null ? pitchMult.Value : UserPreferences.DefaultVoicePitch);

                // pronounce
                var speechSynthesizer = new AVSpeechSynthesizer();
                speechSynthesizer.SpeakUtterance(speechUtterance);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #22
0
        public void Speak(string text)
        {
            NSError error        = new NSError();
            var     audioSession = AVAudioSession.SharedInstance();

            audioSession.OverrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, out error);

            var speechSynthesizer = new AVSpeechSynthesizer();

            var rate            = AVSpeechUtterance.MaximumSpeechRate / 4;
            var voice           = AVSpeechSynthesisVoice.FromLanguage("en-US");
            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = rate,
                Voice           = voice,
                Volume          = 0.5f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #23
0
        AVSpeechSynthesisVoice SelectVoice()
        {
            AVSpeechSynthesisVoice[] voices = AVSpeechSynthesisVoice.GetSpeechVoices();
            AVSpeechSynthesisVoice   voice  = null;

            foreach (AVSpeechSynthesisVoice cVoice in voices)
            {
                if (cVoice.Language == "en-US")
                {
                    if (string.Compare(cVoice.Name, "Samantha (Enhanced)", StringComparison.Ordinal) == 0)
                    {
                        voice = cVoice;
                    }
                }
            }
            if (voice == null)
            {
                voice = AVSpeechSynthesisVoice.FromLanguage("en-US");
            }
            return(voice);
        }
        void Speak(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            Console.WriteLine("Speak: " + text);

            AVAudioSession.SharedInstance().SetActive(true);

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.DefaultSpeechRate,
                Voice           = AVSpeechSynthesisVoice.FromLanguage("en-US"),
                Volume          = 1.0f,
                PitchMultiplier = 1.0f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
        }
예제 #25
0
        public static void Speak(string text, bool force = false)
        {
            if (!force && !Sound)
            {
                return;
            }
            if (g_synthesizer.Speaking)
            {
                g_synthesizer.StopSpeaking(AVSpeechBoundary.Immediate);
            }

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = SpeechRate * AVSpeechUtterance.MaximumSpeechRate,
                Voice           = AVSpeechSynthesisVoice.FromLanguage(Voice),
                Volume          = Volume,
                PitchMultiplier = PitchMultiplier
            };

            g_synthesizer.SpeakUtterance(speechUtterance);
        }
예제 #26
0
        public void PlayAudio(string text)
        {
            if (_speechSynthesizer == null)
            {
                _speechSynthesizer = new AVSpeechSynthesizer();
                _voice             = AVSpeechSynthesisVoice.FromIdentifier("com.apple.ttsbundle.siri_female_de-DE_compact");
                if (_voice == null)
                {
                    _voice = AVSpeechSynthesisVoice.FromLanguage("de-DE");
                }
            }
            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.DefaultSpeechRate,
                Voice           = _voice,
                Volume          = 1.0f,
                PitchMultiplier = 1.0f
            };

            _speechSynthesizer.SpeakUtterance(speechUtterance);
        }
        async void Felicidad(object sender, EventArgs e)
        {
            var ruta = await DescargarImagenAnalizarFelicidad();

            imagen.Image = UIImage.FromFile(ruta);
            var StreamdeImagen = imagen.Image.AsJPEG(.5f).AsStream();
            {
                try
                {
                    float porcentaje = await NiveldeFelicidad(StreamdeImagen);

                    lblDescripccion.Text = TraerMensajeEmocion(porcentaje);
                    var voz = new AVSpeechUtterance(lblDescripccion.Text);
                    voz.Voice = AVSpeechSynthesisVoice.FromLanguage("es-MX");
                    habla.SpeakUtterance(voz);
                }
                catch (Exception ex)
                {
                    lblDescripccion.Text = ex.Message;
                }
            }
        }
예제 #28
0
        public override void Speak(string text, bool gender, int pitch)
        {
            var speechSynthesizer = new AVSpeechSynthesizer();
            var voci = AVSpeechSynthesisVoice.GetSpeechVoices();

            var choices = voci.Where(x => x.Description.Contains(gender ? "female" : "male"));
            //prefer us
            AVSpeechSynthesisVoice voice;

            voice = choices.FirstOrDefault(x => x.Language.ToLowerInvariant().Contains("en-gb"));
            if (voice == null)
            {
                voice = choices.FirstOrDefault(x => x.Language.ToLowerInvariant().Contains("en-gb"));
            }
            if (voice == null && voci.Length > 0)
            {
                voice = voci[0];
            }
            if (voice == null)
            {
                return;
            }

            var speechUtterance = new AVSpeechUtterance(text)
            {
                Rate            = AVSpeechUtterance.DefaultSpeechRate,
                Voice           = voice,
                Volume          = 0.5f,
                PitchMultiplier = pitch / 100f
            };

            speechSynthesizer.SpeakUtterance(speechUtterance);
            speechSynthesizer.DidFinishSpeechUtterance += (sender, e) =>
            {
                speechSynthesizer.Dispose();
            };
        }
예제 #29
0
        /// <summary>
        /// Returns a list of available voices
        /// </summary>
        public List <Voice> GetVoices()
        {
            try
            {
                var voiceObjs = AVSpeechSynthesisVoice.GetSpeechVoices();

                List <Voice> voices = new List <Voice>();
                foreach (var voiceObj in voiceObjs)
                {
                    voices.Add(new Voice()
                    {
                        Language = voiceObj.Language,
                        Name     = "Default iOS"
                    });
                }
                voices = voices.OrderBy(i => i.Language).ToList();

                return(voices);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #30
0
        public void Speak(string s)
        {
            // ------------------------------------------------------
            var utter = new AVSpeechUtterance(s);

            //utter.Rate = AVSpeechUtterance.MaximumSpeechRate / 2;
            utter.Rate = AVSpeechUtterance.DefaultSpeechRate;

            // Aaron's Id = 'siri_male_en-US_compact'...
            AVSpeechSynthesisVoice v = GetVoiceByName("Aaron");

            if (v != null)
            {
                utter.Voice = v;
            }
            else
            {
                utter.Voice = AVSpeechSynthesisVoice.FromLanguage("en-US");
            }
            Debug.Print("Voice used=" + utter.Voice?.Name ?? "None");

            utter.PitchMultiplier = 0.65F;
            speech.SpeakUtterance(utter);
        }