diff --git a/README.md b/README.md
index 76c71b2..bc3567c 100644
--- a/README.md
+++ b/README.md
@@ -28,7 +28,10 @@
2023.03:
1、增加edge-tts语音合成(免费)可替换azure-tts(支持情绪化语音);
-2、替换flask发行版运行方式。
+2、替换flask发行版运行方式;
+4、web socket接口增加数字人文字内容同步,以便数人字可以远程运行;
+5、优化数字人数据web socket同步逻辑;
+6、更改gpt 3.5对接方式。
2023.02:
1、提供chatgpt及yuan1.0作为选择。
@@ -279,6 +282,6 @@ python main.py
技术交流群
-
+
diff --git a/ai_module/chatgpt.py b/ai_module/chatgpt.py
index ce783ee..d58dd30 100644
--- a/ai_module/chatgpt.py
+++ b/ai_module/chatgpt.py
@@ -1,10 +1,16 @@
+import json
+import requests
+
from utils import config_util as cfg
-import openai
-def question(text):
- cfg.load_config()
- openai.api_key = cfg.key_chatgpt_api_key
- prompt = text
- completions = openai.Completion.create(engine="text-davinci-002", prompt=prompt, max_tokens=1024)
- a_msg = completions.choices[0].text
- return a_msg
+def question(cont):
+ url="https://api.openai.com/v1/chat/completions"
+ req = json.dumps({
+ "model": "gpt-3.5-turbo",
+ "messages": [{"role": "user", "content": cont}],
+ "temperature": 0.7})
+ headers = {'content-type': 'application/json', 'Authorization': 'Bearer ' + cfg.key_chatgpt_api_key}
+ r = requests.post(url, headers=headers, data=req)
+ rsp = json.loads(r.text).get('choices')
+ a = rsp[0]['message']['content']
+ return a
\ No newline at end of file
diff --git a/core/fay_core.py b/core/fay_core.py
index 7f62d60..dc81144 100644
--- a/core/fay_core.py
+++ b/core/fay_core.py
@@ -29,7 +29,7 @@
class FeiFei:
def __init__(self):
- pygame.init()
+ pygame.mixer.init()
self.q_msg = '你叫什么名字?'
self.a_msg = 'hi,我叫菲菲,英文名是fay'
self.mood = 0.0 # 情绪值
@@ -255,6 +255,10 @@ def __auto_speak(self):
else:
raise RuntimeError('讯飞key、yuan key、chatgpt key都没有配置!')
util.log(1, '自然语言处理完成. 耗时: {} ms'.format(math.floor((time.time() - tm) * 1000)))
+ #同步文字内容给ue5
+ if text is not None and not config_util.config["interact"]["playSound"]: # 非展板播放
+ content = {'Topic': 'Unreal', 'Data': {'Key': 'text', 'Value': text}}
+ wsa_server.get_instance().add_cmd(content)
if text == '哎呀,你这么说我也不懂,详细点呗' or text == '':
util.log(1, '[!] 自然语言无语了!')
wsa_server.get_web_instance().add_cmd({"panelMsg": ""})
@@ -411,7 +415,7 @@ def __fay(self, index):
def __send_mood(self):
while self.__running:
time.sleep(3)
- if not self.sleep:
+ if not self.sleep and not config_util.config["interact"]["playSound"]:
content = {'Topic': 'Unreal', 'Data': {'Key': 'mood', 'Value': self.mood}}
wsa_server.get_instance().add_cmd(content)
@@ -496,9 +500,9 @@ def __send_audio(self, file_url, say_type):
# with wave.open(file_url, 'rb') as wav_file: #wav音频长度
# audio_length = wav_file.getnframes() / float(wav_file.getframerate())
if audio_length <= config_util.config["interact"]["maxInteractTime"] or say_type == "script":
- if config_util.config["interact"]["playSound"]: # 播放音频
+ if config_util.config["interact"]["playSound"]: # 展板播放
self.__play_sound(file_url)
- else:#TODO 发送音频给ue和socket
+ else:#发送音频给ue和socket
content = {'Topic': 'Unreal', 'Data': {'Key': 'audio', 'Value': os.path.abspath(file_url), 'Time': audio_length, 'Type': say_type}}
wsa_server.get_instance().add_cmd(content)
if self.deviceConnect is not None:
diff --git a/images/20230329172514.jpg b/images/20230329172514.jpg
new file mode 100644
index 0000000..ca5cfda
Binary files /dev/null and b/images/20230329172514.jpg differ