예제 #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");
         }
     }
 }
        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);
        }
예제 #3
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);
            }
        }
예제 #4
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();
            });
        }
예제 #5
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);
                }
            };
        }
예제 #6
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);
                }
            };
        }
예제 #7
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;
        }
예제 #8
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);
 }
예제 #9
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);
        }
예제 #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 SpeechManagerBak(Context context, bool _isPlayActionVoice = true)
        {
            this.mContext      = context;                               //获取上下文
            this.mTextToSpeech = new TextToSpeech(this.mContext, this); //实例化TTS
            mTextToSpeech.SetPitch(0.5f);                               // 
            ///TODO:没有刹车音频文件是会报错的,所以这个是需要注意的
            InitSpeechPlayTimer();
            //是否播报操作语音
            IsPlayActionVoice = Singleton.PlayActionVoice;

            InitMedia(Singleton.dbName);
        }
 public void Speak(string text)
 {
     toSpeak = text;
     if (speaker == null)
     {
         speaker = new TextToSpeech(MainActivity.Instance, this);
         speaker.SetLanguage(new Java.Util.Locale("vi-VN"));
         speaker.SetPitch(0.5f);
         speaker.SetSpeechRate(1);
     }
     else
     {
         speaker.Speak(toSpeak, QueueMode.Flush, null, null);
     }
 }
예제 #13
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);
     }
 }
예제 #14
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);
 }
예제 #15
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);
     }
 }
예제 #16
0
 public SpeechManager(Context context, bool IsPlayActionVoice = true)
 {
     this.mContext      = context;                               //获取上下文
     this.mTextToSpeech = new TextToSpeech(this.mContext, this); //实例化TTS
     mTextToSpeech.SetPitch(0.5f);                               // 
     ///InitSpeechPlay();
     ///InitSpeechPlay();
     ///InitSpeechPlay();
     ///TODO:没有刹车音频文件是会报错的,所以这个是需要注意的
     InitSpeechPlayTimer();
     BreakePath = Android.OS.Environment.ExternalStorageDirectory + "/" + "brake.wav";
     player     = new MediaPlayer();
     Java.IO.File file = new Java.IO.File(BreakePath);
     if (file.Exists())
     {
         fis = new Java.IO.FileInputStream(file);
     }
 }
        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);
        }
예제 #19
0
        private async void Signupbtn_Click(object sender, EventArgs e)
        {
            string             nametext, mobiletext, emailtext, passtext, cnfpasstext;
            InputMethodManager inputManager = (InputMethodManager)GetSystemService(InputMethodService);

            inputManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0);
            nametext    = name.Text;
            mobiletext  = mobile.Text;
            emailtext   = email.Text;
            passtext    = password.Text;
            cnfpasstext = conpass.Text;
            if (!checkEmpty(nametext, "Name"))
            {
                return;
            }
            else if (!checkEmpty(mobiletext, "Phone number"))
            {
                return;
            }
            else if (!checkEmpty(emailtext, "Email"))
            {
                return;
            }
            else if (!checkEmpty(passtext, "Password"))
            {
                return;
            }
            else if (!checkEmpty(cnfpasstext, "Confirm Password"))
            {
                return;
            }
            else
            {
                if (isNameVaid(nametext) && isMobileValid(mobiletext) && isEmailValid(emailtext) && areTermsAccepted() && isPassValid(passtext) && checkPassValidity(passtext, cnfpasstext))
                {
                    mLoadingDialog.Show();
                    CabsAPI        api      = new CabsAPI();
                    SignupResponse response = await api.RegisterUser(nametext, emailtext, mobiletext, passtext);

                    if (response.Code == Utils.ResponseCode.SUCCESS)
                    {
                        mLoadingDialog.Dismiss();
                        mEditor.PutString("email", emailtext);
                        mEditor.PutString("mobile", mobiletext);
                        mEditor.PutString("name", nametext);
                        mEditor.PutString("token", response.Token);
                        mEditor.PutBoolean("isLoggedIn", true);
                        mEditor.Apply();
                        mTextToSpeech = 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
                        mTextToSpeech.SetLanguage(lang);
                        mTextToSpeech.SetPitch(1f);
                        mTextToSpeech.SetSpeechRate(1f);
                        mContext = signupbtn.Context;
                        mTextToSpeech.Speak(mSucLog, QueueMode.Flush, null, null);
                        StartActivity(new Intent(this, typeof(NavigationActivity)));

                        Finish();
                    }
                    else if (response.Code == Utils.ResponseCode.MYSQL_DUPLICATES)
                    {
                        mLoadingDialog.Dismiss();
                        Toast.MakeText(this, "User with same number is already present", ToastLength.Short).Show();
                        mobile.Text = "";
                    }
                    else
                    {
                        mLoadingDialog.Dismiss();
                        Toast.MakeText(this, "Server Error Try Again!", ToastLength.Short).Show();
                    }
                }
            }
        }
