예제 #1
0
 public void Speak(string text, float speed, float pitch, Button btn, string msg)
 {
     if (!string.IsNullOrWhiteSpace(text))
     {
         _Speed  = speed;
         _Pitch  = pitch;
         _btn    = btn;
         _msg    = msg;
         toSpeak = text;
         if (speaker == null)
         {
             speaker = new TextToSpeech(MainActivity.Instance, this);
         }
         else
         {
             if (speaker.IsSpeaking)
             {
                 speaker.Stop();
             }
             //每次传进来的按钮可能不一样
             //speaker.SetOnUtteranceProgressListener(new ttsUtteranceListener(_btn, _msg));
             //speaker.SetOnUtteranceCompletedListener(this);
             //speaker.SetLanguage(Java.Util.Locale.Us);//设置语言
             speaker.SetPitch(_Pitch);      //音高
             speaker.SetSpeechRate(_Speed); //设置的语速
             speaker.Speak(toSpeak, QueueMode.Flush, null, "UniqueID");
         }
     }
 }
예제 #2
0
        /// <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 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);
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.speak);
            var btnSayIt      = FindViewById <Button>(Resource.Id.btnSpeak);
            var editWhatToSay = FindViewById <EditText>(Resource.Id.editSpeech);

            context = btnSayIt.Context;


            textToSpeech = new TextToSpeech(this, null, "com.google.android.tts");


            lang = Java.Util.Locale.Default;
            textToSpeech.SetLanguage(lang);

            // set the speed and pitch
            textToSpeech.SetPitch(1.00f);
            textToSpeech.SetSpeechRate(.8f);

            // 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);
                }
            };
        }
예제 #6
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            spokenHistoryListArray = Intent.GetStringArrayExtra("history_list");
            List <string> spokenHistoryList = spokenHistoryListArray.ToList();

            // Create your application here
            SetContentView(Resource.Layout.History);

            spokenHistoryListView = FindViewById <ListView>(Resource.Id.myListView);
            HistoryListViewAdapter adapter = new HistoryListViewAdapter(this, spokenHistoryList);

            spokenHistoryListView.Adapter = adapter;

            context      = spokenHistoryListView.Context;
            textToSpeech = new TextToSpeech(this, this, "com.google.android.tts");

            lang = Java.Util.Locale.Default;
            textToSpeech.SetLanguage(lang);
            textToSpeech.SetPitch(.80f);
            textToSpeech.SetSpeechRate(1f);


            spokenHistoryListView.ItemClick += SpokenHistoryListView_ItemClick;
        }
예제 #7
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            // Get our button from the layout reference,
            // and attach an event to it
            Button button   = FindViewById <Button>(Resource.Id.button1);
            var    textEdit = FindViewById <EditText>(Resource.Id.editText1);

            _textToSpeech = new TextToSpeech(this, this, "com.google.androd.tts");
            _lang         = Locale.Default;

            _textToSpeech.SetPitch(.5f);
            _textToSpeech.SetSpeechRate(.8f);



            button.Click += delegate
            {
                if (!string.IsNullOrEmpty(textEdit.Text))
                {
                    _textToSpeech.Speak(textEdit.Text, QueueMode.Flush, null);
                }
            };
        }
예제 #8
0
        public void Start()
        {
            this.lastUtteranceID = Guid.NewGuid();
            speechEngine.SetOnUtteranceProgressListener(this);

            for (int i = 0; i < numRepeats - 1; i++)
            {
                // Increase the pitch for a comical result
                speechEngine.SetPitch(INITIAL_PITCH + i * PITCH_INCREASE);
                speechEngine.SetSpeechRate(INITIAL_SPEACH_RATE + i * SPEACH_RATE_INCREASE);
                sayThePhrase(Guid.NewGuid());
            }

            speechEngine.SetPitch(INITIAL_PITCH);
            speechEngine.SetSpeechRate(INITIAL_SPEACH_RATE);
            sayThePhrase(lastUtteranceID);
        }
예제 #9
0
 protected override void OnCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     textToSpeech = new TextToSpeech(this, this, "com.google.android.tts");
     textToSpeech.SetLanguage(Java.Util.Locale.Default);
     textToSpeech.SetPitch(1f);
     textToSpeech.SetSpeechRate(1f);
 }
