コード例 #1
0
 public void SpeechPlaybackStarted(ChatMessage message, float duration)
 {
     OnChatSpeech?.Invoke(message, duration);
 }
コード例 #2
0
        private void Update()
        {
            if (!SpeechToTextManager.Instance.UseNativeTTS)
            {
                if (!SpeechToTextManager.Instance.IsActive &&
                    !SpeechToTextManager.Instance.IsInitializing)
                {
                    SpeechToTextManager.Instance.Run();

                    failedListenAttempts++;

                    if (failedListenAttempts >= MaxFailListenAttempts)
                    {
                        OnSpeakingFailed?.Invoke();
                    }
                }
                else if (SpeechToTextManager.Instance.IsActive)
                {
                    failedListenAttempts = 0;
                }
            }

            foreach (ChatMessage message in chatMessages)
            {
                if (!message.HasAudio)
                {
                    if (message.IsFailedAudio)
                    {
                        continue;
                    }

                    if (RecordedDialog.Instance.RecordedFileExists(message.Text))
                    {
                        message.HasAudio = true;
                    }
                    else if (TextToSpeechManager.Instance.CachedOnly && !message.IsEmoji)
                    {
                        message.Text     = "Try that again. Maybe speak a little clearer.";
                        message.HasAudio = true;
                    }
                    else
                    {
                        if (!TextToSpeechManager.Instance.IsSynthesizing)
                        {
                            bool successStarting = TextToSpeechManager.Instance.GetAudio(message);
                            if (!successStarting && !message.IsEmoji)
                            {
                                message.AudioFails = ChatMessage.FailRetriesMax;
                                break;
                            }
                        }
                    }
                }
            }

            if (!TextToSpeechManager.Instance.IsSpeaking)
            {
                if (chatMessages.Count > 0)
                {
                    ChatMessage message = chatMessages[0];

                    if (message.IsEmoji)
                    {
                        if (Character != null)
                        {
                            Character.PlayAnimation(message.Text);
                        }

                        chatMessages.RemoveAt(0);
                    }
                    else if (message.HasAudio)
                    {
                        SpeakOutloud(message);

                        chatMessages.RemoveAt(0);
                    }
                    else if (message.IsFailedAudio)
                    {
                        OnSpeakingFailed?.Invoke();
                        OnChatSpeech?.Invoke(message, 3.0f);
                        chatMessages.RemoveAt(0);
                    }
                }
            }
        }