Exemple #1
0
#pragma warning restore CS1998

        // Show response
        public virtual async Task ShowResponseAsync(Response response, Request request, Context context, CancellationToken token)
        {
            if (token.IsCancellationRequested)
            {
                return;
            }

            if (response.AnimatedVoiceRequest != null)
            {
                await modelController?.AnimatedSay(response.AnimatedVoiceRequest, token);
            }
        }
        public async Task AnimatedSay()
        {
            // 発話・アニメーション要求の作成
            var request = new AnimatedVoiceRequest();

            request.AddVoice("line-girl1-yobimashita1", 1.0f, 1.0f);
            request.AddAnimation("AGIA_Idle_angry_01_hands_on_waist");

            //request.AddVoice("line-girl1-yobimashita1");
            //request.AddAnimation("Default");

            //request.AddVoice("line-girl1-haihaai1", 1.0f, 1.0f, asNewFrame: true);
            //request.AddAnimation("AGIA_Idle_angry_01_hands_on_waist");
            //request.AddFace("Smile", 2.0f);   // 笑顔を2秒間継続
            //request.AddFace("Default");       // 元に戻す

            //request.AddVoice("line-girl1-konnichiha1", asNewFrame: true);
            //request.AddAnimation("Default");

            // 発話・アニメーションの実行
            await modelController.AnimatedSay(request, GetToken());
        }
        protected virtual void Awake()
        {
            // Get components
            chatdoll              = gameObject.GetComponent <Chatdoll>();
            modelController       = gameObject.GetComponent <ModelController>();
            voiceRequestProvider  = gameObject.GetComponent <VoiceRequestProviderBase>();
            cameraRequestProvider = gameObject.GetComponent <CameraRequestProvider>();
            qrcodeRequestProvider = gameObject.GetComponent <QRCodeRequestProvider>();
            wakeWordListener      = GetComponent <WakeWordListenerBase>();

            // Prompt
            var httpPrompter = gameObject.GetComponent <HttpPrompter>();

            if (httpPrompter != null)
            {
                chatdoll.OnPromptAsync = httpPrompter.OnPromptAsync;
            }
            else
            {
                if (!string.IsNullOrEmpty(PromptVoice))
                {
                    if (PromptVoiceType == VoiceSource.Local)
                    {
                        PromptAnimatedVoiceRequest.AddVoice(PromptVoice);
                    }
                    else if (PromptVoiceType == VoiceSource.Web)
                    {
                        PromptAnimatedVoiceRequest.AddVoiceWeb(PromptVoice);
                    }
                    else if (PromptVoiceType == VoiceSource.TTS)
                    {
                        PromptAnimatedVoiceRequest.AddVoiceTTS(PromptVoice);
                    }
                }
                if (!string.IsNullOrEmpty(PromptFace))
                {
                    PromptAnimatedVoiceRequest.AddFace(PromptFace);
                }
                if (!string.IsNullOrEmpty(PromptAnimation))
                {
                    PromptAnimatedVoiceRequest.AddAnimation(PromptAnimation);
                }

                chatdoll.OnPromptAsync = async(r, u, c, t) =>
                {
                    await modelController.AnimatedSay(PromptAnimatedVoiceRequest, t);
                };
            }

            // Error
            chatdoll.OnErrorAsync = async(r, c, t) =>
            {
                await modelController.AnimatedSay(ErrorAnimatedVoiceRequest, t);
            };

            // Wakeword Listener
            if (wakeWordListener != null)
            {
                // Register wakeword
                if (wakeWordListener.WakeWords.Count == 0)
                {
                    if (!string.IsNullOrEmpty(WakeWord))
                    {
                        wakeWordListener.WakeWords.Add(new WakeWord()
                        {
                            Text = WakeWord, Intent = string.Empty
                        });
                    }
                }

                // Register cancel word
                if (wakeWordListener.CancelWords.Count == 0)
                {
                    if (!string.IsNullOrEmpty(CancelWord))
                    {
                        wakeWordListener.CancelWords.Add(CancelWord);
                    }
                }

                // Awaken
                wakeWordListener.OnWakeAsync = async(wakeword) =>
                {
                    var     skipPrompt = false;
                    Request preRequest = null;

                    // Set request type, intent and inline request if set
                    if (wakeword.RequestType != RequestType.None ||
                        !string.IsNullOrEmpty(wakeword.Intent) ||
                        !string.IsNullOrEmpty(wakeword.InlineRequestText))
                    {
                        preRequest        = new Request(wakeword.RequestType);
                        preRequest.Intent = wakeword.Intent;
                        if (!string.IsNullOrEmpty(wakeword.InlineRequestText))
                        {
                            preRequest.Text = wakeword.InlineRequestText;
                            skipPrompt      = true;
                        }
                    }

                    // Invoke chat
                    await chatdoll.StartChatAsync(GetUserId(), skipPrompt, preRequest);
                };

                // Cancel
                wakeWordListener.OnCancelAsync = async() => { chatdoll.StopChat(); };

                // Raise voice detection threshold when chatting
                wakeWordListener.ShouldRaiseThreshold = () => { return(chatdoll.IsChatting); };
            }

            // Voice Request Provider
            if (voiceRequestProvider != null)
            {
                // Set message window
                if (voiceRequestProvider.MessageWindow == null)
                {
                    InstantiateMessageWindos();
                    voiceRequestProvider.MessageWindow = MessageWindow;
                }

                // Register cancel word to request provider
                if (voiceRequestProvider.CancelWords.Count == 0)
                {
                    voiceRequestProvider.CancelWords.Add(CancelWord);
                }
            }

            // Camera and QRCode Request Provider
            if (cameraRequestProvider.ChatdollCamera == null)
            {
                InstantiateCamera();
                cameraRequestProvider.ChatdollCamera = ChatdollCamera;
            }
            if (qrcodeRequestProvider.ChatdollCamera == null)
            {
                InstantiateCamera();
                qrcodeRequestProvider.ChatdollCamera = ChatdollCamera;
            }
        }
Exemple #4
0
 public async Task ShowResponseAsync(Response response, Request request, Context context, CancellationToken token)
 {
     var animatedVoiceRequest = response.Payloads as AnimatedVoiceRequest;
     await modelController.AnimatedSay(animatedVoiceRequest, token);
 }