Example #1
0
        public async Task <Response> ProcessAsync(Request request, Context context, CancellationToken token)
        {
            // 何らかの処理

            // インテント抽出結果の表示アクションを定義
            var animatedVoiceRequest = new AnimatedVoiceRequest();

            animatedVoiceRequest.AddVoice("line-girl1-konnichiha1", preGap: 1.0f, postGap: 2.0f);
            animatedVoiceRequest.AddAnimation("Default");

            // レスポンス
            var response = new Response(request.Id);

            response.Payloads = animatedVoiceRequest;
            return(response);
        }
Example #2
0
        // インテントとエンティティの抽出
        public async Task <Response> ExtractIntentAsync(Request request, Context context, CancellationToken token)
        {
            // インテントを抽出(常に hello)してリクエストを更新
            request.Intent = "hello";

            // インテント抽出結果の表示アクションを定義
            var animatedVoiceRequest = new AnimatedVoiceRequest();

            animatedVoiceRequest.AddVoice("line-girl1-haihaai1", preGap: 1.0f, postGap: 2.0f);
            animatedVoiceRequest.AddAnimation("Default");

            // レスポンス
            var response = new Response(request.Id);

            response.Payloads = animatedVoiceRequest;
            return(response);
        }
Example #3
0
        private 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 chatdoll.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;
            }
        }
Example #5
0
 public void AddVoice(string name, float preGap = 0.0f, float postGap = 0.0f, string description = null, bool asNewFrame = false)
 {
     AnimatedVoiceRequest.AddVoice(name, preGap, postGap, description, asNewFrame);
 }