예제 #10
0
 public void OnInit([GeneratedEnum] OperationResult status)
 {
     if (status == OperationResult.Success)
     {
         tts.SetPitch(1f);
         tts.SetSpeechRate(1f);
         tts.Speak("Hello Luke!", QueueMode.Flush, null);
     }
 }
예제 #11
0
        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);
            }
        }
예제 #12
0
        public static void PlayTTS(Context context, string text, float rate, bool queueflush)
        {
            TextToSpeech tts = new TextToSpeech(context, null, "com.google.android.tts");

            tts.SetSpeechRate(rate);
            tts.SetLanguage(Locale.Default);
            QueueMode mode = queueflush ? QueueMode.Flush : QueueMode.Add;

            tts.Speak(text, mode, null, null);
        }
예제 #13
0
 public void Speak(string text)
 {
     lock (lockObject)
     {
         if (speaker == null)
         {
             speaker = new TextToSpeech(Forms.Context, this);
             var voices = speaker.Voices;
             speaker.SetSpeechRate(1.5f);
         }
         speaker.Speak(text, QueueMode.Add, null, null);
     }
 }
예제 #14
0
 public async Task SpeakAsync(string text)
 {
     toSpeak = text;
     if (speaker == null)
     {
         speaker = new TextToSpeech(MainActivity.Instance, this);
         speaker.SetSpeechRate(0.75f);
     }
     else
     {
         speaker.Speak(toSpeak, QueueMode.Flush, null, null);
     }
 }
예제 #15
0
 public void Speak(string text, string language)
 {
     toSpeak = text;
     if (speaker == null)
     {
         speaker = new TextToSpeech(MainActivity.Instance, this);
     }
     else
     {
         speaker.SetLanguage(new Java.Util.Locale(language));
         speaker.SetSpeechRate(0.8f);
         speaker.Speak(toSpeak, QueueMode.Flush, null, null);
     }
 }
 public void PlayAudio(string text)
 {
     _textToSpeak = text;
     if (_speaker == null)
     {
         _speaker = new TextToSpeech(Android.App.Application.Context, this);
         _speaker.SetSpeechRate(1.0f);
         _speaker.SetOnUtteranceProgressListener(this);
     }
     else
     {
         _speaker.Speak(_textToSpeak, QueueMode.Flush, null, "MajaUtteranceId");
     }
 }
예제 #17
0
        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();
                }
            }
        }
예제 #18
0
 //String hello = "String";
 protected override void OnCreate(Bundle savedInstanceState)
 //void speak(string hello,Context con)
 //sending context and string from other activity/frame
 {
     base.OnCreate(savedInstanceState);
     //creating a texttospeech instance for voice commands
     textToSpeech = new TextToSpeech(this, this, "com.google.android.tts");
     //  new TextToSpeech(con, this, "com.google.android.tts");
     lang = Java.Util.Locale.Default;
     //setting language , pitch and speed rate to the voice
     textToSpeech.SetLanguage(lang);
     textToSpeech.SetPitch(1f);
     textToSpeech.SetSpeechRate(1f);
     //Speak the string sent to function
     textToSpeech.Speak("string to speak", QueueMode.Flush, null, null);
 }
예제 #19
0
 public void Speak(string text)
 {
     toSpeak = text;
     if (speaker == null)
     {
         speaker = new TextToSpeech(this, this);
         speaker.SetPitch(1.5f);
         speaker.SetSpeechRate(1.5f);
         speaker.SetLanguage(Java.Util.Locale.English);
     }
     else
     {
         var p = new Dictionary <string, string>();
         speaker.Speak(toSpeak, QueueMode.Flush, p);
     }
 }
예제 #20
0
 public void Speak(string text)
 {
     toSpeak = $"Helooo, this is tech support speaking, let me answer your question: {text}";
     if (speaker == null)
     {
         speaker = new TextToSpeech(this, this);
         speaker.SetPitch(1.5f);
         speaker.SetSpeechRate(2.0f);
         speaker.SetLanguage(Java.Util.Locale.English);
     }
     else
     {
         var p = new Dictionary <string, string>();
         speaker.Speak(toSpeak, QueueMode.Flush, p);
     }
 }
        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;
                }
            }
        }
        public AppController(Context context, Activity activity, TextToSpeech.IOnInitListener initListener, UtteranceProgressListenerWrapper listenerWrapper)
        {
            _context  = context;
            _activity = activity;

            OutputFile = new OutputFileModel(_context.GetText(Resource.String.save_dir));

            SetDefaultLocale();

            // set up the TextToSpeech object
            // third parameter is the speech engine to use
            _textToSpeech = new TextToSpeech(context, initListener, "com.google.android.tts");

            // set up the speech to use the default langauge
            // if a language is not available, then the default language is used.
            _textToSpeech.SetLanguage(SelectedLocale);

            // set the speed and pitch
            _textToSpeech.SetPitch(1f);
            _textToSpeech.SetSpeechRate(1f);

            _textToSpeech.SetOnUtteranceProgressListener(listenerWrapper);
        }
