mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
Merge branch 'main' into tts-response
# Conflicts: # main/xiaozhi-server/core/handle/intentHandler.py
This commit is contained in:
@@ -53,6 +53,8 @@ class IntentProvider(IntentProviderBase):
|
||||
|
||||
prompt = (
|
||||
"你是一个意图识别助手。请分析用户的最后一句话,判断用户意图并调用相应的函数。\n\n"
|
||||
"- 如果用户使用疑问词(如'怎么'、'为什么'、'如何')询问退出相关的问题(例如'怎么退出了?'),注意这不是让你退出,请返回 {'function_call': {'name': 'continue_chat'}\n"
|
||||
"- 仅当用户明确使用'退出系统'、'结束对话'、'我不想和你说话了'等指令时,才触发 handle_exit_intent\n\n"
|
||||
f"{functions_desc}\n"
|
||||
"处理步骤:\n"
|
||||
"1. 分析用户输入,确定用户意图\n"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import json
|
||||
import uuid
|
||||
import requests
|
||||
from pydub import AudioSegment
|
||||
@@ -16,11 +17,21 @@ class TTSProvider(TTSProviderBase):
|
||||
def __init__(self, config, delete_audio_file):
|
||||
super().__init__(config, delete_audio_file)
|
||||
self.url = config.get("url")
|
||||
self.method = config.get("method", "GET")
|
||||
self.headers = config.get("headers", {})
|
||||
self.params = config.get("params")
|
||||
self.format = config.get("format", "wav")
|
||||
self.output_file = config.get("output_dir", "tmp/")
|
||||
|
||||
self.params = config.get("params")
|
||||
|
||||
if isinstance(self.params, str):
|
||||
try:
|
||||
self.params = json.loads(self.params)
|
||||
except json.JSONDecodeError:
|
||||
raise ValueError("Custom TTS配置参数出错,无法将字符串解析为对象")
|
||||
elif not isinstance(self.params, dict):
|
||||
raise TypeError("Custom TTS配置参数出错, 请参考配置说明")
|
||||
|
||||
def generate_filename(self):
|
||||
return os.path.join(
|
||||
self.output_file,
|
||||
@@ -35,7 +46,10 @@ class TTSProvider(TTSProviderBase):
|
||||
v = v.replace("{prompt_text}", text)
|
||||
request_params[k] = v
|
||||
|
||||
resp = requests.get(self.url, params=request_params, headers=self.headers)
|
||||
if self.method.upper() == "POST":
|
||||
resp = requests.post(self.url, json=request_params, headers=self.headers)
|
||||
else:
|
||||
resp = requests.get(self.url, params=request_params, headers=self.headers)
|
||||
if resp.status_code == 200:
|
||||
with open(tmp_file, "wb") as file:
|
||||
file.write(resp.content)
|
||||
|
||||
Reference in New Issue
Block a user