예제 #20
0
        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);
                }
            };
        }
예제 #21
0
 public void ChangePitch()
 {
     tts.SetPitch(0.6f);
 }
        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);
            };
        }
예제 #23
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);
        }
예제 #24
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

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

            AdView mAdView = FindViewById<AdView>(Resource.Id.adView1);
            var adRequest = new AdRequest.Builder().Build();
            // Start loading the ad.
            mAdView.LoadAd(adRequest);


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



             a = FindViewById<Button>(Resource.Id.a);
            b = FindViewById<Button>(Resource.Id.b);
            c = FindViewById<Button>(Resource.Id.c);
            d = FindViewById<Button>(Resource.Id.d);
            e = FindViewById<Button>(Resource.Id.e);
            f = FindViewById<Button>(Resource.Id.f);
            g = FindViewById<Button>(Resource.Id.g);
            h = FindViewById<Button>(Resource.Id.h);
            i = FindViewById<Button>(Resource.Id.i);
            j = FindViewById<Button>(Resource.Id.j);
            k = FindViewById<Button>(Resource.Id.k);
            l = FindViewById<Button>(Resource.Id.l);
            m = FindViewById<Button>(Resource.Id.m);
            n = FindViewById<Button>(Resource.Id.n);
            o = FindViewById<Button>(Resource.Id.o);
            p = FindViewById<Button>(Resource.Id.p);
            u = FindViewById<Button>(Resource.Id.u);
            q = FindViewById<Button>(Resource.Id.q);
            r = FindViewById<Button>(Resource.Id.r);
            s = FindViewById<Button>(Resource.Id.s);
            w = FindViewById<Button>(Resource.Id.w);
            v = FindViewById<Button>(Resource.Id.v);
            x = FindViewById<Button>(Resource.Id.x);
            y = FindViewById<Button>(Resource.Id.y);
            z = FindViewById<Button>(Resource.Id.z);
            one = FindViewById<Button>(Resource.Id.one);
            two = FindViewById<Button>(Resource.Id.two);
            three = FindViewById<Button>(Resource.Id.three);
            four = FindViewById<Button>(Resource.Id.four);
            five = FindViewById<Button>(Resource.Id.five);
            six = FindViewById<Button>(Resource.Id.six);
            seven = FindViewById<Button>(Resource.Id.seven);
            eight = FindViewById<Button>(Resource.Id.eight);
            nine = FindViewById<Button>(Resource.Id.nine);
            ten = FindViewById<Button>(Resource.Id.ten);
            t = FindViewById<Button>(Resource.Id.t);
            
            a.Click +=  A_Click;
            b.Click += B_Click;
            c.Click += C_Click;
            d.Click += D_Click;
            e.Click += E_Click;
            f.Click += F_Click;
            g.Click += G_Click;
            h.Click += H_Click;
            i.Click += I_Click;
            k.Click += K_Click;

            w.Click += w_Click;
            k.Click += K_Click;
            l.Click += L_Click;
            m.Click += M_Click;
            n.Click += N_Click;
            o.Click += O_Click;
            j.Click += J_Click;
            t.Click += T_Click;
            q.Click += Q_Click;
            p.Click += P_Click;
            r.Click += R_Click;
            s.Click += S_Click;
            u.Click += U_Click;
            v.Click += V_Click;
            x.Click += X_Click;

            z.Click += Z_Click;
            one.Click += One_Click;
            two.Click += Two_Click;
            three.Click += Three_Click;
            four.Click += Four_Click;
            five.Click += Five_Click;
            six.Click += Six_Click;
            seven.Click += Seven_Click;
            eight.Click += Eight_Click;
            nine.Click += Nine_Click;
            ten.Click += Ten_Click;
            y.Click += y_Click;






        }
예제 #25
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);
                }
            };
        }
예제 #26
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);
        }
예제 #27
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();
                }
            };
        }
예제 #28
0
 void setSpeechPitch(float speechPitch)
 {
     textToSpeech.SetPitch(speechPitch);
     currentSpeechPitch = speechPitch;
 }
예제 #29
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();
            }
        }
 public void SetPitch(float pitch)
 {
     _textToSpeech.SetPitch(pitch);
 }