예제 #23
0
        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);
                }
            }
        }
        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);
            };
        }
예제 #25
0
파일: work.cs 프로젝트: mosageneral/learn
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.work);
            AdView mAdView   = FindViewById <AdView>(Resource.Id.adView1);
            var    adRequest = new AdRequest.Builder().Build();

            // Start loading the ad.
            mAdView.LoadAd(adRequest);
            b1         = FindViewById <Button>(Resource.Id.b1);
            b2         = FindViewById <Button>(Resource.Id.b2);
            b3         = FindViewById <Button>(Resource.Id.b3);
            b4         = FindViewById <Button>(Resource.Id.b4);
            b5         = FindViewById <Button>(Resource.Id.b5);
            b6         = FindViewById <Button>(Resource.Id.b6);
            b7         = FindViewById <Button>(Resource.Id.b7);
            b8         = FindViewById <Button>(Resource.Id.b8);
            b9         = FindViewById <Button>(Resource.Id.b9);
            b10        = FindViewById <Button>(Resource.Id.b10);
            b11        = FindViewById <Button>(Resource.Id.b11);
            b12        = FindViewById <Button>(Resource.Id.b12);
            b13        = FindViewById <Button>(Resource.Id.b13);
            b14        = FindViewById <Button>(Resource.Id.b14);
            b15        = FindViewById <Button>(Resource.Id.b15);
            b16        = FindViewById <Button>(Resource.Id.b16);
            b17        = FindViewById <Button>(Resource.Id.b17);
            b18        = FindViewById <Button>(Resource.Id.b18);
            b19        = FindViewById <Button>(Resource.Id.b19);
            b20        = FindViewById <Button>(Resource.Id.b20);
            b21        = FindViewById <Button>(Resource.Id.b21);
            b22        = FindViewById <Button>(Resource.Id.b22);
            b23        = FindViewById <Button>(Resource.Id.b23);
            b24        = FindViewById <Button>(Resource.Id.b24);
            b25        = FindViewById <Button>(Resource.Id.b25);
            b26        = FindViewById <Button>(Resource.Id.b26);
            b27        = FindViewById <Button>(Resource.Id.b27);
            b28        = FindViewById <Button>(Resource.Id.b28);
            b29        = FindViewById <Button>(Resource.Id.b29);
            b30        = FindViewById <Button>(Resource.Id.b30);
            b31        = FindViewById <Button>(Resource.Id.b31);
            b32        = FindViewById <Button>(Resource.Id.b32);
            b33        = FindViewById <Button>(Resource.Id.b33);
            b34        = FindViewById <Button>(Resource.Id.b34);
            b35        = FindViewById <Button>(Resource.Id.b35);
            b36        = FindViewById <Button>(Resource.Id.b36);
            b37        = FindViewById <Button>(Resource.Id.b37);
            b38        = FindViewById <Button>(Resource.Id.b38);
            b39        = FindViewById <Button>(Resource.Id.b39);
            b40        = FindViewById <Button>(Resource.Id.b40);
            b41        = FindViewById <Button>(Resource.Id.b41);
            b42        = FindViewById <Button>(Resource.Id.b42);
            b43        = FindViewById <Button>(Resource.Id.b43);
            b44        = FindViewById <Button>(Resource.Id.b44);
            b45        = FindViewById <Button>(Resource.Id.b45);
            b46        = FindViewById <Button>(Resource.Id.b46);
            b47        = FindViewById <Button>(Resource.Id.b47);
            b48        = FindViewById <Button>(Resource.Id.b48);
            b49        = FindViewById <Button>(Resource.Id.b49);
            b50        = FindViewById <Button>(Resource.Id.b50);
            b1.Click  += B1_Click;
            b2.Click  += B2_Click;
            b3.Click  += B3_Click;
            b4.Click  += B4_Click;
            b5.Click  += B5_Click;
            b6.Click  += B6_Click;
            b7.Click  += B7_Click;
            b8.Click  += B8_Click;
            b9.Click  += B9_Click;
            b10.Click += B10_Click;
            b11.Click += B11_Click;
            b12.Click += B12_Click;
            b13.Click += B13_Click;
            b14.Click += B14_Click;
            b15.Click += B15_Click;
            b16.Click += B16_Click;
            b17.Click += B17_Click;
            b18.Click += B18_Click;
            b19.Click += B19_Click;
            b20.Click += B20_Click;
            b21.Click += B21_Click;
            b22.Click += B22_Click;
            b23.Click += B23_Click;
            b24.Click += B24_Click;
            b25.Click += B25_Click;
            b26.Click += B26_Click;
            b27.Click += B27_Click;
            b28.Click += B28_Click;
            b29.Click += B29_Click;
            b30.Click += B30_Click;
            b31.Click += B31_Click;
            b32.Click += B32_Click;
            b33.Click += B33_Click;
            b34.Click += B34_Click;
            b35.Click += B35_Click;
            b36.Click += B36_Click;
            b37.Click += B37_Click;
            b38.Click += B38_Click;
            b39.Click += B39_Click;
            b40.Click += B40_Click;
            b41.Click += B41_Click;
            b42.Click += B42_Click;
            b43.Click += B43_Click;
            b44.Click += B44_Click;
            b45.Click += B45_Click;
            b46.Click += B46_Click;
            b47.Click += B47_Click;
            b48.Click += B48_Click;
            b49.Click += B49_Click;
            b50.Click += B50_Click;


            textToSpeech = new TextToSpeech(this, null, "com.google.android.tts");


            lang = Java.Util.Locale.Default;
            textToSpeech.SetLanguage(lang);

            // set the speed and pitch
            textToSpeech.SetPitch(1.00f);
            textToSpeech.SetSpeechRate(.8f);
        }
