/// <summary> /// this gets the available language /// </summary> /// <returns> available language in local device </returns> private List <string> GetLanguages() { var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); return(langAvailable); }
public void Speak(string text, bool force = false) { m_text = text; m_textToSpeech.Stop(); m_force = force; if (!Sound && !force) { return; } Console.WriteLine("Speak TTS {0} {1} {2} --> {3}. Available: {4}", m_language, SpeechRate, m_textToSpeech.Language, text, m_textToSpeech.IsLanguageAvailable(m_language)); m_textToSpeech.SetLanguage(m_language); m_textToSpeech.SetSpeechRate(SpeechRate); m_textToSpeech.SetPitch(PitchMultiplier); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { // 5.0, API 21 string utteranceId = m_text.GetHashCode() + ""; m_textToSpeech.Speak(m_text, QueueMode.Flush, null, utteranceId); } else { m_textToSpeech.Speak(m_text, QueueMode.Flush, null); } }
/// <summary> /// 实现 TextToSpeech.IOnInitListener 接口方法 /// 初始化TTS /// </summary> /// <param name="status"></param> public void OnInit([GeneratedEnum] OperationResult status) { // if (status != TextToSpeech.SUCCESS) --> 安卓源码 if (status.ToString() != "Success") { // 返回并非成功结果, 继续弹出TTS语音选择界面 InitTextToSpeech(); return; } if (mTextToSpeech.IsLanguageAvailable(Java.Util.Locale.Uk) >= 0) { mTextToSpeech.SetLanguage(Java.Util.Locale.Uk); } mTextToSpeech.SetPitch(1f); mTextToSpeech.SetSpeechRate(1f); mTTS_Init_Success = true; System.Threading.Tasks.Task.Run(() => { Looper.Prepare(); Toast.MakeText(((Activity)Xamarin.Forms.Forms.Context), "TTS启动成功", ToastLength.Long).Show(); Looper.Loop(); }); }
private void InvokeRead(string TextToRead, long MillisecValue) { var editWhatToSay = FindViewById <EditText>(Resource.Id.etxtTTS); editWhatToSay.Text = TextToRead; NeedToSpeak = true; if (!string.IsNullOrEmpty(TextToRead)) { // set up the TextToSpeech object // third parameter is the speech engine to use textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // set up the langauge spinner // set the top option to be default var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); //spinLanguages.Adapter = adapter; // set up the speech to use the default langauge // if a language is not available, then the default language is used. lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); textToSpeech.Speak(TextToRead, QueueMode.Flush, null, null); var btnAction = FindViewById <ImageButton>(Resource.Id.imgBtnListen); btnAction.SetImageResource(Resource.Drawable.micspeak); //@android:drawable/presence_audio_online + Android.Resource.Drawable.PresenceAudioOnline + Android.Resource.Drawable.IcDialogInfo NeedToSpeak = false; } }
public List <Voice> GetVoices() { try { // call this only once to get voices and save them. // The following calls, just return the previously saved voices if (voicesInitialized) { return(androidVoices); } List <Voice> voices = new List <Voice>(); var localesAvailable = Java.Util.Locale.GetAvailableLocales(); foreach (var locale in localesAvailable) { try { var res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: case LanguageAvailableResult.MissingData: // MissingData actually seems to work ok (Spanish, German) //case LanguageAvailableResult.CountryAvailable: //case LanguageAvailableResult.CountryVarAvailable: // There is "English", there also a long list of English (Australia) ... English(Zimbabwe). // Just take one default locale per language for now if (locale.DisplayLanguage == locale.DisplayName) { voices.Add(new Voice() { Language = locale.DisplayLanguage, Name = locale.DisplayName }); //System.Diagnostics.Debug.WriteLine ("DisplayName, avail: " + locale.DisplayName + " " + res.ToString()); } break; } } catch (Exception) { continue; } } voices = voices.OrderBy(i => i.Language).ToList(); androidVoices = voices; voicesInitialized = true; return(androidVoices); } catch (Exception) { return(null); } }
private void InitTTSMethod() { var btnSayIt = FindViewById <Button>(Resource.Id.btnSpeakEmailForm); var editWhatToSay = FindViewById <EditText>(Resource.Id.etxtTTSEmailForm); // set up the TextToSpeech object // third parameter is the speech engine to use textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // set up the langauge spinner // set the top option to be default var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); //var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); //spinLanguages.Adapter = adapter; // set up the speech to use the default langauge // if a language is not available, then the default language is used. lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); // connect up the events btnSayIt.Click += delegate { // if there is nothing to say, don't say it if (!string.IsNullOrEmpty(editWhatToSay.Text)) { textToSpeech.Speak(editWhatToSay.Text, QueueMode.Flush, null, null); } }; }
public void InitializeLocaleList() { // referencing to the local var, the LangAvailable property can't be replaced, it's read-only _langList.Clear(); _langList.Add("Default"); // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = _textToSpeech.IsLanguageAvailable(locale); if (IsLocaleAvailable(locale)) { _langList.Add(locale.DisplayName); } } _langList = _langList.OrderBy(t => t).Distinct().ToList(); }
public void OnInit(OperationResult status) { if (status.Equals(OperationResult.Success)) { speaker.SetLanguage(Locale.ForLanguageTag("sv-SE")); if ((int)speaker.IsLanguageAvailable(Locale.ForLanguageTag(language)) > 0) { speaker.SetLanguage(Locale.ForLanguageTag(language)); } speaker.Speak(toSpeak, QueueMode.Flush, null, null); } }
private void InitSpeaking() { // Set our view from the "main" layout resource SetContentView(Resource.Layout.MainTTs); var editWhatToSay = textBox; // set up the TextToSpeech object // third parameter is the speech engine to use textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // set the top option to be default var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } // set up the speech to use the default langauge // if a language is not available, then the default language is used. lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); // set the speed and pitch textToSpeech.SetPitch(.5f); textToSpeech.SetSpeechRate(.5f); var pitch = 150 / 255f; textToSpeech.SetPitch(pitch); textToSpeech.SetSpeechRate(pitch); }
private List <string> GetLanguageSuppport() { //using defalut tts //textextToSpeech = new TextToSpeech(this, this); //using special tts //Task<TextToSpeech> _tts; //_tts = CreateTtsAsync(this, "com.google.android.tts"); //textToSpeech = _tts.Result; //textToSpeech = new TextToSpeech(this, null); IList <TextToSpeech.EngineInfo> engines = textToSpeech.Engines; var intent = new Intent(TextToSpeech.Engine.ActionCheckTtsData); StartActivityForResult(intent, 10); langAvailable = new List <string> { "Default" }; var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { var res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); spinLanguages.Adapter = adapter; return(langAvailable); }
void IOnInitListener.OnInit(OperationResult status) { if (status == OperationResult.Success) { Locale defaultOrPassedIn = locale; if (locale == null) { defaultOrPassedIn = Locale.Default; } switch (tts.IsLanguageAvailable(defaultOrPassedIn)) { case LanguageAvailableResult.Available: case LanguageAvailableResult.CountryAvailable: case LanguageAvailableResult.CountryVarAvailable: Log.Debug(LOG_TAG, "SUPPORTED"); tts.SetLanguage(locale); tts.SetSpeechRate(1.0f); tts.SetPitch(1.2f); break; case LanguageAvailableResult.MissingData: Log.Debug(LOG_TAG, "MISSING_DATA"); Log.Debug(LOG_TAG, "require data..."); Intent installIntent = new Intent(); installIntent.SetAction(TextToSpeech.Engine.ActionInstallTtsData); StartActivity(installIntent); break; case LanguageAvailableResult.NotSupported: Log.Debug(LOG_TAG, "NOT SUPPORTED"); break; default: Speak(ELUSIVE_ANSWERS); break; } } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // we need to register the onscreen gadgets we're interested in var btnSayIt = FindViewById <Button>(Resource.Id.btnSpeak); var editWhatToSay = FindViewById <EditText>(Resource.Id.editSpeech); var spinLanguages = FindViewById <Spinner>(Resource.Id.spinLanguage); var txtSpeedVal = FindViewById <TextView>(Resource.Id.textSpeed); var txtPitchVal = FindViewById <TextView>(Resource.Id.textPitch); var seekSpeed = FindViewById <SeekBar>(Resource.Id.seekSpeed); var seekPitch = FindViewById <SeekBar>(Resource.Id.seekPitch); // set up the initial pitch and speed values then the onscreen values // the pitch and rate both go from 0f to 1f, however if you have a seek bar with a max of 1, you get a single step // therefore, a simpler option is to have the slider go from 0 to 255 and divide the position of the slider by 255 to get // the float seekSpeed.Progress = seekPitch.Progress = 127; txtSpeedVal.Text = txtPitchVal.Text = "0.5"; // get the context - easiest way is to obtain it from an on screen gadget context = btnSayIt.Context; // set up the TextToSpeech object // third parameter is the speech engine to use textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // set up the langauge spinner // set the top option to be default var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); spinLanguages.Adapter = adapter; // set up the speech to use the default langauge // if a language is not available, then the default language is used. lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); // set the speed and pitch textToSpeech.SetPitch(.5f); textToSpeech.SetSpeechRate(.5f); // connect up the events btnSayIt.Click += delegate { // if there is nothing to say, don't say it if (!string.IsNullOrEmpty(editWhatToSay.Text)) { textToSpeech.Speak(editWhatToSay.Text, QueueMode.Flush, null); } }; // sliders seekPitch.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetPitch(progress); txtPitchVal.Text = progress.ToString("F2"); }; seekSpeed.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetSpeechRate(progress); txtSpeedVal.Text = progress.ToString("F2"); }; spinLanguages.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => { lang = Java.Util.Locale.GetAvailableLocales().FirstOrDefault(t => t.DisplayLanguage == langAvailable[(int)e.Id]); // create intent to check the TTS has this language installed var checkTTSIntent = new Intent(); checkTTSIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData); StartActivityForResult(checkTTSIntent, NeedLang); }; }
private void InitTTSMethod() { btnSayIt = FindViewById <Button>(Resource.Id.btnReadSMSReader); // set up the TextToSpeech object // third parameter is the speech engine to use textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); // set up the langauge spinner // set the top option to be default var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); // connect up the events btnSayIt.Click += delegate { // if there is nothing to say, don't say it var EmailsToRead = ""; EmailsToRead += " Message is.: " + SMSMessage; EmailsToRead += " from.:" + SMSFrom; EmailsToRead += " sent on.: " + SMSDate; if (!string.IsNullOrEmpty(EmailsToRead)) { if (EmailsToRead.Length > 3000) { textToSpeech.Speak(EmailsToRead.Substring(0, 3000), QueueMode.Add, null, null); } else { textToSpeech.Speak(EmailsToRead, QueueMode.Add, null, null); } } }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.activity_main); var btnSayIt = FindViewById <Button>(Resource.Id.btnSpeak); var editWhatToSay = FindViewById <EditText>(Resource.Id.editSpeech); var spinLanguages = FindViewById <Spinner>(Resource.Id.spinLanguage); var txtSpeedVal = FindViewById <TextView>(Resource.Id.textSpeed); var txtPitchVal = FindViewById <TextView>(Resource.Id.textPitch); var seekSpeed = FindViewById <SeekBar>(Resource.Id.seekSpeed); var seekPitch = FindViewById <SeekBar>(Resource.Id.seekPitch); seekSpeed.Progress = seekPitch.Progress = 127; txtSpeedVal.Text = txtPitchVal.Text = "0.5"; context = btnSayIt.Context; textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); var langAvailable = new List <string> { "Default" }; var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); spinLanguages.Adapter = adapter; lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); textToSpeech.SetPitch(0.5f); textToSpeech.SetSpeechRate(0.5f); btnSayIt.Click += delegate { if (!string.IsNullOrEmpty(editWhatToSay.Text)) { textToSpeech.Speak(editWhatToSay.Text, QueueMode.Flush, null); } }; seekPitch.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetPitch(progress); txtPitchVal.Text = progress.ToString("F2"); }; seekSpeed.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetSpeechRate(progress); txtSpeedVal.Text = progress.ToString("F2"); }; spinLanguages.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => { lang = Java.Util.Locale.GetAvailableLocales().FirstOrDefault(t => t.DisplayLanguage == langAvailable[(int)e.Id]); var checkTTSIntent = new Intent(); checkTTSIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData); StartActivityForResult(checkTTSIntent, NeedLang); }; }
/////////////////////////////////////////////////////// protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle);; string TxtToVoice = this.Intent.GetStringExtra("TxtToVoice"); int para2 = this.Intent.GetIntExtra("DelayTime", -1); isRecording = false; SetContentView(Resource.Layout.TextToLuisMain); textBox = FindViewById <TextView>(Resource.Id.textYourText); LuisBox_Intent = FindViewById <TextView>(Resource.Id.LuisIntentText); LuisBox_Entiti = FindViewById <TextView>(Resource.Id.LuisEntitiText); int para3 = this.Intent.GetIntExtra("para3", -1); if (para3 >= 0) { VoiceIndex = para3; para3 = 0; PollingJobTime(300, para3); } else { PollingJobTime(300, 0); } textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); var langAvailable = new List <string> { "Default" }; // our spinner only wants to contain the languages supported by the tts and ignore the rest var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); // set up the speech to use the default langauge // if a language is not available, then the default language is used. lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); // set the speed and pitch textToSpeech.SetPitch(.9f); textToSpeech.SetSpeechRate(.9f); // check to see if we can actually record - if we can, assign the event to the button string rec = Android.Content.PM.PackageManager.FeatureMicrophone; if (rec != "android.hardware.microphone") { // no microphone, no recording. Disable the button and output an alert var alert = new AlertDialog.Builder(recButton.Context); alert.SetTitle("You don't seem to have a microphone to record with"); alert.SetPositiveButton("OK", (sender, e) => { textBox.Text = "No microphone present"; recButton.Enabled = false; return; }); alert.Show(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); //Speak to text isRecording = false; recButton = FindViewById <Button> (Resource.Id.btnRecord); Log.Info("MainActivity", "recButton 1=" + recButton); textBox = FindViewById <TextView> (Resource.Id.textYourText); string rec = Android.Content.PM.PackageManager.FeatureMicrophone; if (rec != "android.hardware.microphone") { // no microphone, no recording. Disable the button and output an alert var alert = new AlertDialog.Builder(recButton.Context); alert.SetTitle("You don't seem to have a microphone to record with"); alert.SetPositiveButton("OK", (sender, e) => { textBox.Text = "No microphone present"; recButton.Enabled = false; return; }); alert.Show(); } else { Log.Info("MainActivity", "recButton 2=" + recButton); recButton.Click += delegate { // change the text on the button recButton.Text = "End Recording"; isRecording = !isRecording; if (isRecording) { Log.Info("MainActivity", "isRecording=" + isRecording); // create the intent and start the activity var voiceIntent = new Intent(RecognizerIntent.ActionRecognizeSpeech); voiceIntent.PutExtra(RecognizerIntent.ExtraLanguageModel, RecognizerIntent.LanguageModelFreeForm); // put a message on the modal dialog voiceIntent.PutExtra(RecognizerIntent.ExtraPrompt, Application.Context.GetString(Resource.String.messageSpeakNow)); // if there is more then 1.5s of silence, consider the speech over voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputCompleteSilenceLengthMillis, 1500); voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputPossiblyCompleteSilenceLengthMillis, 1500); voiceIntent.PutExtra(RecognizerIntent.ExtraSpeechInputMinimumLengthMillis, 15000); voiceIntent.PutExtra(RecognizerIntent.ExtraMaxResults, 1); // you can specify other languages recognised here, for example // voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.German); // if you wish it to recognise the default Locale language and German // if you do use another locale, regional dialects may not be recognised very well voiceIntent.PutExtra(RecognizerIntent.ExtraLanguage, Java.Util.Locale.Default); StartActivityForResult(voiceIntent, VOICE); } }; } //Text to speak var btnSayIt = FindViewById <Button> (Resource.Id.btnSpeak); var editWhatToSay = FindViewById <EditText> (Resource.Id.editSpeech); var spinLanguages = FindViewById <Spinner> (Resource.Id.spinLanguage); var txtSpeedVal = FindViewById <TextView> (Resource.Id.textSpeed); var txtPitchVal = FindViewById <TextView> (Resource.Id.textPitch); var seekSpeed = FindViewById <SeekBar> (Resource.Id.seekSpeed); var seekPitch = FindViewById <SeekBar> (Resource.Id.seekPitch); seekSpeed.Progress = seekPitch.Progress = 127; txtSpeedVal.Text = txtPitchVal.Text = "1.0"; context = btnSayIt.Context; textToSpeech = new TextToSpeech(this, this, "com.google.android.tts"); var langAvailable = new List <string> { "Default" }; var localesAvailable = Java.Util.Locale.GetAvailableLocales().ToList(); foreach (var locale in localesAvailable) { LanguageAvailableResult res = textToSpeech.IsLanguageAvailable(locale); Log.Info("MainActivity", "locale available=" + locale); switch (res) { case LanguageAvailableResult.Available: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryAvailable: langAvailable.Add(locale.DisplayLanguage); break; case LanguageAvailableResult.CountryVarAvailable: langAvailable.Add(locale.DisplayLanguage); break; } } langAvailable = langAvailable.OrderBy(t => t).Distinct().ToList(); var adapter = new ArrayAdapter <string> (this, Android.Resource.Layout.SimpleSpinnerDropDownItem, langAvailable); spinLanguages.Adapter = adapter; lang = Java.Util.Locale.Default; textToSpeech.SetLanguage(lang); textToSpeech.SetPitch(1.1f); textToSpeech.SetSpeechRate(1.0f); btnSayIt.Click += delegate { Log.Info("MainActivity", "btnSayIt: " + editWhatToSay.Text); if (!string.IsNullOrEmpty(editWhatToSay.Text)) { textToSpeech.Speak(editWhatToSay.Text, QueueMode.Flush, null); } }; seekPitch.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetPitch(progress); txtPitchVal.Text = progress.ToString("F2"); }; seekSpeed.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) => { var seek = sender as SeekBar; var progress = seek.Progress / 255f; textToSpeech.SetSpeechRate(progress); txtSpeedVal.Text = progress.ToString("F2"); }; spinLanguages.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) => { lang = Java.Util.Locale.GetAvailableLocales().FirstOrDefault(t => t.DisplayLanguage == langAvailable [(int)e.Id]); // create intent to check the TTS has this language installed var checkTTSIntent = new Intent(); checkTTSIntent.SetAction(TextToSpeech.Engine.ActionCheckTtsData); StartActivityForResult(checkTTSIntent, NeedLang); }; //VOLUMKONTROLL!! Volumet er uavhengig fra alle andre volumkontroller på device! //parsing var btnTell = FindViewById <Button> (Resource.Id.btnTell); var say = FindViewById <EditText> (Resource.Id.textYouSay); btnTell.Click += delegate { Log.Info("MainActivity", "btnTell: " + say.Text); if (!string.IsNullOrEmpty(say.Text)) { String tell = learner.respondToSentence(say.Text); textBox.Text = tell; textToSpeech.Speak(tell, QueueMode.Flush, null); //learn (say.Text); } }; }
public void OnInit(Android.Speech.Tts.OperationResult result) { Console.WriteLine(Speech.IsLanguageAvailable(Java.Util.Locale.English)); Speech.SetLanguage(Java.Util.Locale.English); }