Beispiel #1
0
        /// <summary>
        /// Initialize TTS
        /// </summary>
        public void Init()
        {
            Console.WriteLine("Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);
            Android.Util.Log.Info("CrossTTS", "Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);

            textToSpeech = new Android.Speech.Tts.TextToSpeech(Application.Context, this);
        }
        /// <summary>
        /// Process results from started activities.
        /// </summary>
        protected override void OnActivityResult(int requestCode, int resultCode, Intent data)
        {
            if (requestCode == RECOGNIZER_RESULT && resultCode == RESULT_OK)
            {
                var matches = data.GetStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

                var speechText = FindViewById<TextView>(R.Ids.speechText);
                recognizedText = matches.Get(0);
                speechText.SetText(recognizedText);

                var checkIntent = new Intent();
                checkIntent.SetAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
                StartActivityForResult(checkIntent, SPEECH_RESULT);
            }

            if (requestCode == SPEECH_RESULT)
            {
                if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
                {
                    textToSpeech = new TextToSpeech(this, this);
                    textToSpeech.SetLanguage(Locale.US);
                }
                else
                {
                    // TTS data not yet loaded, try to install it
                    var ttsLoadIntent = new Intent();
                    ttsLoadIntent.SetAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                    StartActivity(ttsLoadIntent);
                }
            }
            base.OnActivityResult(requestCode, resultCode, data);
        }
        /// <summary>
        /// Initialize TTS
        /// </summary>
        public void Init()
        {
            Console.WriteLine("Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);
            Android.Util.Log.Info("CrossTTS", "Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);

            textToSpeech = new Android.Speech.Tts.TextToSpeech(Application.Context, this);
        }
Beispiel #4
0
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view from the "main" layout resource
			SetContentView (Resource.Layout.Main);

			//Inicializaremos nuestra variable principal que nos pide dos parametros nuestro contexto y una clase
			//tipo TextToSpeech.IOnInitListener la cual heredamos mediante la implementacion de la clase
			tts = new TextToSpeech (this, this);

			Button button = FindViewById<Button> (Resource.Id.Button1);
			EditText caja = FindViewById<EditText> (Resource.Id.Texto);
			button.Click += delegate {
				//Verificamos que nuestra variable tipo TextToSpeech sea diferente de null
				if (tts!=null) {
					//En una variable tipo string depositamos el contenido de nuestro textbox
					String text = caja.Text;
					//Verificamos que nuestra variable de texto no sea nula para evitar una excepcion
					if (text!=null) {
						//Verificamos que nuestro telefono no este usando la funcion de dictado
						if (!tts.IsSpeaking) {
							//mandamos a llamar la funcion de dictado que nos pedida tres parametros
							//1 Texto a dictar
							//2 Modo
							//3 Diccionario de parametros el cual ira vacio en esta ocacion
							tts.Speak(text, QueueMode.Flush, new Dictionary<string, string>());
						}
					}
				}
			};
		}
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button>(Resource.Id.myButton);

            button.Click += (object sender, EventArgs e) =>
            {
                Button btn = (Button)sender;
                toSpeak = btn.Text;
                if (speaker == null)
                {
                    speaker = new Android.Speech.Tts.TextToSpeech(this, this);
                }
                else
                {
                    var p = new Dictionary <string, string> ();
                    speaker.Speak(toSpeak, QueueMode.Flush, p);
                    System.Diagnostics.Debug.WriteLine("spoke " + toSpeak);
                }
            };
        }
Beispiel #6
0
        private bool IsSpeakerInitialized(SpeechTts.TextToSpeech _speaker)
        {
            if (_speaker != null)
            {
                return(true);
            }

            return(false);
        }
Beispiel #7
0
 void IDisposable.Dispose()
 {
     if (textToSpeech != null)
     {
         textToSpeech.Stop();
         textToSpeech.Dispose();
         textToSpeech = null;
     }
 }
        public AndroidTextToSpeech(AndroidSensusService service)
        {
            _textToSpeech = new TextToSpeech(service, this);
            _initWait = new ManualResetEvent(false);
            _utteranceWait = new ManualResetEvent(false);
            _disposed = false;

            _textToSpeech.SetOnUtteranceProgressListener(this);
        }
 private void SetObject()
 {
     this.ActionBar.Hide();
     btnFind      = FindViewById <Button>(Resource.Id.btnFind);
     textToSpeech = new Android.Speech.Tts.TextToSpeech(Application.Context, null);
     mapMain      = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.mapMain);
     map          = mapMain.Map;
     //map.MapType = GoogleMap.MapTypeNormal;
     map.UiSettings.ZoomControlsEnabled = true;
 }
Beispiel #10
0
 public void Falar(string Fala)
 {
     var ctx = Forms.Context; // useful for many Android SDK features
     if (speaker == null) {
         speaker = new TextToSpeech (ctx, this);
     } else {
         var p = new Dictionary<string,string> ();
         speaker.Speak (Fala, QueueMode.Flush, p);
     }
 }
Beispiel #11
0
        public void Speak(string text)
        {
            _text = text;
            if (!this.IsSpeakerInitialized(speaker))
            {
                speaker = this.InitializingSpeaker();
            }

            speaker.Speak(_text, SpeechTts.QueueMode.Flush, null, null);
        }
		public void Speak(string text)
		{
			if (speech == null) {
				lastText = text;
				speech = new TextToSpeech(Application.Context, this);
			}
			else {
				speech.Speak(text, QueueMode.Flush, new Dictionary<string, string>());
			}
		}
 public TextToSpeechManager(Context context)
 {
     if (context == null)
         throw new ArgumentNullException("context");
     this.context = context;
     app = ((GlobalApp)context.ApplicationContext);
     if (mTts == null)
         mTts = new TextToSpeech(context, this);
     lockObject = new object();
 }
 public void Speak(string text)
 {
     var c = Forms.Context;
     toSpeak = text;
     if (speaker == null) {
         speaker = new TextToSpeech (c, this);
     }
     var p = new Dictionary<string,string> ();
     speaker.Speak (toSpeak, QueueMode.Flush, p);
 }
        public void Speak(string text) {
            if (this.IsSpeaking)
                return;

            this.IsSpeaking = true;
            this.speechText = text;
            if (this.speech != null) 
                this.DoSpeech();
            else 
                this.speech = new TextToSpeech(Forms.Context, this);
        }
Beispiel #16
0
		public void Speak (Context context, string text)
		{
			toSpeak = text;
			if (speaker == null)
				speaker = new TextToSpeech (context, this);
			else
			{
				var p = new Dictionary<string,string> ();
				speaker.Speak (toSpeak, QueueMode.Flush, p);
			}
		}
Beispiel #17
0
 public void Speak(string text)
 {
     toSpeak = text;
     if (speaker == null)
     {
         speaker = new Android.Speech.Tts.TextToSpeech(MainActivity.Instance, this);
     }
     else
     {
         speaker.Speak(toSpeak, QueueMode.Flush, null, null);
     }
 }
		public void Speak (string text)
		{
			if (!string.IsNullOrWhiteSpace (text)) {
				toSpeak = text;
				if (textToSpeech == null) {
					textToSpeech = new TextToSpeech (Forms.Context, this);
				} else {
					var p = new Dictionary<string, string> ();
					textToSpeech.Speak (toSpeak, QueueMode.Flush, p);
				}
			}
		}
		public void Speak (string text)
		{
			var c = Forms.Context; 
			toSpeak = text;
			if (speaker == null) {
				speaker = new TextToSpeech (c, this);
			} else {
				var p = new Dictionary<string,string> ();
				speaker.Speak (toSpeak, QueueMode.Flush, p);
				System.Diagnostics.Debug.WriteLine ("spoke " + toSpeak);
			}
		}
Beispiel #20
0
 public void OnInit(OperationResult status)
 {
     if(status == OperationResult.Success)
     {
         tts.SetLanguage(Locale.Default);
         tts.SetOnUtteranceProgressListener(this);
     }
     else
     {
         tts = null;
     }
 }
Beispiel #21
0
 public void Speak(string text)
 {
     ToSpeak = text;
     if (speaker == null)
     {
         speaker = new Android.Speech.Tts.TextToSpeech(CurrentActivity.BaseContext, this);
     }
     else
     {
         speaker.Speak(ToSpeak, QueueMode.Flush, null, null);
     }
 }
Beispiel #22
0
        public override void OnCreate()
        {
            base.OnCreate();

            _speech = new TextToSpeech(this, this);

            _orientationManager = new OrientationManager(
                this.getSensorManager(),
                this.getLocationManager());

            _landmarks = new Landmarks(AndroidResourceReader.read(this, Resource.Raw.landmarks));
        }
Beispiel #23
0
        public override void OnCreate()
        {
            base.OnCreate();

            _speech = new TextToSpeech(this, this);

            _orientationManager = new OrientationManager(
                this.getSensorManager(),
                this.getLocationManager());

            _landmarks = new Landmarks(this);
        }
 public void Speak(string text)
 {
     toSpeak = text;
     if (speaker == null)
     {
         MainActivity context = (MainActivity)Forms.Context;
         speaker = new DroidTts.TextToSpeech(context, this);
     }
     else
     {
         speaker.Speak(toSpeak, DroidTts.QueueMode.Flush, null, null);
     }
 }
Beispiel #25
0
        public void Conversar(string texto)
        {
            var ctx = Xamarin.Forms.Forms.Context;

            textAFalar = texto;

            if (speaker == null) {
                speaker = new TextToSpeech (ctx, this);
            } else {
                var p = new Dictionary<string,string> ();

                speaker.Speak (textAFalar, QueueMode.Flush, p);
            }
        }
 public void Speak(string text)
 {
     var c = Forms.Context;
     _toSpeak = text;
     if (_speaker == null)
     {
         _speaker = new TextToSpeech(c, this);
     }
     else
     {
         var p = new Dictionary<string, string>();
         _speaker.Speak(_toSpeak, QueueMode.Flush, p);
         Debug.WriteLine("spoke " + _toSpeak);
     }
 }
Beispiel #27
0
 public void Speak(string text)
 {
     if (speech == null) {
         lastText = text;
         speech = new TextToSpeech (Android.App.Application.Context, this);
     } else {
         if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
             speech.Speak (text, QueueMode.Flush, null, null);
         else {
     #pragma warning disable 0618
             speech.Speak (text, QueueMode.Flush, null);
     #pragma warning restore 0618
         }
     }
 }
		public void speak(string text, float speed)
		{
			var context = Forms.Context;
			tosay = text;
			speakSpeed = speed;

			if (speaker == null) {
				speaker = new TextToSpeech (context, this);

			} else {
				var d = new Dictionary<string, string> ();

				speaker.SetSpeechRate (speakSpeed);
				speaker.Speak (tosay, QueueMode.Flush, d);
			}
		}
        public bool Speak(string text)
        {
            toSpeak = text;
            var ctx = Forms.Context;
            if (speaker == null)
            {
                speaker = new TextToSpeech(ctx, this);
            }
            else
            {
                var p = new Dictionary<string, string>();
                speaker.Speak(toSpeak, QueueMode.Flush, p);
            }

            return true;
        }
		public void Speak (string text)
		{
			var c = Forms.Context; 
			toSpeak = text;
			if (speaker == null) {
				speaker = new TextToSpeech (c, this);
				var languageIso = "en_GB";
				var locale = new Java.Util.Locale(languageIso);// languageIso is locale string
				speaker.SetLanguage (locale);
			}
			else
			{
				var p = new Dictionary<string,string> ();
				speaker.Speak (toSpeak, QueueMode.Flush, p);
			}
        }
Beispiel #31
0
        public void Speak(string text)
        {
            var ctx = Forms.Context; // useful for many Android SDK features

            toSpeak = text;
            if (speaker == null)
            {
                speaker = new Android.Speech.Tts.TextToSpeech(ctx, this);
            }
            else
            {
                var p = new Dictionary <string, string>();
                speaker.Speak(toSpeak, QueueMode.Flush, p);
                Debug.WriteLine("tts android: speak=" + toSpeak);
            }
        }
        /// <summary>
        ///     The speak.
        /// </summary>
        /// <param name="text">
        ///     The text.
        /// </param>
        public void Speak (string text, string language = DefaultLocale)
        {
            _toSpeak = text;
            if (_speaker == null)
            {
                _speaker = new TextToSpeech(Context, this);

                var lang = GetInstalledLanguages().Where(c => c == language).DefaultIfEmpty(DefaultLocale).First();
                var locale = new Locale (lang);
                _speaker.SetLanguage (locale);
            }
            else
            {
                var p = new Dictionary<string, string>();
                _speaker.Speak(_toSpeak, QueueMode.Flush, p);
            }
        }
        protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			
			View titleView = Window.FindViewById(Android.Resource.Id.Title);
			if (titleView != null) {
			  IViewParent parent = titleView.Parent;
			  if (parent != null && (parent is View)) {
			    View parentView = (View)parent;
			    parentView.SetBackgroundColor(Color.Rgb(0x26, 0x75 ,0xFF)); //38, 117 ,255
			  }
			}

			int taskID = Intent.GetIntExtra("TaskID", 0);
			if(taskID > 0) {
                task = TaskyApp.Current.TaskMgr.GetTask(taskID);
            }

            #region Inicia Layout
            // Seta o layout para a tela inicial
			SetContentView(Resource.Layout.TaskDetails);
			nameTextEdit = FindViewById<EditText>(Resource.Id.txtName);
			notesTextEdit = FindViewById<EditText>(Resource.Id.txtNotes);
			saveButton = FindViewById<Button>(Resource.Id.btnSave);
			doneCheckbox = FindViewById<CheckBox>(Resource.Id.chkDone);
			cancelDeleteButton = FindViewById<Button>(Resource.Id.btnCancelDelete);
			speakButton = FindViewById<Button> (Resource.Id.btnSpeak);
            #endregion

            // set the cancel delete based on whether or not it's an existing task
			cancelDeleteButton.Text = (task.ID == 0 ? "Cancel" : "Delete");
			// nome
			nameTextEdit.Text = task.Name; 
			// comentarios
			notesTextEdit.Text = task.Notes; 
			// done
			doneCheckbox.Checked = task.Done; 

			//clicks de botao 
			cancelDeleteButton.Click += (sender, e) => { CancelDelete(); };
			saveButton.Click += (sender, e) => { Save(); };
			speakButton.Click += (sender, e) => {
				Speak(nameTextEdit.Text + ". " + notesTextEdit.Text);
			};
			speaker = new TextToSpeech (this, this);
		}
		/// <summary>
		/// The speak.
		/// </summary>
		/// <param name="text">The text.</param>
		/// <param name="language">The language.</param>
		public void Speak (string text, string language = DefaultLocale)
        {
            _toSpeak = text;
            if (_speaker == null)
            {
                _speaker = new TextToSpeech(Context, this);

                var lang = GetInstalledLanguages().Where(c => c == language).DefaultIfEmpty(DefaultLocale).First();
                var locale = new Locale (lang);
                _speaker.SetLanguage (locale);
            }
            else
            {
                var p = new Dictionary<string, string>();

#pragma warning disable CS0618 // Type or member is obsolete
				_speaker.Speak(_toSpeak, QueueMode.Flush, p);
#pragma warning restore CS0618 // Type or member is obsolete
			}
        }