예제 #26
0
파일: Words.cs 프로젝트: OculusMalus/myvox
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            String[]      spokenHistoryListArray = Intent.GetStringArrayExtra("history_list");
            List <string> spokenHistoryList      = spokenHistoryListArray.ToList();

            SetContentView(Resource.Layout.words);

            var editText = FindViewById <EditText>(Resource.Id.editText);
            var I        = FindViewById <Button>(Resource.Id.I);
            var you      = FindViewById <Button>(Resource.Id.you);
            var they     = FindViewById <Button>(Resource.Id.they);
            var feel     = FindViewById <Button>(Resource.Id.feel);
            var happy    = FindViewById <Button>(Resource.Id.happy);
            var angry    = FindViewById <Button>(Resource.Id.angry);
            var come     = FindViewById <Button>(Resource.Id.come);
            var give     = FindViewById <Button>(Resource.Id.give);
            var go       = FindViewById <Button>(Resource.Id.go);
            var speak    = FindViewById <Button>(Resource.Id.speak);
            var please   = FindViewById <Button>(Resource.Id.please);
            var help     = FindViewById <Button>(Resource.Id.help);
            var home     = FindViewById <Button>(Resource.Id.home);


            context = speak.Context;

            textToSpeech = new TextToSpeech(this, this, "com.google.android.tts");

            lang = Java.Util.Locale.Default;
            textToSpeech.SetLanguage(lang);
            textToSpeech.SetPitch(.80f);
            textToSpeech.SetSpeechRate(1f);

            speak.Click += delegate
            {
                // if there is nothing to say, don't say it
                if (!string.IsNullOrEmpty(editText.Text))
                {
                    textToSpeech.Speak(editText.Text, QueueMode.Flush, null, null);
                }
                //add phrase to list of spoken phrases
                spokenHistoryList.Add(editText.Text);
                //empty editText string
                editText.Text = "";
            };



            Button history = FindViewById <Button>(Resource.Id.history);

            history.Click += delegate
            {
                String[] phraseHistoryArray = spokenHistoryList.ToArray();
                Intent   intent             = new Intent(this, typeof(HistoryActivity));
                intent.PutExtra("history_list", phraseHistoryArray);
                this.StartActivity(intent);
            };


            Button phrases = FindViewById <Button>(Resource.Id.phrases);

            phrases.Click += delegate
            {
                String[] phraseHistoryArray = spokenHistoryList.ToArray();
                Intent   intent             = new Intent(this, typeof(MainActivity));
                intent.PutExtra("history_list", phraseHistoryArray);
                this.StartActivity(intent);
            };

            Button custom = FindViewById <Button>(Resource.Id.custom);

            custom.Click += delegate
            {
                String[] phraseHistoryArray = spokenHistoryList.ToArray();
                Intent   intent             = new Intent(this, typeof(CameraActivity));
                intent.PutExtra("history_list", phraseHistoryArray);
                this.StartActivity(intent);
            };

            please.Click += delegate
            {
                if (!string.IsNullOrEmpty(please.Text))
                {
                    editText.Append(please.Text);
                }
            };

            help.Click += delegate
            {
                if (!string.IsNullOrEmpty(help.Text))
                {
                    editText.Append(help.Text);
                }
            };

            home.Click += delegate
            {
                if (!string.IsNullOrEmpty(home.Text))
                {
                    editText.Append(home.Text);
                }
            };

            I.Click += delegate
            {
                if (!string.IsNullOrEmpty(I.Text))
                {
                    editText.Append(I.Text);
                }
            };


            you.Click += delegate
            {
                if (!string.IsNullOrEmpty(you.Text))
                {
                    editText.Append(you.Text);
                }
            };

            they.Click += delegate
            {
                if (!string.IsNullOrEmpty(they.Text))
                {
                    editText.Append(they.Text);
                }
            };

            feel.Click += delegate
            {
                if (!string.IsNullOrEmpty(feel.Text))
                {
                    editText.Append(feel.Text);
                }
            };

            happy.Click += delegate
            {
                if (!string.IsNullOrEmpty(happy.Text))
                {
                    editText.Append(happy.Text);
                }
            };

            angry.Click += delegate
            {
                if (!string.IsNullOrEmpty(angry.Text))
                {
                    editText.Append(angry.Text);
                }
            };

            come.Click += delegate
            {
                if (!string.IsNullOrEmpty(come.Text))
                {
                    editText.Append(come.Text);
                }
            };


            give.Click += delegate
            {
                if (!string.IsNullOrEmpty(give.Text))
                {
                    editText.Append(give.Text);
                }
            };

            go.Click += delegate
            {
                if (!string.IsNullOrEmpty(go.Text))
                {
                    editText.Append(go.Text);
                }
            };
        }