Example #6
0
        public void TestAnimatedVoiceRequest()
        {
            var animatedVoiceRequest = new AnimatedVoiceRequest();

            Assert.AreEqual(new Dictionary <string, List <AnimatedVoice> >(), animatedVoiceRequest.AnimatedVoices);
            Assert.IsTrue(animatedVoiceRequest.DisableBlink);
            Assert.IsTrue(animatedVoiceRequest.StartIdlingOnEnd);
            Assert.IsTrue(animatedVoiceRequest.StopIdlingOnStart);
            Assert.IsTrue(animatedVoiceRequest.StopLayeredAnimations);
            Assert.AreEqual(string.Empty, animatedVoiceRequest.BaseLayerName);

            // 1st frame
            animatedVoiceRequest.AddAnimation("Walk");
            animatedVoiceRequest.AddAnimation("Run", 2.0f, 1.0f, 0.5f, 0.1f);
            animatedVoiceRequest.AddAnimation("WaveHands", "UpperBody", 3.0f, 2.0f, 0.8f, 0.2f, "upper animation");
            animatedVoiceRequest.AddVoice("Hello");
            animatedVoiceRequest.AddVoice("Goodby", 0.1f, 0.2f);
            animatedVoiceRequest.AddFace("Neutral");
            animatedVoiceRequest.AddFace("Default", 0.1f, "default face");

            // 2nd frame
            animatedVoiceRequest.AddAnimation("Jump", asNewFrame: true);
            animatedVoiceRequest.AddVoiceWeb("https://voice.local/goodmorning");
            animatedVoiceRequest.AddVoiceWeb("https://voice.local/goodafternoon", 0.1f, 0.2f);
            animatedVoiceRequest.AddFace("Cry");

            // 3rd frame
            var ttsConfig = new TTSConfiguration("TestTTSFuncName");

            ttsConfig.Params.Add("key1", "val1");
            ttsConfig.Params.Add("key2", 2.0f);
            animatedVoiceRequest.AddVoiceTTS("Good afternoon.", asNewFrame: true);
            animatedVoiceRequest.AddVoiceTTS("Good evening.", 0.1f, 0.2f, ttsConfig: ttsConfig);
            animatedVoiceRequest.AddAnimation("HandsFront");
            animatedVoiceRequest.AddFace("Jito");

            // 4th frame
            animatedVoiceRequest.AddFace("Surprise", asNewFrame: true);
            animatedVoiceRequest.AddVoice("GoodNight");
            animatedVoiceRequest.AddAnimation("HandsBack");

            // 1st frame
            var animation0101 = animatedVoiceRequest.AnimatedVoices[0].Animations[string.Empty][0];

            Assert.AreEqual("Walk", animation0101.Name);
            Assert.AreEqual(string.Empty, animation0101.LayerName);
            Assert.AreEqual(0.0f, animation0101.Duration);
            Assert.AreEqual(-1.0f, animation0101.FadeLength);
            Assert.AreEqual(1.0f, animation0101.Weight);
            Assert.AreEqual(0.0f, animation0101.PreGap);
            Assert.IsNull(animation0101.Description);
            Assert.AreEqual(0.0f, animation0101.Length);

            var animation0102 = animatedVoiceRequest.AnimatedVoices[0].Animations[string.Empty][1];

            Assert.AreEqual("Run", animation0102.Name);
            Assert.AreEqual(string.Empty, animation0102.LayerName);
            Assert.AreEqual(2.0f, animation0102.Duration);
            Assert.AreEqual(1.0f, animation0102.FadeLength);
            Assert.AreEqual(0.5f, animation0102.Weight);
            Assert.AreEqual(0.1f, animation0102.PreGap);
            Assert.IsNull(animation0102.Description);
            Assert.AreEqual(2.1f, animation0102.Length);

            var animation0103 = animatedVoiceRequest.AnimatedVoices[0].Animations["UpperBody"][0];

            Assert.AreEqual("WaveHands", animation0103.Name);
            Assert.AreEqual("UpperBody", animation0103.LayerName);
            Assert.AreEqual(3.0f, animation0103.Duration);
            Assert.AreEqual(2.0f, animation0103.FadeLength);
            Assert.AreEqual(0.8f, animation0103.Weight);
            Assert.AreEqual(0.2f, animation0103.PreGap);
            Assert.AreEqual("upper animation", animation0103.Description);
            Assert.AreEqual(3.2f, animation0103.Length);

            var voice0101 = animatedVoiceRequest.AnimatedVoices[0].Voices[0];

            Assert.AreEqual("Hello", voice0101.Name);
            Assert.AreEqual(0.0f, voice0101.PreGap);
            Assert.AreEqual(0.0f, voice0101.PostGap);
            Assert.IsNull(voice0101.Text);
            Assert.IsNull(voice0101.Url);
            Assert.IsNull(voice0101.TTSConfig);
            Assert.AreEqual(string.Empty, voice0101.GetTTSFunctionName());
            Assert.IsNull(voice0101.GetTTSParam("key1"));
            Assert.AreEqual(VoiceSource.Local, voice0101.Source);
            Assert.IsFalse(voice0101.UseCache);

            var voice0102 = animatedVoiceRequest.AnimatedVoices[0].Voices[1];

            Assert.AreEqual("Goodby", voice0102.Name);
            Assert.AreEqual(0.1f, voice0102.PreGap);
            Assert.AreEqual(0.2f, voice0102.PostGap);
            Assert.IsNull(voice0102.Text);
            Assert.IsNull(voice0102.Url);
            Assert.IsNull(voice0102.TTSConfig);
            Assert.AreEqual(string.Empty, voice0102.GetTTSFunctionName());
            Assert.IsNull(voice0102.GetTTSParam("key1"));
            Assert.AreEqual(VoiceSource.Local, voice0102.Source);
            Assert.IsFalse(voice0102.UseCache);

            var face0101 = animatedVoiceRequest.AnimatedVoices[0].Faces[0];

            Assert.AreEqual("Neutral", face0101.Name);
            Assert.AreEqual(0.0f, face0101.Duration);
            Assert.IsNull(face0101.Description);

            var face0102 = animatedVoiceRequest.AnimatedVoices[0].Faces[1];

            Assert.AreEqual("Default", face0102.Name);
            Assert.AreEqual(0.1f, face0102.Duration);
            Assert.AreEqual("default face", face0102.Description);

            // 2nd frame
            var animation0201 = animatedVoiceRequest.AnimatedVoices[1].Animations[string.Empty][0];

            Assert.AreEqual("Jump", animation0201.Name);

            var voice0201 = animatedVoiceRequest.AnimatedVoices[1].Voices[0];

            Assert.AreEqual(string.Empty, voice0201.Name);
            Assert.AreEqual(0.0f, voice0201.PreGap);
            Assert.AreEqual(0.0f, voice0201.PostGap);
            Assert.IsNull(voice0201.Text);
            Assert.AreEqual("https://voice.local/goodmorning", voice0201.Url);
            Assert.IsNull(voice0201.TTSConfig);
            Assert.AreEqual(string.Empty, voice0201.GetTTSFunctionName());
            Assert.IsNull(voice0201.GetTTSParam("key1"));
            Assert.AreEqual(VoiceSource.Web, voice0201.Source);
            Assert.IsTrue(voice0201.UseCache);
            Assert.AreEqual("https://voice.local/goodmorning", voice0201.CacheKey);

            var voice0202 = animatedVoiceRequest.AnimatedVoices[1].Voices[1];

            Assert.AreEqual(string.Empty, voice0202.Name);
            Assert.AreEqual(0.1f, voice0202.PreGap);
            Assert.AreEqual(0.2f, voice0202.PostGap);
            Assert.IsNull(voice0202.Text);
            Assert.AreEqual("https://voice.local/goodafternoon", voice0202.Url);
            Assert.IsNull(voice0202.TTSConfig);
            Assert.AreEqual(string.Empty, voice0202.GetTTSFunctionName());
            Assert.IsNull(voice0202.GetTTSParam("key1"));
            Assert.AreEqual(VoiceSource.Web, voice0202.Source);
            Assert.IsTrue(voice0202.UseCache);
            Assert.AreEqual("https://voice.local/goodafternoon", voice0202.CacheKey);

            var face0201 = animatedVoiceRequest.AnimatedVoices[1].Faces[0];

            Assert.AreEqual("Cry", face0201.Name);

            // 3rd frame
            var voice0301 = animatedVoiceRequest.AnimatedVoices[2].Voices[0];

            Assert.AreEqual(string.Empty, voice0301.Name);
            Assert.AreEqual(0.0f, voice0301.PreGap);
            Assert.AreEqual(0.0f, voice0301.PostGap);
            Assert.AreEqual("Good afternoon.", voice0301.Text);
            Assert.AreEqual(string.Empty, voice0301.Url);
            Assert.IsNull(voice0301.TTSConfig);
            Assert.AreEqual(VoiceSource.TTS, voice0301.Source);
            Assert.IsTrue(voice0301.UseCache);

            var voice0302 = animatedVoiceRequest.AnimatedVoices[2].Voices[1];

            Assert.AreEqual(string.Empty, voice0302.Name);
            Assert.AreEqual(0.1f, voice0302.PreGap);
            Assert.AreEqual(0.2f, voice0302.PostGap);
            Assert.AreEqual("Good evening.", voice0302.Text);
            Assert.AreEqual(string.Empty, voice0302.Url);
            Assert.AreEqual("TestTTSFuncName", voice0302.GetTTSFunctionName());
            Assert.AreEqual("val1", voice0302.GetTTSParam("key1"));
            Assert.AreEqual(2.0f, voice0302.GetTTSParam("key2"));
            Assert.AreEqual(VoiceSource.TTS, voice0302.Source);
            Assert.IsTrue(voice0302.UseCache);

            var animation0301 = animatedVoiceRequest.AnimatedVoices[2].Animations[string.Empty][0];

            Assert.AreEqual("HandsFront", animation0301.Name);

            var face0301 = animatedVoiceRequest.AnimatedVoices[2].Faces[0];

            Assert.AreEqual("Jito", face0301.Name);

            // 4th frame
            var face0401 = animatedVoiceRequest.AnimatedVoices[3].Faces[0];

            Assert.AreEqual("Surprise", face0401.Name);

            var voice0401 = animatedVoiceRequest.AnimatedVoices[3].Voices[0];

            Assert.AreEqual("GoodNight", voice0401.Name);

            var animation0401 = animatedVoiceRequest.AnimatedVoices[3].Animations[string.Empty][0];

            Assert.AreEqual("HandsBack", animation0401.Name);
        }