using System;
using UnityEngine;
public class ChatAI : MonoBehaviour
{
///
/// 聊天配置
///
public ChatSetting m_ChatSettings;
public static ChatAI Instance { get; private set; }
Action recordingCallBack;
void Awake()
{
Instance = this;
//DontDestroyOnLoad(this);
}
#region AI智能体
public void SendData(string _postWord, Action action = null)
{
if (string.IsNullOrEmpty(_postWord)) return;
m_ChatSettings.m_ChatModel.PostMsg(_postWord, reply => {
action?.Invoke(reply);
});
}
public void StopSend()
{
m_ChatSettings.m_ChatModel.StopMsg();
}
#endregion
#region 语音输入
///
/// 开始录制
///
public void StartRecord()
{
//m_ChatSettings.m_RealtimeSpeechToText?.StopSpeechToText(null);//停止流式语音
m_ChatSettings.m_SpeechToText?.StartSpeechToText(null);//开启非流式语音
}
///
/// 结束录制
///
public void StopRecord(Action callBack)
{
m_ChatSettings.m_SpeechToText?.StopSpeechToText(callBack);//停止非流式语音
//m_ChatSettings.m_RealtimeSpeechToText?.StartSpeechToText(recordingCallBack);//开启流式语音
}
///
/// 开始实时录制
///
public void StartRecording(Action callBack)
{
recordingCallBack = callBack;
m_ChatSettings.m_RealtimeSpeechToText.StartSpeechToText(recordingCallBack);
}
public void StopRecording()
{
recordingCallBack = null;
m_ChatSettings.m_RealtimeSpeechToText.StopSpeechToText(null);
}
#endregion
#region 语音合成
public void PlayVoice(string speakText,Action callBack = null)
{
m_ChatSettings.m_TextToSpeech.StartSpeak(speakText, callBack);
}
public void StopVoice()
{
m_ChatSettings.m_TextToSpeech.StopSpeak();
}
#endregion
}