예제 #27
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            SetContentView(Resource.Layout.Main);


            //Status bar
            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
            }

            SupportToolbar toolBar = FindViewById <SupportToolbar>(Resource.Id.my_toolbar);

            SetSupportActionBar(toolBar);
            SupportActionBar ab = SupportActionBar;

            ab.SetHomeAsUpIndicator(Resource.Drawable.ic_menu1);
            ab.SetDisplayHomeAsUpEnabled(true);

            CollapsingToolbarLayout collapsingToolbar =
                (CollapsingToolbarLayout)FindViewById(Resource.Id.collapsing_toolbar);

            collapsingToolbar.Title = "Pronounce";


            //History
            var listView = FindViewById <ListView>(Resource.Id.listView1);

            editText         = FindViewById <EditText>(Resource.Id.editText1);
            items            = new List <string>(new[] { "History" });
            adapter          = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, items);
            listView.Adapter = adapter;
            FindViewById <Button>(Resource.Id.MyButton).Click += HandleClick;

            listView.ItemClick += delegate(object sender, AdapterView.ItemClickEventArgs args)
            {
                editText.Text = ((TextView)args.View).Text;
            };


            //Drawer
            mDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            if (navigationView != null)
            {
                SetUpDrawerContent(navigationView);
            }

            // Volume bar setup
            mgr = (AudioManager)GetSystemService(Context.AudioService);

            ////
            _seekBarAlarm = FindViewById <SeekBar>(Resource.Id.seekBar1);

            // modify the ring
            initBar(_seekBarAlarm, Android.Media.Stream.Music);

            /// <summary>
            /// initBar
            /// </summary>
            /// <param name="bar"></param>
            /// <param name="stream"></param>
            ///


            //tts
            tts = new TextToSpeech(this.ApplicationContext, this);
            tts.SetLanguage(Java.Util.Locale.Default);

            Button dbutton      = FindViewById <Button>(Resource.Id.MyButton);
            Button clear_button = FindViewById <Button>(Resource.Id.button1);

            editText = FindViewById <EditText>(Resource.Id.editText1);


            //Pitch and Speed
            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 = 255;
            txtSpeedVal.Text   = "1";
            txtPitchVal.Text   = "1";

            // set the speed and pitch
            tts.SetPitch(1.0f);
            tts.SetSpeechRate(1.0f);

            // sliders
            seekPitch.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) =>
            {
                var seek     = sender as SeekBar;
                var progress = seek.Progress / 255f;
                tts.SetPitch(progress);
                txtPitchVal.Text = progress.ToString("F2");
            };
            seekSpeed.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) =>
            {
                var seek     = sender as SeekBar;
                var progress = seek.Progress / 255f;
                tts.SetSpeechRate(progress);
                txtSpeedVal.Text = progress.ToString("F2");
            };



            //Bottom sheet

            LinearLayout        sheet = FindViewById <LinearLayout>(Resource.Id.bottom_sheet);
            BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.From(sheet);

            var metrics    = Resources.DisplayMetrics;
            var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);

            if (heightInDp <= 731)
            {
                // it's a phone
                bottomSheetBehavior.PeekHeight = 120;
            }
            else
            {
                // it's a tablet
                bottomSheetBehavior.PeekHeight = 360;
            }

            bottomSheetBehavior.Hideable = false;

            bottomSheetBehavior.SetBottomSheetCallback(new MyBottomSheetCallBack());


            //Speak button
            dbutton.Click += Button_Click;


            //Clear button
            clear_button.Click += delegate
            {
                if (!string.IsNullOrEmpty(editText.Text))
                {
                    editText.Text = "";
                }
            };

            //Clear history button
            Button clear_history = FindViewById <Button>(Resource.Id.button3);

            clear_history.Click += delegate
            {
                adapter.Clear();
                adapter.NotifyDataSetChanged();
            };


            //setup navigation view
            _navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);
        }
