예제 #1
0
        public async Task <TextToSpeech> GetTTS(Context context)
        {
            if (_textToSpeech != null)
            {
                try{
                    _textToSpeech.Stop();
                    _textToSpeech.Shutdown();
                    _textToSpeech = null;
                }
                catch
                {
                    Log.Info(TAG, "Error when GetTTS");
                }
            }
            _textToSpeech = await CreateTtsAsync(context, this, _config.GetTtsEngine());

            var locale = new Locale(_config.GetTtsLang());

            SetLang(locale);
            if (_textToSpeech != null)
            {
                _textToSpeech.SetOnUtteranceProgressListener(new UtteranceProgressLs(this));
                Log.Info(TAG, "Set callback for textToSpeech");
            }
            return(_textToSpeech);
        }
예제 #2
0
        public AndroidTextToSpeech(AndroidSensusService service)
        {
            _textToSpeech  = new TextToSpeech(service, this);
            _initWait      = new ManualResetEvent(false);
            _utteranceWait = new ManualResetEvent(false);
            _disposed      = false;

            _textToSpeech.SetOnUtteranceProgressListener(this);
        }
예제 #3
0
        public ShopLensTextToSpeech(Context context, Action <object, EventArgs> ReactToTtsInit,
                                    Action <object, UtteranceIdArgs> ReactToEndOfSpeech)
        {
            tts         = new TextToSpeech(context, this);
            uttListener = new ShopLensUtteranceProgressListener(ReactToEndOfSpeech);

            tts.SetOnUtteranceProgressListener(uttListener);
            TtsInitialized += (obj, eargs) => ReactToTtsInit(obj, eargs);
        }
예제 #4
0
 public void OnInit(OperationResult status)
 {
     if (status.Equals(OperationResult.Success))
     {
         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");
     }
 }
예제 #5
0
        public AndroidTextToSpeech(AndroidSensusService service)
        {
            // initialize wait handles before passing the current object as a listener
            // below. if the listener OnInit method is called before the wait handles are
            // initialized we could get an NRE:  https://insights.xamarin.com/app/Sensus-Production/issues/1099
            _initWait      = new ManualResetEvent(false);
            _utteranceWait = new ManualResetEvent(false);
            _disposed      = false;

            // initialize speech module
            _textToSpeech = new TextToSpeech(service, this);
            _textToSpeech.SetLanguage(Java.Util.Locale.Default);
            _textToSpeech.SetOnUtteranceProgressListener(this);
        }
 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");
     }
 }
        public DroidTextToSpeechService()
        {
            var context = Application.Context;

            _speaker = new TextToSpeech(context, this);
            _speaker.SetLanguage(new Java.Util.Locale("en-US"));
            _speaker.SetOnUtteranceProgressListener(this);
            AudioManager am = (AudioManager)context.GetSystemService(Context.AudioService);

#if RELEASE
            am.SetStreamVolume(Stream.Music, am.GetStreamMaxVolume(Stream.Music), 0);
#endif
#if DEBUG
            am.SetStreamVolume(Stream.Music, 5, 0);
#endif
        }
예제 #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
 public AndroidTextToSpeechService()
 {
     this.tts = new TextToSpeech(Android.App.Application.Context, new Listener {
         Init = (status) => {
             var r = tts.SetLanguage(Java.Util.Locale.English);
             if (r == LanguageAvailableResult.MissingData || r == LanguageAvailableResult.NotSupported)
             {
                 System.Diagnostics.Debug.Fail("Language is not supported");
             }
             initialized?.TrySetResult(true);
         }
     });
     tts.SetOnUtteranceProgressListener(new CompletedListener {
         Done  = async(s) => await OnDone(s),
         Error = async(s) => await OnError(s),
         Start = async(s) => await OnStart(s)
     });
 }
        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);
        }
예제 #11
0
 static Speech()
 {
     TextToSpeech = new TextToSpeech(Application.Context, Listener);
     TextToSpeech.SetOnUtteranceProgressListener(ProgressListener);
 }
예제 #12
0
 public TTSManager(Context activity)
 {
     context = activity;
     speaker = new TextToSpeech(context, this);
     speaker.SetOnUtteranceProgressListener(this);
 }
예제 #13
0
 public void SetupSpeaker()
 {
     speaker = new TextToSpeech(this, this);
     speaker.SetOnUtteranceProgressListener(new utteranceProgressListener(this));
 }