예제 #1
0
 protected override void OnResume()
 {
     base.OnResume();
     key = true;
     if (ttslist.Count != 0)
     {
         Dictionary <string, string> param = new Dictionary <string, string> {
             { TextToSpeech.Engine.KeyParamUtteranceId, "1" }
         };
         tt.PlaySilence(10, QueueMode.Add, param);
     }
 }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.main);
            key = true;
            EditText        tb1     = FindViewById <EditText>(Resource.Id.text);
            SeekBar         ss      = FindViewById <SeekBar>(Resource.Id.speed);
            TextView        sst     = FindViewById <TextView>(Resource.Id.textSpeed);
            SeekBar         sp      = FindViewById <SeekBar>(Resource.Id.ton);
            TextView        spt     = FindViewById <TextView>(Resource.Id.textton);
            Button          button1 = FindViewById <Button>(Resource.Id.buttonread);
            ttsListFragment frag    = SupportFragmentManager.FindFragmentById(Resource.Id.tts_list_fragment) as ttsListFragment;

            ttslist     = new List <elemTts>();
            ss.Progress = sp.Progress = 127;
            sst.Text    = spt.Text = "0,5";
            context     = button1.Context;

            tt = new TextToSpeech(this, this);
            tt.SetPitch(1.25f);
            tt.SetSpeechRate(1f);
            sp.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) =>
            {
                var seek     = sender as SeekBar;
                var progress = seek.Progress / 255f;
                tt.SetPitch(seek.Progress / 170f + 0.5f);
                spt.Text = progress.ToString("F2");
            };
            ss.StopTrackingTouch += (object sender, SeekBar.StopTrackingTouchEventArgs e) =>
            {
                var seek     = sender as SeekBar;
                var progress = seek.Progress / 255f;
                tt.SetSpeechRate(seek.Progress / 255f + 0.1f);
                sst.Text = progress.ToString("F2");
            };
            button1.Click += delegate
            {
                try
                {
                    if (new Regex(@"[А-Яа-я]").Match(tb1.Text).Success)
                    {
                        tb1.FindFocus();
                        throw new Exception("возможно чтение только символов английского алфавита");
                    }

                    ttslist.Add(new elemTts(tb1.Text, ss.Progress / 255f + 0.1f, sp.Progress / 170f + 0.5f));
                    frag.OnResume();
                    if (ttslist.Count == 1)
                    {
                        Dictionary <string, string> param = new Dictionary <string, string> {
                            { TextToSpeech.Engine.KeyParamUtteranceId, "1" }
                        };
                        tt.PlaySilence(10, QueueMode.Add, param);
                    }
                }
                catch (Exception E)
                {
                    Toast.MakeText(this, E.Message, ToastLength.Short).Show();
                }
            };
            Button button2 = FindViewById <Button>(Resource.Id.buttonload);

            button2.Click += delegate
            {
                StartActivityForResult(new Intent(this, typeof(FilePickerActivity)), tkey);
            };
        }