/// <summary> /// 实现 ITTS 接口方法 /// 播放语音 /// </summary> /// <param name="content"></param> public void Play(string content) { if (Check_InitTextToSpeech() == false) { return; } Task myTask = new Task(() => { AVSpeechUtterance speechUtterance = new AVSpeechUtterance(content) { Rate = AVSpeechUtterance.MaximumSpeechRate / 3, Voice = AVSpeechSynthesisVoice.FromLanguage("zh-CN"), Volume = mVolume, PitchMultiplier = mPitch, }; speechUtterance.Rate = mRate; mSpeechSynthesizer.SpeakUtterance(speechUtterance); }); myTask.ContinueWith((task) => { if (task.IsFaulted == true) { string msg = string.Empty; if (task.Exception != null) { msg = "TTS Play 异常 : \r\n{0}".FormatWith(task.Exception.GetFullInfo()); } else { msg = "TTS Play 异常 : ".FormatWith(); } System.Diagnostics.Debug.WriteLine(msg); // TODO iOS MyTTS 弹窗提示 //System.Threading.Tasks.Task.Run(() => //{ // Looper.Prepare(); // Toast.MakeText(((Activity)Xamarin.Forms.Forms.Context), msg, ToastLength.Long).Show(); // Looper.Loop(); //}); } }); myTask.Start(); }
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); }
public override void ViewDidLoad() { base.ViewDidLoad(); #region Using Siri's Voice //First we're gonna create the AvFundation in which we use it for reading the speech using the Siri's voice AVSpeechSynthesizer Siri = new AVSpeechSynthesizer(); #endregion ButtonDesc.TouchUpInside += Happiness; #region Hapiness Method Async //This is used for getting the Image which we're gonna use async void Happiness(object sender, EventArgs e) { var Path = await DownloadImageHappiness(); ImgDetection.Image = UIImage.FromFile(Path); var StreamImage = ImgDetection.Image.AsJPEG(.5f).AsStream(); { try { float Percent = await HappinessLevel(StreamImage); TextDescription.Text = GettingMessage(Percent); var Voice = new AVSpeechUtterance(TextDescription.Text); Voice.Voice = AVSpeechSynthesisVoice.FromLanguage("es-MX"); Siri.SpeakUtterance(Voice); } catch (Exception ex) { TextDescription.Text = ex.Message; } } } #endregion }
public void Speak(string text, string voiceTypeIdentifier, FinishEvent audioFinishHandler = null) { if (string.IsNullOrEmpty(text)) { throw new ArgumentNullException("text"); } if (IsPlaying) { return; } this.audioFinishHandler = audioFinishHandler; IsPlaying = true; AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord, AVAudioSessionCategoryOptions.AllowBluetooth | AVAudioSessionCategoryOptions.AllowBluetoothA2DP); AVAudioSession.SharedInstance().OverrideOutputAudioPort(AVAudioSessionPortOverride.Speaker, out NSError error); AVSpeechUtterance speechUtterance = new AVSpeechUtterance(text); if (!string.IsNullOrEmpty(voiceTypeIdentifier)) { speechUtterance.Voice = AVSpeechSynthesisVoice.FromIdentifier(voiceTypeIdentifier); } speechSynthesizer.SpeakUtterance(speechUtterance); }
async Task SpeakUtterance(AVSpeechUtterance speechUtterance, CancellationToken cancelToken) { AVSpeechSynthesizer speechSynthesizer = new AVSpeechSynthesizer(); try { currentSpeak = new TaskCompletionSource <object>(); speechSynthesizer.DidFinishSpeechUtterance += OnFinishedSpeechUtterance; speechSynthesizer.SpeakUtterance(speechUtterance); using (cancelToken.Register(TryCancel)) { await currentSpeak.Task; } } finally { speechSynthesizer.DidFinishSpeechUtterance -= OnFinishedSpeechUtterance; speechSynthesizer.Dispose(); } void OnFinishedSpeechUtterance(object sender, AVSpeechSynthesizerUteranceEventArgs args) => currentSpeak?.TrySetResult(null); void TryCancel() { speechSynthesizer?.StopSpeaking(AVSpeechBoundary.Word); currentSpeak?.TrySetCanceled(); } }
public static Task Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); var tcs = new TaskCompletionSource <bool> (); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, //Voice = AVSpeechSynthesisVoice.FromLanguage ("en-AU"), //Volume = 0.5f, //PitchMultiplier = 1.5f }; EventHandler <AVSpeechSynthesizerUteranceEventArgs> del = null; del = (object sender, AVSpeechSynthesizerUteranceEventArgs e) => { if (e.Utterance == speechUtterance) { tcs.TrySetResult(true); speechSynthesizer.DidFinishSpeechUtterance -= del; } }; speechSynthesizer.DidFinishSpeechUtterance += del; speechSynthesizer.SpeakUtterance(speechUtterance); return(tcs.Task); }
// only works on devices, not the iOS Simulator? public void Speak() { context.Fetch(); // re-populates with updated values var text = taskDialog.Name + ". " + taskDialog.Notes; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = AVSpeechSynthesisVoice.FromLanguage("en-AU"), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); } else { Console.WriteLine("Speech requires iOS 7"); } }
public Task <bool> Speak(string text, bool disableMusic = false) { _speakTask = new TaskCompletionSource <bool>(); if (IsEnabled) { var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 2, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 1.0f, PitchMultiplier = 1.0f //PreUtteranceDelay = 0.1 }; _speechSynthesizer.DidFinishSpeechUtterance += (sender, e) => { _speakTask.TrySetResult(true); }; if (_speechSynthesizer.Speaking) { _speechSynthesizer.StopSpeaking(AVSpeechBoundary.Immediate); } _speechSynthesizer.SpeakUtterance(speechUtterance); } return(_speakTask.Task); }
public void Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text); speechSynthesizer.SpeakUtterance(speechUtterance); }
internal static async Task SpeakUtterance(AVSpeechUtterance speechUtterance, CancellationToken cancelToken) { var tcsUtterance = new TaskCompletionSource <bool>(); var speechSynthesizer = new AVSpeechSynthesizer(); try { speechSynthesizer.DidFinishSpeechUtterance += OnFinishedSpeechUtterance; speechSynthesizer.SpeakUtterance(speechUtterance); using (cancelToken.Register(TryCancel)) { await tcsUtterance.Task; } } finally { speechSynthesizer.DidFinishSpeechUtterance -= OnFinishedSpeechUtterance; } void TryCancel() { speechSynthesizer?.StopSpeaking(AVSpeechBoundary.Word); tcsUtterance?.TrySetResult(true); } void OnFinishedSpeechUtterance(object sender, AVSpeechSynthesizerUteranceEventArgs args) { if (speechUtterance == args.Utterance) { tcsUtterance?.TrySetResult(true); } } }
public void Play() { if (!String.IsNullOrEmpty (Text)) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (Text); speechSynthesizer.SpeakUtterance (speechUtterance); } }
public void WelcomePerson(string name) { if (!isSpeacking) { var speechUtterance = CreateUtterance(name); _speech.SpeakUtterance(speechUtterance); } }
public static void Speak(string toSpeak) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (toSpeak) { Rate = AVSpeechUtterance.MaximumSpeechRate / 3 }; speechSynthesizer.SpeakUtterance (speechUtterance); }
private void SpeakUtterance(bool queue, AVSpeechUtterance speechUtterance) { if (!queue && speechSynthesizer.Speaking) { speechSynthesizer.StopSpeaking(AVSpeechBoundary.Word); } speechSynthesizer.SpeakUtterance(speechUtterance); }
public void Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer (); speechSynthesizer.SpeakUtterance (new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.DefaultSpeechRate, Voice = AVSpeechSynthesisVoice.FromLanguage ("en-US"), Volume = .5f, PitchMultiplier = 1.0f }); }
public static void Speak(string toSpeak) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(toSpeak) { Rate = AVSpeechUtterance.MaximumSpeechRate / 3 }; speechSynthesizer.SpeakUtterance(speechUtterance); }
public void Speak(string text){ 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); }
public void Speak(string text) { var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = language,//AVSpeechSynthesisVoice.FromLanguage("ko-KR"), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
public void Falar(string Fala) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (Fala) { Rate = AVSpeechUtterance.MaximumSpeechRate/4, Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance (speechUtterance); }
public void SeseDonustur(string metin) { var metinSesi = new AVSpeechSynthesizer(); metinSesi.SpeakUtterance(new AVSpeechUtterance(metin) { Rate = AVSpeechUtterance.DefaultSpeechRate, Voice = AVSpeechSynthesisVoice.FromLanguage("tr-TR"), Volume = .5f, PitchMultiplier = 1.0f }); }
public void Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); speechSynthesizer.SpeakUtterance(new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.DefaultSpeechRate, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = .5f, PitchMultiplier = 1.0f }); }
/// <summary> /// 文字列を読み上げます /// </summary> /// <param name="text">読み上げる文字列</param> public void Speak(string text) { var synthesizer = new AVSpeechSynthesizer(); synthesizer.SpeakUtterance( new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = AVSpeechSynthesisVoice.FromLanguage("ja-JP"), Volume = 0.5f, PitchMultiplier = 1.0f }); }
public void LowSpeak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 2, Voice = SelectVoice(), Volume = 0.3f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
public void speak(string text) { var speechSinthesizer = new AVSpeechSynthesizer(); var speechUterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = AVSpeechSynthesisVoice.FromLanguage("es-ES"), Volume = 0.5F, PitchMultiplier = 1.0F }; speechSinthesizer.SpeakUtterance(speechUterance); }
public void Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 3, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = volume, PitchMultiplier = pitch }; 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; } } }
public void Speak(string speakText) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(speakText) { Rate = AVSpeechUtterance.MaximumSpeechRate / 2, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
/// <summary> /// Uses speech synthesis to say something. /// </summary> /// <param name="text">Text.</param> void Say(string text) { // Speak the current location. var utterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = .5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(utterance); }
public void Speak(string text, string language) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 2, Voice = AVSpeechSynthesisVoice.FromLanguage(language), Volume = 1f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
private void AISpeech(string textSpeak, float speechRate) { AVSpeechSynthesizer speech = new AVSpeechSynthesizer(); AVSpeechUtterance speechUtterance = new AVSpeechUtterance(textSpeak) { Rate = AVSpeechUtterance.MaximumSpeechRate / speechRate, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 1.0f, PitchMultiplier = 1.0f }; speech.SpeakUtterance(speechUtterance); }
async Task SpeakUtterance(AVSpeechUtterance speechUtterance, CancellationToken cancelToken) { try { currentSpeak = new TaskCompletionSource <object> (); speechSynthesizer.DidFinishSpeechUtterance += OnFinishedSpeechUtterance; speechSynthesizer.SpeakUtterance(speechUtterance); using (cancelToken.Register(TryCancel)) { await currentSpeak.Task; } } finally { speechSynthesizer.DidFinishSpeechUtterance -= OnFinishedSpeechUtterance; } }
public void Speak(string text, SpeechLanguages lang) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, //Voice = AVSpeechSynthesisVoice.FromLanguage(lang.ToLocale().LocaleIdentifier), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
public Task SpeakTextAsync(string text) { return(Task.Run(() => { var speechUtterance = new AVSpeechUtterance(text.ToLower()) { Rate = AVSpeechUtterance.MaximumSpeechRate / 4, Voice = _voice, 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); }
/// <summary> /// Speak example from: /// http://blog.xamarin.com/make-your-ios-7-app-speak/ /// </summary> public void Speak (string text) { if (!string.IsNullOrWhiteSpace (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); } }
//english voice that notifies the end user of background executions public void englishAIBackground(string textToSpeak) { AVSpeechSynthesizer englishSpeech = new AVSpeechSynthesizer(); AVSpeechUtterance englishVoice = new AVSpeechUtterance(textToSpeak) { Rate = AVSpeechUtterance.MaximumSpeechRate / 2.2f, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 1.0f, PitchMultiplier = 1.0f }; englishSpeech.SpeakUtterance(englishVoice); }
//french voice that will be used to read the subtitle (DetailTextLabel) property of the french phrases, stored currently in the table view's memory cache public void frenchPhraseBookAI(string textToSpeak) { 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); }
/// <summary> /// Speak example from: /// http://blog.xamarin.com/make-your-ios-7-app-speak/ /// </summary> void Speak (string text) { var speechSynthesizer = new AVSpeechSynthesizer (); // var voices = AVSpeechSynthesisVoice.GetSpeechVoices (); var speechUtterance = new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.MaximumSpeechRate/4, Voice = AVSpeechSynthesisVoice.FromLanguage ("en-AU"), Volume = volume, PitchMultiplier = pitch }; speechSynthesizer.SpeakUtterance (speechUtterance); }
/// <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); }
public IObservable<Unit> SpeakAsync(string speechString, CancellationToken cancellationToken = default(CancellationToken)) { speechString.AssertNotNull(nameof(speechString)); var utterance = new AVSpeechUtterance(speechString) { Voice = voice, Rate = 0.55f }; var synthesizer = new AVSpeechSynthesizer(); var finishedUtterance = Observable .FromEventPattern<AVSpeechSynthesizerUteranceEventArgs>(x => synthesizer.DidFinishSpeechUtterance += x, x => synthesizer.DidFinishSpeechUtterance -= x) .Select(_ => Unit.Default) .Publish(); finishedUtterance .Subscribe( _ => { utterance.Dispose(); synthesizer.Dispose(); }); if (cancellationToken.CanBeCanceled) { cancellationToken.Register(() => synthesizer.StopSpeaking(AVSpeechBoundary.Immediate)); Observable .FromEventPattern<AVSpeechSynthesizerUteranceEventArgs>(x => synthesizer.DidCancelSpeechUtterance += x, x => synthesizer.DidCancelSpeechUtterance -= x) .Select(_ => Unit.Default) .Subscribe( _ => { utterance.Dispose(); synthesizer.Dispose(); }); } synthesizer.SpeakUtterance(utterance); finishedUtterance.Connect(); return finishedUtterance .FirstAsync() .RunAsync(cancellationToken); }
public IObservable<Unit> Speak(string speechString) { Ensure.ArgumentNotNull(speechString, nameof(speechString)); var utterance = new AVSpeechUtterance(speechString) { Voice = voice, Rate = 0.55f }; var synthesizer = new AVSpeechSynthesizer(); var finishedUtterance = Observable .FromEventPattern<AVSpeechSynthesizerUteranceEventArgs>(x => synthesizer.DidFinishSpeechUtterance += x, x => synthesizer.DidFinishSpeechUtterance -= x) .Select(_ => Unit.Default) .Publish(); finishedUtterance .Subscribe( _ => { utterance.Dispose(); synthesizer.Dispose(); }); //if (cancellationToken.CanBeCanceled) //{ // cancellationToken.Register(() => synthesizer.StopSpeaking(AVSpeechBoundary.Immediate)); // Observable // .FromEventPattern<AVSpeechSynthesizerUteranceEventArgs>(x => synthesizer.DidCancelSpeechUtterance += x, x => synthesizer.DidCancelSpeechUtterance -= x) // .Select(_ => Unit.Default) // .Subscribe( // _ => // { // utterance.Dispose(); // synthesizer.Dispose(); // }); //} synthesizer.SpeakUtterance(utterance); finishedUtterance.Connect(); return finishedUtterance .FirstAsync(); }
// only works on devices, not the iOS Simulator? public void Speak() { context.Fetch (); // re-populates with updated values var text = taskDialog.Name + ". " + taskDialog.Notes; if (UIDevice.CurrentDevice.CheckSystemVersion (7, 0)) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.MaximumSpeechRate/4, Voice = AVSpeechSynthesisVoice.FromLanguage ("en-AU"), Volume = 0.5f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance (speechUtterance); } else { Console.WriteLine ("Speak requires iOS 7"); } }
public static Task Speak (string text) { var speechSynthesizer = new AVSpeechSynthesizer (); var tcs = new TaskCompletionSource<bool> (); var speechUtterance = new AVSpeechUtterance (text) { Rate = AVSpeechUtterance.MaximumSpeechRate/4, //Voice = AVSpeechSynthesisVoice.FromLanguage ("en-AU"), //Volume = 0.5f, //PitchMultiplier = 1.5f }; EventHandler<AVSpeechSynthesizerUteranceEventArgs> del = null; del = (object sender, AVSpeechSynthesizerUteranceEventArgs e) => { if(e.Utterance == speechUtterance){ tcs.TrySetResult(true); speechSynthesizer.DidFinishSpeechUtterance -= del; } }; speechSynthesizer.DidFinishSpeechUtterance += del; speechSynthesizer.SpeakUtterance (speechUtterance); return tcs.Task; }
public void SpeakText(string text) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance(text); speechSynthesizer.SpeakUtterance (speechUtterance); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear (animated); this.View.BackgroundColor = UIColor.LightGray; txtSpeak = new UITextView (new RectangleF (20, 50, this.View.Bounds.Width - 40, 100)); txtSpeak.Text = "Xamarin rocks!"; this.View.AddSubview (txtSpeak); segAccent = new UISegmentedControl (new string[] {"US", "UK", "AUS" }); segAccent.Frame = new RectangleF(20,160,this.View.Bounds.Width - 40, 50); segAccent.SelectedSegment = 0; this.View.AddSubview (segAccent); lblRate = new UILabel (new RectangleF (20, 230, 200, 20)); lblRate.Text = "Rate"; this.View.AddSubview (lblRate); sldRate = new UISlider(new RectangleF(20,250,this.View.Bounds.Width - 40, 50)); sldRate.MinValue = 0; sldRate.MaxValue = 100; sldRate.Value = 75; this.View.AddSubview (sldRate); lblPitch = new UILabel (new RectangleF (20, 305, 200, 20)); lblPitch.Text = "Pitch"; this.View.AddSubview (lblPitch); sldPitch = new UISlider(new RectangleF(20,325,this.View.Bounds.Width - 40, 50)); sldPitch.MinValue = 0; sldPitch.MaxValue = 100; sldPitch.Value = 75; this.View.AddSubview (sldPitch); btnSpeak = new UIButton (UIButtonType.RoundedRect); btnSpeak.Frame = new RectangleF (100, 375, this.View.Bounds.Width - 200, 30); btnSpeak.SetTitle ("Speak", UIControlState.Normal); btnSpeak.TouchDown += (object sender, EventArgs e) => { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (txtSpeak.Text); string lang = "en-US"; if (segAccent.SelectedSegment == 1) lang = "en-GB"; if (segAccent.SelectedSegment == 2) lang = "en-AU"; speechUtterance.Voice = AVSpeechSynthesisVoice.FromLanguage (lang); speechUtterance.Rate = AVSpeechUtterance.MaximumSpeechRate * (sldRate.Value / 100); speechUtterance.PitchMultiplier = 2.0f * (sldPitch.Value / 100); speechSynthesizer.SpeakUtterance (speechUtterance); }; this.View.AddSubview (btnSpeak); }