Example #1
0
        public void onSpeakingDone(Vocalizer vocalizer, string text, SpeechError error, object context)
        {
            Logger.info(this, "onSpeakingDone()");

            // for debugging purpose: logging the speechkit session id
            Logger.info(this, "session id: [" + _speechKit.getSessionId() + "]");

            hidePopup();
            if (error != null)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    MessageBox.Show(error.getErrorDetail());
                });
            }
            _vocalizer.cancel();
        }
Example #2
0
 void speechStart()
 {
     Thread thread = new Thread(() =>
     {
         _vocalizer = _speechKit.createVocalizerWithLanguage(_oemconfig.defaultLanguage(), this, _handler);
         _vocalizer.setLanguage(_oemconfig.defaultLanguage());
         _vocalizer.setVoice(_ttsVoice);
         _vocalizer.speakString(_ttsText, null);
         showPopup("Processing TTS");
     });
     thread.Start();
 }
Example #3
0
        public void onSpeakingBegin(Vocalizer vocalizer, string text, object context)
        {
            Logger.info(this, "onSpeakingBegin()");

            showPopup("Speaking");
        }
        protected void cleanup()
        {
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanup: Entered method.");
            if (currentRecognizer != null)
            {
            try
            {
                currentRecognizer.cancel();
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanupSpeechKit: Error cancelling recognizer: " + e.ToString());
            }
            }
            if (vocalizerInstance != null)
            {
            try
            {
                vocalizerInstance.cancel();
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanupSpeechKit: Vocalizer cancelled.");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanupSpeechKit: Error cancelling vocalizer: " + e.ToString());
            }
            vocalizerInstance = null;

            }

            if (speechKit != null)
            {
            try
            {
                speechKit.cancelCurrent();
                speechKit.release();
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanupSpeechKit: Speech kit released.");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.cleanupSpeechKit: Error releasing speech kit: " + e.ToString());
            }
            speechKit = null;
            }
        }
        /// <summary>Starts TTS playback</summary>
        /// <param name="args">JSON encoded request parameters</param>
        public void startTTS(String args)
        {
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Entered method.");

            PluginResult result = null;
            ReturnObject returnObject = new ReturnObject();

            StartTTSParameters startParams = JsonHelper.Deserialize<StartTTSParameters>(args);

            String ttsText = startParams.text;
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS Text = ["+ttsText+"]");
            String language = startParams.language;
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Language = ["+language+"]");
            String voice = startParams.voice;
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Voice = ["+voice+"]");

            if ((ttsText == null) || ("".Equals(ttsText))){
            setReturnCode(returnObject, RC_TTS_TEXT_INVALID, "TTS Text Invalid");
            }
            else
            if ((language == null) && (voice == null)){
            setReturnCode(returnObject, RC_TTS_PARAMS_INVALID, "Invalid language or voice.");
            }
            else
            if (speechKit != null){
            if (vocalizerInstance == null){

                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Vocalizer was not null.");

                if (language != null){
                    vocalizerInstance = speechKit.createVocalizerWithLanguage(language, this, null);
                }
                else{
                    vocalizerInstance = speechKit.createVocalizerWithVoice(voice, this, null);
                }

            }
            else{

                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Vocalizer was null.");
                if (language != null){
                    vocalizerInstance.setLanguage(language);
                }
                else{
                    vocalizerInstance.setVoice(voice);
                }

            }

            _lastTtsContext = new Object();
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Calling speakString.");
            vocalizerInstance.speakString(ttsText, _lastTtsContext);
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Called speakString.");

            setReturnCode(returnObject, RC_SUCCESS, "Success");
            }
            else{
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.execute: Speech kit was null, initialize not called.");
            setReturnCode(returnObject, RC_NOT_INITIALIZED, "TTS Start Failure: Speech Kit not initialized.");
            }

            result = new PluginResult(PluginResult.Status.OK, returnObject);
            result.KeepCallback = true;
            DispatchCommandResult(result);

            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin.startTTS: Leaving method.");
        }
        /// <summary>Callback method for TTS speaking done</summary>
        public void onSpeakingDone(Vocalizer vocalizer, String text, SpeechError error, Object context)
        {
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingDone: Context = [" + context + "], last context = " + _lastTtsContext);
                // Use the context to detemine if this was the final TTS phrase
                if (context != _lastTtsContext)
                {
                    ReturnObject returnObject = new ReturnObject();

                    setReturnCode(returnObject, RC_SUCCESS, "TTS Playing...");
                    returnObject.eventName = EVENT_TTS_PLAYING;

                    System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingDone: TTS Playing...");

                    PluginResult result = new PluginResult(PluginResult.Status.OK, returnObject);
                    result.KeepCallback = true;
                    DispatchCommandResult(result);

                }
                else
                {

                    ReturnObject returnObject = new ReturnObject();

                    setReturnCode(returnObject, RC_SUCCESS, "TTS Playback Complete");
                    returnObject.eventName = EVENT_TTS_COMPLETE;
                    System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingDone: TTS Complete...");

                    PluginResult result = new PluginResult(PluginResult.Status.OK, returnObject);
                    DispatchCommandResult(result);

                }

                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingDone: Leaving method.");
        }
        /// <summary>Callback method for TTS starting to speak</summary>
        public void onSpeakingBegin(Vocalizer vocalizer, String text, Object context)
        {
            System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingBegin: Entered method");

                ReturnObject returnObject = new ReturnObject();

                setReturnCode(returnObject, RC_SUCCESS, "TTS Playback Started");
                returnObject.eventName = EVENT_TTS_STARTED;
                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingDone: TTS Started...");

                PluginResult result = new PluginResult(PluginResult.Status.OK, returnObject);
                result.KeepCallback = true;
                DispatchCommandResult(result);

                System.Diagnostics.Debug.WriteLine("PhoneGapSpeechPlugin: Vocalizer.Listener.onSpeakingBegin: Leaving method.");
        }