コード例 #1
0
    // Start is called before the first frame update
    public void Start()
    {
#if PLATFORM_ANDROID
        if (!Permission.HasUserAuthorizedPermission(Permission.Microphone))
        {
            Permission.RequestUserPermission(Permission.Microphone);
        }
#endif
        //voiceTest = new VoiceTest();
        voiceC    = this.transform.GetChild(2).gameObject;
        voiceTest = voiceC.GetComponent <VoiceTest>();
        VoiceController voiceController = voiceC.GetComponent <VoiceController>();
        voiceTest.InitPluin();
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        pandaBot            = new pandaAIMLBot();
        pandaBot.Start();
        speechController = new myvoiceController();
        var aSources = GetComponents <AudioSource>();
        userAudioSource                  = aSources[0];
        pandaOutputAudioSource           = aSources[1];
        originalPosition                 = gameObject.transform.position;
        originalRotationValue            = transform.rotation;
        speechController.audioSource     = pandaOutputAudioSource;
        speechController.myHandleTextBox = myHandleTextBox;
        animator = GetComponent <Animator>();
        speechController.animator = animator;
        robotOutput.text          = "Hi, I am panda bot. How can I help you?";
        Debug.Log(robotOutput.text);
        if (voiceTest.isIntialised())
        {
            //StartCoroutine(voiceTest.TTS(robotOutput.text));
            voiceTest.TTS(robotOutput.text);
        }
        else
        {
            StartCoroutine(speechController.sendRequestToRSSAndPlayAudio(robotOutput.text));
        }
        animator.Play("talking");
        animator.Play("waving");
        clipSampleData       = new float[1024];
        userAudioSource.clip = null;
        //Invoke("voiceTest.TTS(robotOutput.text)", 1);
        Idle();
    }
コード例 #2
0
    private void Talk()
    {
        //inputField.text = "Talk called.....";

        if (animator != null)
        {
            Debug.Log("Talk called");
            //inputField.text = "Talk called.";
            gameObject.transform.position = originalPosition;

            transform.rotation = Quaternion.Slerp(transform.rotation, originalRotationValue, Time.time * 1.0f);
            if (!(voiceTest.myResponse == null))
            {
                inputField.text = "My question is: " + voiceTest.myResponse;
                char[] a = voiceTest.myResponse.ToCharArray();
                a[0] = char.ToUpper(a[0]);
                string userAudioResponse = new string(a);
                string answer            = pandaBot.getResponse(userAudioResponse);
                animator.Play("talking");
                voiceTest.TTS(answer);
                //StartCoroutine(voiceTest.TTS(answer));
                //StartCoroutine(speechController.sendRequestToRSSAndPlayAudio(answer));
                robotOutput.text = answer;
                SwitchState();

                //Invoke("SwitchState", 4);
            }
            else
            {
                myHandleTextBox.text = "Please speak loudly.";
                Invoke("SwitchState", 1);
            }
        }
        else
        {
            inputField.text = "Animator is not running.";
        }
    }