mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
#164 自定义asr、tts缓存目录,项目启动自动创建目录
This commit is contained in:
parent
6eac25425c
commit
723b394f6c
3 changed files with 87 additions and 60 deletions
|
|
@ -30,7 +30,7 @@ log:
|
||||||
# 设置日志等级:INFO、DEBUG
|
# 设置日志等级:INFO、DEBUG
|
||||||
log_level: INFO
|
log_level: INFO
|
||||||
# 设置日志路径
|
# 设置日志路径
|
||||||
log_dir: tmp
|
log_dir: log
|
||||||
# 设置日志文件
|
# 设置日志文件
|
||||||
log_file: "server.log"
|
log_file: "server.log"
|
||||||
# 设置数据文件路径
|
# 设置数据文件路径
|
||||||
|
|
@ -51,15 +51,13 @@ xiaozhi:
|
||||||
prompt: |
|
prompt: |
|
||||||
你是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。
|
你是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。
|
||||||
请注意,要像一个人一样说话,请不要回复表情符号、代码、和xml标签。
|
请注意,要像一个人一样说话,请不要回复表情符号、代码、和xml标签。
|
||||||
现在我正在和你进行语音聊天,我们开始吧。
|
当前时间是:{date_time},现在我正在和你进行语音聊天,我们开始吧。
|
||||||
如果用户希望结束对话,请在最后说“拜拜”或“再见”。
|
如果用户希望结束对话,请在最后说“拜拜”或“再见”。
|
||||||
# 使用完声音文件后删除文件(Delete the sound file when you are done using it)
|
# 使用完声音文件后删除文件(Delete the sound file when you are done using it)
|
||||||
delete_audio: true
|
delete_audio: true
|
||||||
|
|
||||||
# 没有语音输入多久后断开连接(秒),默认2分钟,即120秒
|
# 没有语音输入多久后断开连接(秒),默认2分钟,即120秒
|
||||||
close_connection_no_voice_time: 120
|
close_connection_no_voice_time: 120
|
||||||
# TTS请求超时时间(秒)
|
|
||||||
tts_timeout: 10
|
|
||||||
|
|
||||||
CMD_exit:
|
CMD_exit:
|
||||||
- "退出"
|
- "退出"
|
||||||
|
|
@ -87,20 +85,14 @@ selected_module:
|
||||||
Intent:
|
Intent:
|
||||||
# 不使用意图识别
|
# 不使用意图识别
|
||||||
nointent:
|
nointent:
|
||||||
# 不需要动type
|
# 不需要动
|
||||||
type: nointent
|
type: nointent
|
||||||
intent_llm:
|
intent_llm:
|
||||||
# 不需要动type
|
# 不需要动
|
||||||
type: intent_llm
|
type: intent_llm
|
||||||
function_call:
|
function_call:
|
||||||
# 不需要动type
|
# 不需要动
|
||||||
type: nointent
|
type: nointent
|
||||||
# plugins_func/functions下的模块,可以通过配置,选择加载哪个模块,加载后对话支持相应的function调用
|
|
||||||
# 系统默认已经记载“handle_exit_intent(退出识别)”、“play_music(音乐播放)”插件,请勿重复加载
|
|
||||||
# 下面是加载查天气、角色切换的插件示例
|
|
||||||
functions:
|
|
||||||
- change_role
|
|
||||||
- get_weather
|
|
||||||
|
|
||||||
Memory:
|
Memory:
|
||||||
mem0ai:
|
mem0ai:
|
||||||
|
|
@ -220,7 +212,7 @@ TTS:
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: edge
|
type: edge
|
||||||
voice: zh-CN-XiaoxiaoNeural
|
voice: zh-CN-XiaoxiaoNeural
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
DoubaoTTS:
|
DoubaoTTS:
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: doubao
|
type: doubao
|
||||||
|
|
@ -230,7 +222,7 @@ TTS:
|
||||||
# 地址:https://console.volcengine.com/speech/service/8
|
# 地址:https://console.volcengine.com/speech/service/8
|
||||||
api_url: https://openspeech.bytedance.com/api/v1/tts
|
api_url: https://openspeech.bytedance.com/api/v1/tts
|
||||||
voice: BV001_streaming
|
voice: BV001_streaming
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
authorization: "Bearer;"
|
authorization: "Bearer;"
|
||||||
appid: 你的火山引擎语音合成服务appid
|
appid: 你的火山引擎语音合成服务appid
|
||||||
access_token: 你的火山引擎语音合成服务access_token
|
access_token: 你的火山引擎语音合成服务access_token
|
||||||
|
|
@ -241,7 +233,7 @@ TTS:
|
||||||
# token申请地址 https://cloud.siliconflow.cn/account/ak
|
# token申请地址 https://cloud.siliconflow.cn/account/ak
|
||||||
model: FunAudioLLM/CosyVoice2-0.5B
|
model: FunAudioLLM/CosyVoice2-0.5B
|
||||||
voice: FunAudioLLM/CosyVoice2-0.5B:alex
|
voice: FunAudioLLM/CosyVoice2-0.5B:alex
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
access_token: 你的硅基流动API密钥
|
access_token: 你的硅基流动API密钥
|
||||||
response_format: wav
|
response_format: wav
|
||||||
CozeCnTTS:
|
CozeCnTTS:
|
||||||
|
|
@ -249,7 +241,7 @@ TTS:
|
||||||
# COZECN TTS
|
# COZECN TTS
|
||||||
# token申请地址 https://www.coze.cn/open/oauth/pats
|
# token申请地址 https://www.coze.cn/open/oauth/pats
|
||||||
voice: 7426720361733046281
|
voice: 7426720361733046281
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
access_token: 你的coze web key
|
access_token: 你的coze web key
|
||||||
response_format: wav
|
response_format: wav
|
||||||
FishSpeech:
|
FishSpeech:
|
||||||
|
|
@ -262,7 +254,7 @@ TTS:
|
||||||
#--decoder-config-name firefly_gan_vq
|
#--decoder-config-name firefly_gan_vq
|
||||||
#--compile
|
#--compile
|
||||||
type: fishspeech
|
type: fishspeech
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
response_format: wav
|
response_format: wav
|
||||||
reference_id: null
|
reference_id: null
|
||||||
reference_audio: ["/tmp/test.wav",]
|
reference_audio: ["/tmp/test.wav",]
|
||||||
|
|
@ -286,7 +278,7 @@ TTS:
|
||||||
#python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/caixukun.yaml
|
#python api_v2.py -a 127.0.0.1 -p 9880 -c GPT_SoVITS/configs/caixukun.yaml
|
||||||
type: gpt_sovits_v2
|
type: gpt_sovits_v2
|
||||||
url: "http://127.0.0.1:9880/tts"
|
url: "http://127.0.0.1:9880/tts"
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
text_lang: "auto"
|
text_lang: "auto"
|
||||||
ref_audio_path: "caixukun.wav"
|
ref_audio_path: "caixukun.wav"
|
||||||
prompt_text: ""
|
prompt_text: ""
|
||||||
|
|
@ -306,24 +298,20 @@ TTS:
|
||||||
repetition_penalty: 1.35
|
repetition_penalty: 1.35
|
||||||
aux_ref_audio_paths: []
|
aux_ref_audio_paths: []
|
||||||
GPT_SOVITS_V3:
|
GPT_SOVITS_V3:
|
||||||
# 定义TTS API类型 GPT-SoVITS-v3lora-20250228
|
|
||||||
#启动tts方法:
|
|
||||||
#python api.py
|
|
||||||
type: gpt_sovits_v3
|
type: gpt_sovits_v3
|
||||||
url: "http://127.0.0.1:9880"
|
url: "http://127.0.0.1:9880/tts"
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
text_language: "auto"
|
text_lang: "auto"
|
||||||
refer_wav_path: "caixukun.wav"
|
ref_audio_path: "caixukun.wav"
|
||||||
prompt_language: "zh"
|
prompt_lang: "zh"
|
||||||
prompt_text: ""
|
prompt_text: ""
|
||||||
top_k: 15
|
top_k: 5
|
||||||
top_p: 1.0
|
top_p: 1
|
||||||
temperature: 1.0
|
temperature: 1
|
||||||
cut_punc: ""
|
sample_steps: 16
|
||||||
speed: 1.0
|
media_type: "wav"
|
||||||
inp_refs: []
|
streaming_mode: false
|
||||||
sample_steps: 32
|
threshold: 30
|
||||||
if_sr: false
|
|
||||||
MinimaxTTS:
|
MinimaxTTS:
|
||||||
# Minimax语音合成服务,需要先在minimax平台创建账户充值,并获取登录信息
|
# Minimax语音合成服务,需要先在minimax平台创建账户充值,并获取登录信息
|
||||||
# 平台地址:https://platform.minimaxi.com/
|
# 平台地址:https://platform.minimaxi.com/
|
||||||
|
|
@ -332,7 +320,7 @@ TTS:
|
||||||
# api_key地址:https://platform.minimaxi.com/user-center/basic-information/interface-key
|
# api_key地址:https://platform.minimaxi.com/user-center/basic-information/interface-key
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: minimax
|
type: minimax
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
group_id: 你的minimax平台groupID
|
group_id: 你的minimax平台groupID
|
||||||
api_key: 你的minimax平台接口密钥
|
api_key: 你的minimax平台接口密钥
|
||||||
model: "speech-01-turbo"
|
model: "speech-01-turbo"
|
||||||
|
|
@ -369,7 +357,7 @@ TTS:
|
||||||
# token地址:https://nls-portal.console.aliyun.com/overview
|
# token地址:https://nls-portal.console.aliyun.com/overview
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
type: aliyun
|
type: aliyun
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
appkey: 你的阿里云智能语音交互服务项目Appkey
|
appkey: 你的阿里云智能语音交互服务项目Appkey
|
||||||
token: 你的阿里云智能语音交互服务AccessToken,临时的24小时,要长期用下方的access_key_id,access_key_secret
|
token: 你的阿里云智能语音交互服务AccessToken,临时的24小时,要长期用下方的access_key_id,access_key_secret
|
||||||
voice: xiaoyun
|
voice: xiaoyun
|
||||||
|
|
@ -409,7 +397,7 @@ TTS:
|
||||||
to_lang: ZH
|
to_lang: ZH
|
||||||
url: https://u95167-bd74-2aef8085.westx.seetacloud.com:8443/flashsummary/tts?token=
|
url: https://u95167-bd74-2aef8085.westx.seetacloud.com:8443/flashsummary/tts?token=
|
||||||
format: mp3
|
format: mp3
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
emotion: 1
|
emotion: 1
|
||||||
OpenAITTS:
|
OpenAITTS:
|
||||||
# openai官方文本转语音服务,可支持全球大多数语种
|
# openai官方文本转语音服务,可支持全球大多数语种
|
||||||
|
|
@ -423,22 +411,7 @@ TTS:
|
||||||
voice: onyx
|
voice: onyx
|
||||||
# 语速范围0.25-4.0
|
# 语速范围0.25-4.0
|
||||||
speed: 1
|
speed: 1
|
||||||
output_file: tmp/
|
output_dir: tmp/
|
||||||
CustomTTS:
|
|
||||||
# 自定义的TTS接口服务,请求参数可自定义
|
|
||||||
# 要求接口使用GET方式请求,并返回音频文件
|
|
||||||
type: custom
|
|
||||||
url: "http://127.0.0.1:9880/tts"
|
|
||||||
params: # 自定义请求参数
|
|
||||||
# text: "{prompt_text}" # {prompt_text}会被替换为实际的提示词内容
|
|
||||||
# speaker: jok老师
|
|
||||||
# speed: 1
|
|
||||||
# foo: bar
|
|
||||||
# testabc: 123456
|
|
||||||
headers: # 自定义请求头
|
|
||||||
# Authorization: Bearer xxxx
|
|
||||||
format: wav # 接口返回的音频格式
|
|
||||||
output_file: tmp/
|
|
||||||
# 模块测试配置
|
# 模块测试配置
|
||||||
module_test:
|
module_test:
|
||||||
test_sentences: # 自定义测试语句
|
test_sentences: # 自定义测试语句
|
||||||
|
|
@ -461,4 +434,4 @@ manager:
|
||||||
enabled: false
|
enabled: false
|
||||||
ip: 0.0.0.0
|
ip: 0.0.0.0
|
||||||
port: 8002
|
port: 8002
|
||||||
use_private_config: false
|
use_private_config: false
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,73 @@ from core.utils.util import read_config, get_project_dir
|
||||||
default_config_file = "config.yaml"
|
default_config_file = "config.yaml"
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_directories(config):
|
||||||
|
"""确保所有配置路径存在"""
|
||||||
|
dirs_to_create = set()
|
||||||
|
project_dir = get_project_dir() # 获取项目根目录
|
||||||
|
# 日志文件目录
|
||||||
|
log_dir = config.get('log', {}).get('log_dir', 'tmp')
|
||||||
|
dirs_to_create.add(os.path.join(project_dir, log_dir))
|
||||||
|
|
||||||
|
# ASR/TTS模块输出目录
|
||||||
|
for module in ['ASR', 'TTS']:
|
||||||
|
for provider in config.get(module, {}).values():
|
||||||
|
output_dir = provider.get('output_dir', '')
|
||||||
|
if output_dir:
|
||||||
|
dirs_to_create.add(output_dir)
|
||||||
|
|
||||||
|
# 根据selected_module创建模型目录
|
||||||
|
selected_modules = config.get('selected_module', {})
|
||||||
|
for module_type in ['ASR', 'LLM', 'TTS']:
|
||||||
|
selected_provider = selected_modules.get(module_type)
|
||||||
|
if not selected_provider:
|
||||||
|
continue
|
||||||
|
provider_config = config.get(module_type, {}).get(selected_provider, {})
|
||||||
|
output_dir = provider_config.get('output_dir')
|
||||||
|
if output_dir:
|
||||||
|
full_model_dir = os.path.join(project_dir, output_dir)
|
||||||
|
dirs_to_create.add(full_model_dir)
|
||||||
|
|
||||||
|
# 统一创建目录(保留原data目录创建)
|
||||||
|
for dir_path in dirs_to_create:
|
||||||
|
try:
|
||||||
|
os.makedirs(dir_path, exist_ok=True)
|
||||||
|
except PermissionError:
|
||||||
|
print(f"警告:无法创建目录 {dir_path},请检查写入权限")
|
||||||
|
|
||||||
|
|
||||||
def get_config_file():
|
def get_config_file():
|
||||||
global default_config_file
|
global default_config_file
|
||||||
|
"""获取配置文件路径,优先使用私有配置文件(若存在)。
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: 配置文件路径(相对路径或默认路径)
|
||||||
|
"""
|
||||||
# 判断是否存在私有的配置文件
|
# 判断是否存在私有的配置文件
|
||||||
config_file = default_config_file
|
default_config = "config.yaml"
|
||||||
if os.path.exists(get_project_dir() + "data/." + default_config_file):
|
project_dir = get_project_dir()
|
||||||
config_file = "data/." + default_config_file
|
# 创建data目录(如果不存在)
|
||||||
return config_file
|
data_dir = os.path.join(project_dir, "data")
|
||||||
|
os.makedirs(data_dir, exist_ok=True)
|
||||||
|
# 配置文件路径
|
||||||
|
config_path = os.path.join(project_dir, "data", default_config)
|
||||||
|
# 优先使用私有配置,若不存在则使用默认配置
|
||||||
|
config_path = config_path if os.path.exists(config_path) else default_config
|
||||||
|
|
||||||
|
return config_path
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
"""加载配置文件"""
|
"""加载配置文件"""
|
||||||
parser = argparse.ArgumentParser(description="Server configuration")
|
parser = argparse.ArgumentParser(description="Server configuration")
|
||||||
config_file = get_config_file()
|
config_file = get_config_file()
|
||||||
|
|
||||||
parser.add_argument("--config_path", type=str, default=config_file)
|
parser.add_argument("--config_path", type=str, default=config_file)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return read_config(args.config_path)
|
config = read_config(args.config_path)
|
||||||
|
# 初始化目录
|
||||||
|
ensure_directories(config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def update_config(config):
|
def update_config(config):
|
||||||
|
|
|
||||||
3
main/xiaozhi-server/docker-compose.yml
Executable file → Normal file
3
main/xiaozhi-server/docker-compose.yml
Executable file → Normal file
|
|
@ -21,6 +21,9 @@ services:
|
||||||
- ./data:/opt/xiaozhi-esp32-server/data
|
- ./data:/opt/xiaozhi-esp32-server/data
|
||||||
# 模型文件挂接,很重要
|
# 模型文件挂接,很重要
|
||||||
- ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt
|
- ./models/SenseVoiceSmall/model.pt:/opt/xiaozhi-esp32-server/models/SenseVoiceSmall/model.pt
|
||||||
|
# tmp目录挂接,TTS和ASR的output_dir路径默认配置挂载,
|
||||||
|
# 若要映射本地目录,请修改config.yaml中的output_dir路径,key和value在此配置后面赋值增加即可
|
||||||
|
- ./tmp:/opt/xiaozhi-esp32-server/tmp
|
||||||
# #智控台还没开发好,还不能完全使用,会报很多错误,如果是非技术人员,请不要启用智控台服务
|
# #智控台还没开发好,还不能完全使用,会报很多错误,如果是非技术人员,请不要启用智控台服务
|
||||||
# xiaozhi-esp32-server-web:
|
# xiaozhi-esp32-server-web:
|
||||||
# image: ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest
|
# image: ghcr.nju.edu.cn/xinnan-tech/xiaozhi-esp32-server:web_latest
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue