public void Speak(string text) { var utterance = new AVSpeechUtterance(text); utterance.Rate = AVSpeechUtterance.MinimumSpeechRate + 0.1f; utterance.Voice = AVSpeechSynthesisVoice.FromLanguage("en-us"); _synthesizer.SpeakUtterance(utterance); }
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); }
internal static void _OnStarted(AVSpeechUtterance utterance) { if (_speechStartedHandlers != null) { _speechStartedHandlers(null, new SpeechEventArgs(utterance)); } }
internal static void _OnWillSpeak(AVSpeechUtterance utterance, NSRange characterRange) { if (_willSpeakHandlers != null) { _willSpeakHandlers(null, new SpeechWillSpeakEventArgs(utterance, characterRange)); } }
// 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); }
private AVSpeechUtterance GetSpeechUtterance(string text, CrossLocale? crossLocale, float? pitch, float? speakRate, float? volume) { AVSpeechUtterance speechUtterance; var voice = GetVoiceForLocaleLanguage(crossLocale); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { speechUtterance = new AVSpeechUtterance(" "); speechUtterance.Voice = voice; } else { speakRate = NormalizeSpeakRate(speakRate); volume = NormalizeVolume(volume); pitch = NormalizePitch(pitch); speechUtterance = new AVSpeechUtterance(text) { Rate = speakRate.Value, Voice = voice, Volume = volume.Value, PitchMultiplier = pitch.Value }; } return speechUtterance; }
static AVSpeechUtterance GetSpeechUtterance(string text, SpeechOptions options) { var speechUtterance = new AVSpeechUtterance(text); if (options != null) { // null voice if fine - it is the default speechUtterance.Voice = AVSpeechSynthesisVoice.FromLanguage(options.Locale?.Language) ?? AVSpeechSynthesisVoice.FromLanguage(AVSpeechSynthesisVoice.CurrentLanguageCode); // the platform has a range of 0.5 - 2.0 // anything lower than 0.5 is set to 0.5 if (options.Pitch.HasValue) { speechUtterance.PitchMultiplier = options.Pitch.Value; } if (options.Volume.HasValue) { speechUtterance.Volume = options.Volume.Value; } } return(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 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); }
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); }
private AVSpeechUtterance GetSpeechUtterance(string text, CrossLocale?crossLocale, float?pitch, float?speakRate, float?volume) { AVSpeechUtterance speechUtterance; var voice = GetVoiceForLocaleLanguage(crossLocale); speakRate = NormalizeSpeakRate(speakRate); pitch = NormalizePitch(pitch); speechUtterance = new AVSpeechUtterance(text) { Rate = speakRate.Value, Voice = voice, PitchMultiplier = pitch.Value }; if (volume.HasValue) { volume = NormalizeVolume(volume); speechUtterance.Volume = volume.Value; } return(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 }
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 void Speak(string text) { var speechSynthesizer = new AVSpeechSynthesizer(); var speechUtterance = new AVSpeechUtterance(text); speechSynthesizer.SpeakUtterance(speechUtterance); }
private AVSpeechUtterance GetSpeechUtterance(string text, CrossLocale?crossLocale, float?pitch, float?speakRate, float?volume) { AVSpeechUtterance speechUtterance; var voice = GetVoiceForLocaleLanguage(crossLocale); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { speechUtterance = new AVSpeechUtterance(text) { Voice = voice }; } else { speakRate = NormalizeSpeakRate(speakRate); volume = NormalizeVolume(volume); pitch = NormalizePitch(pitch); speechUtterance = new AVSpeechUtterance(text) { Rate = speakRate.Value, Voice = voice, Volume = volume.Value, PitchMultiplier = pitch.Value }; } return(speechUtterance); }
async void Descripcion(object sender, EventArgs e) { var ruta = await DescargarImagenAnalizarFelicidad(); imagen.Image = UIImage.FromFile(ruta); var StreamdeImagen = imagen.Image.AsJPEG(.5f).AsStream(); { try { var result = await DescripciondeImagen(StreamdeImagen); imagen.Dispose(); lblDescripccion.Text = ""; foreach (string tags in result.Description.Tags) { var voz = new AVSpeechUtterance(tags); lblDescripccion.Text = lblDescripccion.Text + "\n" + tags; habla.SpeakUtterance(voz); } } catch (Exception ex) { lblDescripccion.Text = ex.Message; } } }
public void Dispose() { synthesizer.DidFinishSpeechUtterance -= OnFinishedSpeechUtterance; utterance.Dispose(); synthesizer.Dispose(); utterance = null; synthesizer = null; }
public void Play() { if (!String.IsNullOrEmpty (Text)) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (Text); speechSynthesizer.SpeakUtterance (speechUtterance); } }
private void SpeakUtterance(bool queue, AVSpeechUtterance speechUtterance) { if (!queue && speechSynthesizer.Speaking) { speechSynthesizer.StopSpeaking(AVSpeechBoundary.Word); } speechSynthesizer.SpeakUtterance(speechUtterance); }
public static void Speak(string toSpeak) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance (toSpeak) { Rate = AVSpeechUtterance.MaximumSpeechRate / 3 }; speechSynthesizer.SpeakUtterance (speechUtterance); }
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 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.DefaultSpeechRate, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 1f, PitchMultiplier = 1.0f }; speechSynthesizer.SpeakUtterance(speechUtterance); }
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); }
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); }
/// <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 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 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); }
public void Play(string message) { if (_speaker.Speaking) return; var speechUtterance = new AVSpeechUtterance(message) { Rate = AVSpeechUtterance.MaximumSpeechRate / 5, Voice = AVSpeechSynthesisVoice.FromLanguage("en-US"), Volume = 1f, PitchMultiplier = 1.0f }; _speaker.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); }
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); }
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); } }
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); })); }
//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); }
//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); }
/// <summary> /// Speak back text /// </summary> /// <param name="text">Text to speak</param> /// <param name="queue">If you want to chain together speak command or cancel current</param> /// <param name="crossLocale">Locale of voice</param> /// <param name="pitch">Pitch of voice</param> /// <param name="speakRate">Speak Rate of voice (All) (0.0 - 2.0f)</param> /// <param name="volume">Volume of voice (iOS/WP) (0.0-1.0)</param> public void Speak(string text, bool queue = false, CrossLocale? crossLocale = null, float? pitch = null, float? speakRate = null, float? volume = null) { if (string.IsNullOrWhiteSpace(text)) return; if (speechSynthesizer == null) Init(); var localCode = crossLocale.HasValue && !string.IsNullOrWhiteSpace(crossLocale.Value.Language) ? crossLocale.Value.Language : AVSpeechSynthesisVoice.CurrentLanguageCode; pitch = !pitch.HasValue ? 1.0f : pitch; if (!volume.HasValue) volume = 1.0f; else if (volume > 1.0f) volume = 1.0f; else if (volume < 0.0f) volume = 0.0f; if (!speakRate.HasValue) speakRate = AVSpeechUtterance.MaximumSpeechRate / 4.0f; //normal speech, default is fast else if (speakRate.Value > AVSpeechUtterance.MaximumSpeechRate) speakRate = AVSpeechUtterance.MaximumSpeechRate; else if (speakRate.Value < AVSpeechUtterance.MinimumSpeechRate) speakRate = AVSpeechUtterance.MinimumSpeechRate; 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); } var speechUtterance = new AVSpeechUtterance(text) { Rate = speakRate.Value, Voice = voice, Volume = volume.Value, PitchMultiplier = pitch.Value }; if (!queue && speechSynthesizer.Speaking) speechSynthesizer.StopSpeaking(AVSpeechBoundary.Word); speechSynthesizer.SpeakUtterance(speechUtterance); }
/// <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"); } }
internal static void _OnStarted(AVSpeechUtterance utterance) { if (_speechStartedHandlers != null) _speechStartedHandlers(null, new SpeechEventArgs(utterance)); }
public void SpeakText(string text) { var speechSynthesizer = new AVSpeechSynthesizer (); var speechUtterance = new AVSpeechUtterance(text); speechSynthesizer.SpeakUtterance (speechUtterance); }
private void SpeakUtterance(bool queue, AVSpeechUtterance speechUtterance) { if (!queue && speechSynthesizer.Speaking) speechSynthesizer.StopSpeaking(AVSpeechBoundary.Word); 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 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; }
/// <summary> /// Initializes a new instance of the <see cref="U3DXT.iOS.Speech.SpeechEventArgs"/> class. /// </summary> /// <param name="utterance">Utterance.</param> public SpeechEventArgs(AVSpeechUtterance utterance) { this.utterance = utterance; }
/// <summary> /// Initializes a new instance of the <see cref="U3DXT.iOS.Speech.SpeechWillSpeakEventArgs"/> class. /// </summary> /// <param name="utterance">Utterance.</param> /// <param name="characterRange">Character range.</param> public SpeechWillSpeakEventArgs(AVSpeechUtterance utterance, NSRange characterRange) : base(utterance) { this.characterRange = characterRange; }
internal static void _OnWillSpeak(AVSpeechUtterance utterance, NSRange characterRange) { if (_willSpeakHandlers != null) _willSpeakHandlers(null, new SpeechWillSpeakEventArgs(utterance, characterRange)); }
/// <summary> /// Speak the specified text. /// </summary> /// <param name="text">Text.</param> public static void Speak(string text) { if (_syn == null) { _syn = new AVSpeechSynthesizer(); _syn.Delegate = SpeechSynthesizerDelegate.instance; } var utterance = new AVSpeechUtterance(text); if (_settings != null) { utterance.pitchMultiplier = _settings.pitchMultiplier; utterance.postUtteranceDelay = _settings.postUtteranceDelay; utterance.preUtteranceDelay = _settings.preUtteranceDelay; utterance.rate = _settings.rate; utterance.voice = _settings.voice; utterance.volume = _settings.volume; } _syn.SpeakUtterance(utterance); }