mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
+2








dd5fecdf5a
* 新增openai tts (#137) On branch openai_tts Changes to be committed: modified: config.yaml new file: core/providers/tts/openai_tts.py Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> * Update config.yaml (#201) * 修改了coze的实现方式,使用了v3接口,修复了只能对话一次的bug * 使用mem0ai api实现记忆功能 * Fix docker space (#179) * update:调试docker编译缓存 * update:调试docker编译 * update:调试docker编译容量 * update:调试docker编译 --------- Co-authored-by: hrz <1710360675@qq.com> * TTS处理增加index信息,完善TTS出错时的处理 (#177) * TTS处理增加index信息,完善TTS出错时的处理 * 第一句语音index处理,歌曲播放index处理 * update:去掉了无用变量,修复continuebug --------- Co-authored-by: hrz <1710360675@qq.com> * update:更新demo (#180) Co-authored-by: hrz <1710360675@qq.com> * 优化chat中异步调用方式 * 记忆增加时间,以便大模型判断先后关系 * 记忆对时间戳排序,便于梳理前后关系 * add: 不跟踪music下的文件的更改 (#187) * Mem0ai (#199) * update:增加mem0ai包依赖 * update:文档增加mem0ai的描述 --------- Co-authored-by: hrz <1710360675@qq.com> * Update config.yaml * Update config.yaml * Update config.yaml * Update config.yaml --------- Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> * update:添加忽略文件 * feat: 增加fastgpt适配:支持think、variables参数 (#213) * 修改了coze的实现方式,使用了v3接口,修复了只能对话一次的bug * 使用mem0ai api实现记忆功能 * Fix docker space (#179) * update:调试docker编译缓存 * update:调试docker编译 * update:调试docker编译容量 * update:调试docker编译 --------- Co-authored-by: hrz <1710360675@qq.com> * TTS处理增加index信息,完善TTS出错时的处理 (#177) * TTS处理增加index信息,完善TTS出错时的处理 * 第一句语音index处理,歌曲播放index处理 * update:去掉了无用变量,修复continuebug --------- Co-authored-by: hrz <1710360675@qq.com> * update:更新demo (#180) Co-authored-by: hrz <1710360675@qq.com> * 优化chat中异步调用方式 * 记忆增加时间,以便大模型判断先后关系 * 记忆对时间戳排序,便于梳理前后关系 * add: 不跟踪music下的文件的更改 (#187) * Mem0ai (#199) * update:增加mem0ai包依赖 * update:文档增加mem0ai的描述 --------- Co-authored-by: hrz <1710360675@qq.com> * feat: 增加fastgpt适配:支持think、variables参数 --------- Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> Co-authored-by: pt <ptsghs@163.com> * update:合并最新代码 * update:合并群友pr * update:openaitts 测试通过 * update:ACGNTTS测试完成 --------- Co-authored-by: Chris <119588753+Chris-websketch@users.noreply.github.com> Co-authored-by: ikun441 <3497689533@qq.com> Co-authored-by: strix214 <a1425699467@gmail.com> Co-authored-by: 玄凤科技 <eric230308@gmail.com> Co-authored-by: HonestQiao <honestqiao@163.com> Co-authored-by: hrz <1710360675@qq.com> Co-authored-by: TOM88812 <ttangxs0808@163.com> Co-authored-by: 香草味的纳西妲 <151599587+NyaOH-Nahida@users.noreply.github.com> Co-authored-by: ptisnoob <49125305+ptisnoob@users.noreply.github.com> Co-authored-by: pt <ptsghs@163.com>
122 lines
4.1 KiB
Python
122 lines
4.1 KiB
Python
import os
|
||
import json
|
||
import yaml
|
||
import socket
|
||
import subprocess
|
||
import logging
|
||
|
||
|
||
def get_project_dir():
|
||
"""获取项目根目录"""
|
||
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/'
|
||
|
||
|
||
def get_local_ip():
|
||
try:
|
||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||
# Connect to Google's DNS servers
|
||
s.connect(("8.8.8.8", 80))
|
||
local_ip = s.getsockname()[0]
|
||
s.close()
|
||
return local_ip
|
||
except Exception as e:
|
||
return "127.0.0.1"
|
||
|
||
|
||
def read_config(config_path):
|
||
with open(config_path, "r", encoding="utf-8") as file:
|
||
config = yaml.safe_load(file)
|
||
return config
|
||
|
||
|
||
def write_json_file(file_path, data):
|
||
"""将数据写入 JSON 文件"""
|
||
with open(file_path, 'w', encoding='utf-8') as file:
|
||
json.dump(data, file, ensure_ascii=False, indent=4)
|
||
|
||
|
||
def is_punctuation_or_emoji(char):
|
||
"""检查字符是否为空格、指定标点或表情符号"""
|
||
# 定义需要去除的中英文标点(包括全角/半角)
|
||
punctuation_set = {
|
||
',', ',', # 中文逗号 + 英文逗号
|
||
'。', '.', # 中文句号 + 英文句号
|
||
'!', '!', # 中文感叹号 + 英文感叹号
|
||
'-', '-', # 英文连字符 + 中文全角横线
|
||
'、' # 中文顿号
|
||
}
|
||
if char.isspace() or char in punctuation_set:
|
||
return True
|
||
# 检查表情符号(保留原有逻辑)
|
||
code_point = ord(char)
|
||
emoji_ranges = [
|
||
(0x1F600, 0x1F64F), (0x1F300, 0x1F5FF),
|
||
(0x1F680, 0x1F6FF), (0x1F900, 0x1F9FF),
|
||
(0x1FA70, 0x1FAFF), (0x2600, 0x26FF),
|
||
(0x2700, 0x27BF)
|
||
]
|
||
return any(start <= code_point <= end for start, end in emoji_ranges)
|
||
|
||
|
||
def get_string_no_punctuation_or_emoji(s):
|
||
"""去除字符串首尾的空格、标点符号和表情符号"""
|
||
chars = list(s)
|
||
# 处理开头的字符
|
||
start = 0
|
||
while start < len(chars) and is_punctuation_or_emoji(chars[start]):
|
||
start += 1
|
||
# 处理结尾的字符
|
||
end = len(chars) - 1
|
||
while end >= start and is_punctuation_or_emoji(chars[end]):
|
||
end -= 1
|
||
return ''.join(chars[start:end + 1])
|
||
|
||
|
||
def remove_punctuation_and_length(text):
|
||
# 全角符号和半角符号的Unicode范围
|
||
full_width_punctuations = '!"#$%&'()*+,-。/:;<=>?@[\]^_`{|}~'
|
||
half_width_punctuations = '!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'
|
||
space = ' ' # 半角空格
|
||
full_width_space = ' ' # 全角空格
|
||
|
||
# 去除全角和半角符号以及空格
|
||
result = ''.join([char for char in text if
|
||
char not in full_width_punctuations and char not in half_width_punctuations and char not in space and char not in full_width_space])
|
||
|
||
if result == "Yeah":
|
||
return 0, ""
|
||
return len(result), result
|
||
|
||
def check_model_key(modelType, modelKey):
|
||
if "你" in modelKey:
|
||
logging.error("你还没配置" + modelType + "的密钥,请在配置文件中配置密钥,否则无法正常工作")
|
||
return False
|
||
return True
|
||
|
||
|
||
def check_ffmpeg_installed():
|
||
ffmpeg_installed = False
|
||
try:
|
||
# 执行ffmpeg -version命令,并捕获输出
|
||
result = subprocess.run(
|
||
['ffmpeg', '-version'],
|
||
stdout=subprocess.PIPE,
|
||
stderr=subprocess.PIPE,
|
||
text=True,
|
||
check=True # 如果返回码非零则抛出异常
|
||
)
|
||
# 检查输出中是否包含版本信息(可选)
|
||
output = result.stdout + result.stderr
|
||
if 'ffmpeg version' in output.lower():
|
||
ffmpeg_installed = True
|
||
return False
|
||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||
# 命令执行失败或未找到
|
||
ffmpeg_installed = False
|
||
if not ffmpeg_installed:
|
||
error_msg = "您的电脑还没正确安装ffmpeg\n"
|
||
error_msg += "\n建议您:\n"
|
||
error_msg += "1、按照项目的安装文档,正确进入conda环境\n"
|
||
error_msg += "2、查阅安装文档,如何在conda环境中安装ffmpeg\n"
|
||
raise ValueError(error_msg)
|