Example #1
0
    private void SetTextToSpeechCallbackListener(
        Action <int> OnInit
        , Action <string> OnGetLocaleCountry
        , Action <int> OnSetLocale
        , Action <string> OnStartSpeech
        , Action <string> OnDoneSpeech
        , Action <string> OnErrorSpeech
        )
    {
        #if UNITY_ANDROID
        if (Application.platform == RuntimePlatform.Android)
        {
            TTSCallback ttsCallback = new TTSCallback();
            ttsCallback.OnInit             = OnInit;
            ttsCallback.OnGetLocaleCountry = OnGetLocaleCountry;
            ttsCallback.OnSetLocale        = OnSetLocale;
            ttsCallback.OnStartSpeech      = OnStartSpeech;
            ttsCallback.OnDoneSpeech       = OnDoneSpeech;
            ttsCallback.OnErrorSpeech      = OnErrorSpeech;

            Debug.Log("[SpeechPLugin] SetTextToSpeechCallbackListener  ttsCallback " + ttsCallback);

            jo.CallStatic("setTextToSpeechCallbackListener", ttsCallback);
        }
        else
        {
            AUP.Utils.Message(TAG, "warning: must run in actual android device");
        }
        #endif
    }
Example #2
0
        // adds string to TTS queue
        public void Say(string msg, TTSCallback callback)
        {
            if (IsClosing() == true || IsRunning() == false) return;
            if (string.IsNullOrEmpty(msg)) return;

            IncomingMessage im = new IncomingMessage();
            im.type = IncomingMessageType.Say;
            im.message = msg;
            im.callback = callback;
            QueueMessage(im);
        }
Example #3
0
    public void SetTextToSpeechCallbackListener(
		Action <int>OnInit
		,Action <string>OnGetLocaleCountry
		,Action <int>OnSetLocale
		,Action <string>OnStartSpeech
		,Action <string>OnDoneSpeech
		,Action <string>OnErrorSpeech
		)
    {
        #if UNITY_ANDROID
        if(Application.platform == RuntimePlatform.Android){
            TTSCallback ttsCallback = new TTSCallback();
            ttsCallback.OnInit = OnInit;
            ttsCallback.OnGetLocaleCountry = OnGetLocaleCountry;
            ttsCallback.OnSetLocale = OnSetLocale;
            ttsCallback.OnStartSpeech = OnStartSpeech;
            ttsCallback.OnDoneSpeech = OnDoneSpeech;
            ttsCallback.OnErrorSpeech = OnErrorSpeech;

            Debug.Log("[SpeechPLugin] SetTextToSpeechCallbackListener  ttsCallback " + ttsCallback);

            jo.CallStatic("setTextToSpeechCallbackListener",ttsCallback);
        }else{
            AUP.Utils.Message(TAG,"warning: must run in actual android device");
        }
        #endif
    }
Example #4
0
        void SpeakerThread()
        {
            bool waiting_for_line = false;
            string message_waited_for = "";
            TTSCallback callback_waited_for = null;
            SetIsRunning(true);
            while (IsClosing() == false) {
                if(waiting_for_line) {
                    if(Client.VoiceFinished()) {
                        byte[] new_voice = Client.PopVoice();
                        float[] voice_float = new float[new_voice.Length/2];

                        for(int i = 0; i < voice_float.Length; i++) {
                            //if(BitConverter.IsLittleEndian) 
                            voice_float[i] = (float)BitConverter.ToInt16(new_voice, i*2)/(float)short.MaxValue;
                        }
                        OutgoingMessage om = new OutgoingMessage();
                        om.type = OutgoingMessageType.VoiceLineFinished;
                        om.data = voice_float;
                        om.message = message_waited_for;
                        om.callback = callback_waited_for;

                        outgoing_message_mutex.WaitOne();
                        outgoing_messages.Enqueue(om);
                        outgoing_message_mutex.ReleaseMutex();
                        waiting_for_line = false;
                        message_waited_for = "";
                        callback_waited_for = null;
                    }
                } else if (HasMessage()) {
                    try
                    {
                        IncomingMessage msg = PopMessage();
                        switch(msg.type) { 
                            case IncomingMessageType.Say:
                                Client.Speak(msg.message);
                                //Client.SpeakSSML(msg);

                                message_waited_for = msg.message;
                                callback_waited_for = msg.callback;
                                waiting_for_line = true;
                                break;
                            case IncomingMessageType.SetPitch:
                                Client.SetPitch(msg.param1);
                                break;
                            case IncomingMessageType.SetRange:
                                Client.SetRange(msg.param1);
                                break;
                            case IncomingMessageType.SetRate:
                                Client.SetRate(msg.param1);
                                break;
                            case IncomingMessageType.SetVolume:
                                Client.SetVolume(msg.param1);
                                break;
                            case IncomingMessageType.SetWordGap:
                                Client.SetWordgap(msg.param1);
                                break;
                            case IncomingMessageType.SetCapitals:
                                Client.SetCapitals(msg.param1);
                                break;
                            case IncomingMessageType.SetIntonation:
                                Client.SetIntonation(msg.param1);
                                break;
                            case IncomingMessageType.SetVoice:
                                Client.SetVoiceByName(msg.message);
                                break;

                        }
                    }
                    catch (System.Exception e)
                    {
                        Debug.LogException(e);
                    }
                }

                Thread.Sleep(8);
            }
            isRunning = false;
        }