public void OnInit([GeneratedEnum] OperationResult status) { if (status == OperationResult.Success) { try { var list = toSpeech.Voices; foreach (var item in list) { if (item.Name == configuracion.TipoVoz) { v = item; break; } } if (v != null) { toSpeech.SetVoice(v); } toSpeech.SetSpeechRate(configuracion.Velocidad); toSpeech.SetLanguage(new Locale("es", "ES")); toSpeech.Speak(textToSpeak, QueueMode.Flush, null); Thread.Sleep(2000); } catch (Exception e) { Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } while (true) { if (!toSpeech.IsSpeaking) { Log.Info(LOG_TAG, "he terminado de hablar"); toSpeech.Stop(); toSpeech.Shutdown(); break; } } if (record) { speechReco.StartListening(intentReco); } else if (!record && textToSpeak == "Sesión cerrada correctamente") { this.FinishAffinity(); } } }
//Get Engines support by Device public async Task <List <string> > GetEngines(Context c) { Log.Debug(TAG, "Trying to get Engine: "); TextToSpeech tts = await CreateTtsAsync(c, this, null); IList <TextToSpeech.EngineInfo> engines = tts.Engines; var listNameEngine = new List <string>(); foreach (var engine in engines) { listNameEngine.Add(engine.Label); } if (listNameEngine.Count == 0) { listNameEngine.Add("NONE"); } try { tts.Shutdown(); } catch { /* don't care */ } return(listNameEngine); }
public void onStop() { mTextToSpeech.Stop();; // 不管是否正在朗读TTS都被打断 mTextToSpeech.Shutdown(); //关闭,释放资源 player.Release(); playerloop.Reset(); }
private void StopTextToSpeech() { if (Speech != null) { Speech.Shutdown(); Speech = null; } }
protected override void OnDestroy() { if (_spokenWord != null) { _spokenWord.Shutdown(); } base.OnDestroy(); }
protected override void OnDestroy() { base.OnDestroy(); if (_spokenWord != null) { _spokenWord.Shutdown(); Log.Info(TAG, "OnDestroy: Shutdown of Spoken Word"); } }
//En nuestro metodo de destruccion paramos y apagamos el dictado protected override void OnDestroy() { if (tts != null) { tts.Stop(); tts.Shutdown(); } base.OnDestroy(); }
protected override void OnDestroy() { // Don't forget to shutdown tts! if (tts != null) { tts.Stop(); tts.Shutdown(); } base.OnDestroy(); }
public void OnInit([GeneratedEnum] OperationResult status) { if (status == OperationResult.Success) { try { toSpeech.SetLanguage(new Locale("es", "ES")); toSpeech.Speak(textToSpeak, QueueMode.Flush, null, null); Thread.Sleep(2000); } catch (Exception e) { Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } while (true) { if (!toSpeech.IsSpeaking) { Log.Info(LOG_TAG, "he terminado de hablar"); toSpeech.Stop(); toSpeech.Shutdown(); break; } } if (!record && !textToSpeak.Contains("No hay conexión a Internet") && !textToSpeak.Contains("código de verificación")) { StartActivity(typeof(MainActivity)); } else if (!record && textToSpeak.Contains("Ha habido un error")) { this.FinishAffinity(); } else if (!record && textToSpeak.Contains("Ha ocurrido un error.")) { this.FinishAffinity(); } else { speechReco.StartListening(intentReco); } } }
protected override void Dispose(bool disposing) { if (disposing) { speaker?.Stop(); speaker?.Shutdown(); speaker = null; } base.Dispose(disposing); }
/// <summary> /// Text to speech initialization callback. /// </summary> public void OnInit(int status) { if (status == TextToSpeech.SUCCESS) { textToSpeech.Speak(recognizedText, TextToSpeech.QUEUE_FLUSH, null); } else if (status == TextToSpeech.ERROR) { textToSpeech.Shutdown(); } }
public void Clean() { if (speaker != null) { if (speaking) { speaker.Stop(); } speaker.Shutdown(); } }
protected override void Dispose(bool disposing) { lock (_locker) { base.Dispose(disposing); _disposed = true; try { _textToSpeech.Shutdown(); } catch (Exception) { } } }
public override void Dispose() { try { tts.Shutdown(); tts.Dispose(); } catch (Exception ex) { System.Diagnostics.Debug.Fail(ex.Message, ex.ToString()); } sources.ClearAsync(a => a.Value?.TrySetCanceled()); }
public void OnInit([GeneratedEnum] OperationResult status) { if (status == OperationResult.Success) { try { if (v != null) { toSpeech.SetVoice(v); } toSpeech.SetSpeechRate(configuracion.Velocidad); toSpeech.SetLanguage(new Locale("es", "ES")); toSpeech.Speak(textToSpeak, QueueMode.Flush, null); System.Threading.Thread.Sleep(2000); } catch (Exception e) { Toast.MakeText(this, e.Message, ToastLength.Long).Show(); } while (true) { if (!toSpeech.IsSpeaking) { Log.Info(LOG_TAG, "he terminado de hablar"); toSpeech.Stop(); toSpeech.Shutdown(); break; } } if (record) { speechReco.StartListening(intentReco); } } }
public async Task <ICollection <Locale> > GetLanguageSupportByEngineAsync(Context c, string engine) { Log.Debug(TAG, "Trying to create TTS Engine: "); TextToSpeech _tts = await CreateTtsAsync(c, this, engine); ICollection <Locale> langCollect = null; List <string> lang = new List <string>(); if (_tts != null) { langCollect = _tts.AvailableLanguages; //Clear TTS try { _tts.Shutdown(); } catch { /* don't care */ } _tts = null; } return(langCollect); }
protected override void OnDestroy() { base.OnDestroy(); tts.Shutdown(); Log.Debug(TAG, "Destroyed..."); }
private async void GetEnginesAndLangsAsync() { _tts = new TextToSpeech(this, null); IList <TextToSpeech.EngineInfo> engines = _tts.Engines; try { _tts.Shutdown(); } catch { /* don't care */ } foreach (TextToSpeech.EngineInfo ei in engines) { Log.Debug(TAG, "Trying to create TTS Engine: " + ei.Name); Log.Debug(TAG, "in GetEnginesAndLangsAsync() before await for CreateTtsAsync(), Thread: " + System.Threading.Thread.CurrentThread.ManagedThreadId); _tts = await CreateTtsAsync(this, ei.Name); // DISRUPTION 1 from Java code eliminated, we simply await TTS engine initialization here. if (_tts != null) { var el = new EngLang(ei); _allEngines.Add(el); Log.Debug(TAG, "Engine: " + ei.Name + " initialized correctly."); var intent = new Intent(TextToSpeech.Engine.ActionCheckTtsData); intent = intent.SetPackage(el.Ei.Name); Intent data = await StartActivityForResultAsync(intent, LANG_REQUEST); // DISTRUPTION 2 from Java code eliminated, we simply await until the result returns. try { // don't care if lastData or voices comes out null, just catch exception and continue IList <String> voices = data.GetStringArrayListExtra(TextToSpeech.Engine.ExtraAvailableVoices); Log.Debug(TAG, "Listing voices for " + el.Name() + " (" + el.Label() + "):"); foreach (String s in voices) { el.AddVoice(s); Log.Debug(TAG, "- " + s); } } catch (Exception e) { Log.Debug(TAG, "Engine " + el.Name() + " listing voices exception: " + e); } try { _tts.Shutdown(); } catch { /* don't care */ } _tts = null; } } FindViewById(Resource.Id.wait).Visibility = ViewStates.Gone; FindViewById(Resource.Id.main).Visibility = ViewStates.Visible; _voiceSpinner = (Spinner)FindViewById(Resource.Id.voices); _voiceSpinner.ItemSelected += _voiceSpinner_ItemSelected; // Complete setup var languages = new List <String>(); String initLang = Intent.GetStringExtra(INIT_LANG); initLang = initLang != null ? new Locale(initLang).ISO3Language : Locale.Default.ISO3Language; foreach (EngLang el in _allEngines) { foreach (String v in el.Voices) { String lang = v; int i = lang.IndexOf('-'); if (i > 0) { lang = lang.Substring(0, i); } var loc = new Locale(lang); lang = loc.ISO3Language.ToLower(); if (lang.Length != 3) { continue; } bool doAdd = true; foreach (LangCodeName lcn in _langCodes) { if (lcn.Code != lang) { continue; } doAdd = false; break; } if (doAdd) { _langCodes.Add(new LangCodeName(lang)); } } } _langCodes.Sort(); int selPos = -1; for (int i = 0; i < _langCodes.Count; i++) { languages.Add(_langCodes[i].Name); if (_langCodes[i].Code.Equals(initLang)) { selPos = i; } } var adapter = new ArrayAdapter <String>(this, Android.Resource.Layout.SimpleSpinnerItem, languages); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); var langSpinner = (Spinner)FindViewById(Resource.Id.languages); langSpinner.Adapter = adapter; if (selPos > -1) { langSpinner.SetSelection(selPos); } langSpinner.ItemSelected += langSpinner_ItemSelected; _voiceSpinner.ItemSelected += _voiceSpinner_ItemSelected; var addBtn = (Button)FindViewById(Resource.Id.add_lang_btn); addBtn.Click += addBtn_Click; var useBtn = (Button)FindViewById(Resource.Id.use_voice_btn); useBtn.Click += useBtn_Click; }