예제 #28
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);

            // Get data from caller activity
            var json = Intent.GetStringExtra("CARDS") ?? "N/A";

            Log.Debug(TAG, "Data received: " + json);

            // Initialize and configure Text2speech engine
            tts = new TextToSpeech(this, this);
            var ttsEngines = tts.Engines;
            var ec         = ttsEngines.Count;

            Log.Debug(TAG, "Installed TTS engines: " + ec);
            foreach (var e in ttsEngines)
            {
                Log.Debug(TAG, "Engine name: " + e.Name);
                Log.Debug(TAG, "Engine label: " + e.Label);
            }

            if (ec > 0)
            {
                // configure TTS engine
                tts.SetPitch(1.0f);
                tts.SetSpeechRate(1.0f);
            }
            else
            {
                var ad = new AlertDialog.Builder(this);
                ad.SetTitle("Warning!");
                ad.SetMessage("No TextToSpeech engines detected." + System.Environment.NewLine + "Install a TTS engine and restart this application!");
                ad.SetPositiveButton("OK", (sender, e) => { });
                ad.Show();
            }

            // configure viewpager
            vpa   = new VPAdapter(this, json);
            pager = FindViewById <ViewPager>(Resource.Id.pager);
            pager.SetBackgroundResource(Resource.Drawable.PagerStyle);
            pager.Adapter = vpa;

            // configure PagerTabStrip
            var pts = pager.FindViewById <PagerTabStrip>(Resource.Id.pts);

            pts.SetBackgroundResource(Resource.Drawable.TabStripStyle);

            // get button and set click event handler
            var btnAddPic = FindViewById <Button>(Resource.Id.btnAddPic);

            btnAddPic.Click += (sender, e) =>
            {
                if (vpa.Count < maxImages)
                {
                    var i = new Intent();
                    i.SetType("image/*");
                    i.SetAction(Intent.ActionGetContent);
                    StartActivityForResult(Intent.CreateChooser(i, "Pick an image..."), RC);
                }
                else
                {
                    Toast.MakeText(this, "Maximum allowed images: " + maxImages, ToastLength.Short).Show();
                }
            };
        }
예제 #29
0
 void setSpeechRate(float speechRate)
 {
     textToSpeech.SetSpeechRate(speechRate);
     currentSpeechRate = speechRate;
 }
예제 #30
0
        ///////////////////////////////////////////////////////

        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();
            }
        }