Beispiel #35
0
        public Task Init()
        {
            if (initialized)
            {
                return(Task.FromResult(true));
            }

            this.initTcs = new TaskCompletionSource <bool>();

            Console.WriteLine("Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);
            Android.Util.Log.Info("CrossTTS", "Current version: " + (int)global::Android.OS.Build.VERSION.SdkInt);
            textToSpeech = new Android.Speech.Tts.TextToSpeech(Application.Context, this);

            listener = new TtsProgressListener();
            textToSpeech.SetOnUtteranceProgressListener(listener);

            return(this.initTcs.Task);
            //bool hasThrown = false;
            //bool isValid = false;
            //while (!isValid)
            //{
            //    try
            //    {
            //        textToSpeech.Speak("Initializing", QueueMode.Add, null, null);
            //        isValid = true;
            //    }
            //    catch (Exception e)
            //    {
            //        if (!hasThrown)
            //        {
            //            hasThrown = true;
            //            Android.Util.Log.Debug("TTS", "(At least one) failure to initialize TTS.");
            //        }
            //    }
            //}
            //return Task.CompletedTask;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.myButton);
            
			button.Click += (object sender, EventArgs e) => 
			{
				Button btn = (Button)sender;
				toSpeak = btn.Text;
				if (speaker == null) {
					speaker = new Android.Speech.Tts.TextToSpeech (this, this);
				} else {
					var p = new Dictionary<string,string> ();
					speaker.Speak (toSpeak, QueueMode.Flush, p);
					System.Diagnostics.Debug.WriteLine ("spoke " + toSpeak);
				}
            };
        }
Beispiel #37
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _audioTmp = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/audioTmp.3gpp";

            var btnSpeak = FindViewById<Button>(Resource.Id.btnSpeak);
            btnSpeak.Click += OnSpeakClick;

            _btnRecord = FindViewById<Button>(Resource.Id.btnRecord);
            _btnRecord.Touch += OnRecordTouch;

            _btnPlay = FindViewById<Button>(Resource.Id.btnPlay);
            _btnPlay.Enabled = false;
            _btnPlay.Click += OnPlayClick;

            _editText = FindViewById<EditText>(Resource.Id.wordTextInput);
            var ttsInit = new TTSInit();
            _tts = new TextToSpeech(this, ttsInit);
            ttsInit.TTS = _tts;
        }
		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);
			};
		}
 void IDisposable.Dispose()
 {
     if (textToSpeech != null)
     {
         textToSpeech.Stop();
         textToSpeech.Dispose();
         textToSpeech = null;
     }
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 public TextToSpeech()
 {
     textToSpeech = new Android.Speech.Tts.TextToSpeech(Application.Context, this);
 }
Beispiel #41
0
        public override void OnDestroy()
        {
            _speech.Shutdown();
            _speech = null;
            _orientationManager = null;
            _landmarks = null;

            base.OnDestroy();
        }