mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 07:03:53 +08:00
update:优化配置及文档
This commit is contained in:
+19
-26
@@ -81,7 +81,7 @@ xiaozhi-server
|
||||
|
||||
下载完后,回到本教程继续往下。
|
||||
|
||||
##### 1.2.3.2 下载 config.yaml
|
||||
##### 1.2.3.2 创建 config.yaml
|
||||
|
||||
用浏览器打开[这个链接](../main/xiaozhi-server/config.yaml)。
|
||||
|
||||
@@ -224,43 +224,36 @@ python app.py
|
||||
## 配置项目
|
||||
|
||||
如果你的`xiaozhi-server`目录没有`data`,你需要创建`data`目录。
|
||||
如果你的`data`下面没有`.config.yaml`文件,你可以把`xiaozhi-server`目录下的`config.yaml`文件复制到`data`,并重命名为`.config.yaml`
|
||||
如果你的`data`下面没有`.config.yaml`文件,有两个方式,任选一种:
|
||||
|
||||
修改`xiaozhi-server`下`data`目录下的`.config.yaml`文件,配置本项目必须的一个配置。
|
||||
第一个方式:你可以把`xiaozhi-server`目录下的`config.yaml`文件复制到`data`,并重命名为`.config.yaml`。在此文件上修改
|
||||
|
||||
第二个方式:你也可以创建在`data`目录下手动创建`.config.yaml`空文件,然后在这个文件中增加必要的配置信息,系统会优先读取`.config.yaml`文件的配置,如果`.config.yaml`没有配置的,系统会自动去加载`xiaozhi-server`目录下的`config.yaml`的配置。推荐使用这种方式,这种方式是最简洁的方式。
|
||||
|
||||
- 默认的LLM使用的是`ChatGLMLLM`,你需要配置密钥,因为他们的模型,虽然有免费的,但是仍要去[官网](https://bigmodel.cn/usercenter/proj-mgmt/apikeys)注册密钥,才能启动。
|
||||
|
||||
配置说明:这里是各个功能使用的默认组件,例如LLM默认使用`ChatGLMLLM`模型。如果需要切换模型,就是改对应的名称。
|
||||
本项目的默认配置仅是成本最低配置(`glm-4-flash`和`EdgeTTS`都是免费的),如果需要更优的更快的搭配,需要自己结合部署环境切换各组件的使用。
|
||||
以下是一个能正常跑起来的,最简单的`.config.yaml`配置示例
|
||||
|
||||
```
|
||||
server:
|
||||
websocket: ws://你的ip或者域名:端口号/xiaozhi/v1/
|
||||
prompt: |
|
||||
我是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。
|
||||
我的男朋友是一个程序员,梦想是开发出一个机器人,能够帮助人们解决生活中的各种问题。
|
||||
我是一个喜欢哈哈大笑的女孩,爱东说西说吹牛,不合逻辑的也照吹,就要逗别人开心。
|
||||
请你像一个人一样说话,请勿返回配置xml及其他特殊字符。
|
||||
|
||||
selected_module:
|
||||
VAD: SileroVAD
|
||||
ASR: FunASR
|
||||
LLM: ChatGLMLLM
|
||||
TTS: EdgeTTS
|
||||
# 默认不开启记忆,如需开启请看配置文件里的描述
|
||||
Memory: nomem
|
||||
# 默认不开启意图识别,如需开启请看配置文件里的描述
|
||||
Intent: nointent
|
||||
```
|
||||
LLM: DoubaoLLM
|
||||
|
||||
比如修改`LLM`使用的组件,就看本项目支持哪些`LLM` API接口,当前支持的是`openai`、`dify`。欢迎验证和支持更多LLM平台的接口。
|
||||
使用时,在`selected_module`修改成对应的如下LLM配置的名称:
|
||||
|
||||
```
|
||||
LLM:
|
||||
DeepSeekLLM:
|
||||
type: openai
|
||||
...
|
||||
ChatGLMLLM:
|
||||
type: openai
|
||||
...
|
||||
DifyLLM:
|
||||
type: dify
|
||||
...
|
||||
api_key: xxxxxxxxxxxxxxx.xxxxxx
|
||||
```
|
||||
|
||||
建议先将最简单的配置运行起来,然后再去`xiaozhi/config.yaml`阅读配置的使用说明。
|
||||
比如你要换更换模型,修改`selected_module`下的配置就行。
|
||||
|
||||
## 模型文件
|
||||
|
||||
本项目语音识别模型,默认使用`SenseVoiceSmall`模型,进行语音转文字。因为模型较大,需要独立下载,下载后把`model.pt`
|
||||
|
||||
@@ -10,9 +10,6 @@ import lombok.Data;
|
||||
@Data
|
||||
@Schema(description = "获取智能体模型配置DTO")
|
||||
public class AgentModelsDTO {
|
||||
@NotBlank(message = "密钥不能为空")
|
||||
@Schema(description = "密钥")
|
||||
private String secret;
|
||||
|
||||
@NotBlank(message = "设备MAC地址不能为空")
|
||||
@Schema(description = "设备MAC地址")
|
||||
|
||||
+6
-6
@@ -2,8 +2,6 @@ package xiaozhi.modules.security.secret;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -12,6 +10,8 @@ import jakarta.servlet.ServletRequest;
|
||||
import jakarta.servlet.ServletResponse;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import xiaozhi.common.constant.Constant;
|
||||
import xiaozhi.common.exception.ErrorCode;
|
||||
import xiaozhi.common.utils.HttpContextUtils;
|
||||
@@ -55,7 +55,7 @@ public class ServerSecretFilter extends AuthenticatingFilter {
|
||||
String token = getRequestToken((HttpServletRequest) servletRequest);
|
||||
if (StringUtils.isBlank(token)) {
|
||||
// token为空,返回401
|
||||
this.sendUnauthorizedResponse((HttpServletResponse) servletResponse, "Authorization token不能为空");
|
||||
this.sendUnauthorizedResponse((HttpServletResponse) servletResponse, "服务器密钥不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ServerSecretFilter extends AuthenticatingFilter {
|
||||
String serverSecret = getServerSecret();
|
||||
if (StringUtils.isBlank(serverSecret) || !serverSecret.equals(token)) {
|
||||
// token无效,返回401
|
||||
this.sendUnauthorizedResponse((HttpServletResponse) servletResponse, "无效的Authorization token");
|
||||
this.sendUnauthorizedResponse((HttpServletResponse) servletResponse, "无效的服务器密钥");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ public class ServerSecretFilter extends AuthenticatingFilter {
|
||||
response.setContentType("application/json;charset=utf-8");
|
||||
response.setHeader("Access-Control-Allow-Credentials", "true");
|
||||
response.setHeader("Access-Control-Allow-Origin", HttpContextUtils.getOrigin());
|
||||
|
||||
|
||||
try {
|
||||
String json = JsonUtils.toJsonString(new Result<Void>().error(ErrorCode.UNAUTHORIZED, message));
|
||||
response.getWriter().print(json);
|
||||
@@ -102,4 +102,4 @@ public class ServerSecretFilter extends AuthenticatingFilter {
|
||||
private String getServerSecret() {
|
||||
return sysParamsService.getValue(Constant.SERVER_SECRET, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ INSERT INTO `ai_model_provider` (`id`, `model_type`, `provider_code`, `name`, `f
|
||||
|
||||
-- TTS模型供应器
|
||||
('SYSTEM_TTS_edge', 'TTS', 'edge', 'Edge TTS', '[{"key":"voice","label":"音色","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"}]', 1, 1, NOW(), 1, NOW()),
|
||||
('SYSTEM_TTS_doubao', 'TTS', 'doubao', '火山引擎TTS', '[{"key": "api_url","label": "API地址","type": "string"},{"key": "voice","label": "音色","type": "string"},{"key": "output_dir","label": "输出目录","type": "string"},{"key": "authorization","label": "授权","type": "string"},{"key": "appid","label": "应用ID","type": "string"},{"key": "access_token","label": "访问令牌","type": "string"},{"key": "cluster","label": "集群","type": "string"},{"key": "speed_ratio","label": "语速","type": "number"},{"key": "volume_ratio","label": "音量","type": "number"},{"key": "pitch_ratio","label": "音高","type": "number"}]', 2, 1, NOW(), 1, NOW()),
|
||||
('SYSTEM_TTS_doubao', 'TTS', 'doubao', '火山引擎TTS', '[{"key":"api_url","label":"API地址","type":"string"},{"key":"voice","label":"音色","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"},{"key":"authorization","label":"授权","type":"string"},{"key":"appid","label":"应用ID","type":"string"},{"key":"access_token","label":"访问令牌","type":"string"},{"key":"cluster","label":"集群","type":"string"}]', 2, 1, NOW(), 1, NOW()),
|
||||
('SYSTEM_TTS_siliconflow', 'TTS', 'siliconflow', '硅基流动TTS', '[{"key":"model","label":"模型","type":"string"},{"key":"voice","label":"音色","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"},{"key":"access_token","label":"访问令牌","type":"string"},{"key":"response_format","label":"响应格式","type":"string"}]', 3, 1, NOW(), 1, NOW()),
|
||||
('SYSTEM_TTS_cozecn', 'TTS', 'cozecn', 'COZECN TTS', '[{"key":"voice","label":"音色","type":"string"},{"key":"output_dir","label":"输出目录","type":"string"},{"key":"access_token","label":"访问令牌","type":"string"},{"key":"response_format","label":"响应格式","type":"string"}]', 4, 1, NOW(), 1, NOW()),
|
||||
('SYSTEM_TTS_fishspeech', 'TTS', 'fishspeech', 'FishSpeech TTS', '[{"key":"output_dir","label":"输出目录","type":"string"},{"key":"response_format","label":"响应格式","type":"string"},{"key":"reference_id","label":"参考ID","type":"string"},{"key":"reference_audio","label":"参考音频","type":"dict","dict_name":"reference_audio"},{"key":"reference_text","label":"参考文本","type":"dict","dict_name":"reference_text"},{"key":"normalize","label":"是否标准化","type":"boolean"},{"key":"max_new_tokens","label":"最大新令牌数","type":"number"},{"key":"chunk_length","label":"块长度","type":"number"},{"key":"top_p","label":"top_p值","type":"number"},{"key":"repetition_penalty","label":"重复惩罚","type":"number"},{"key":"temperature","label":"温度","type":"number"},{"key":"streaming","label":"是否流式","type":"boolean"},{"key":"use_memory_cache","label":"是否使用内存缓存","type":"string"},{"key":"seed","label":"种子","type":"number"},{"key":"channels","label":"通道数","type":"number"},{"key":"rate","label":"采样率","type":"number"},{"key":"api_key","label":"API密钥","type":"string"},{"key":"api_url","label":"API地址","type":"string"}]', 5, 1, NOW(), 1, NOW()),
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
update `ai_model_provider` set `fields` =
|
||||
'[{"key": "api_url","label": "API地址","type": "string"},{"key": "voice","label": "音色","type": "string"},{"key": "output_dir","label": "输出目录","type": "string"},{"key": "authorization","label": "授权","type": "string"},{"key": "appid","label": "应用ID","type": "string"},{"key": "access_token","label": "访问令牌","type": "string"},{"key": "cluster","label": "集群","type": "string"},{"key": "speed_ratio","label": "语速","type": "number"},{"key": "volume_ratio","label": "音量","type": "number"},{"key": "pitch_ratio","label": "音高","type": "number"}]'
|
||||
where `id` = 'SYSTEM_TTS_doubao';
|
||||
@@ -85,4 +85,11 @@ databaseChangeLog:
|
||||
changes:
|
||||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202504291043.sql
|
||||
path: classpath:db/changelog/202504291043.sql
|
||||
- changeSet:
|
||||
id: 202504301339
|
||||
author: Goody
|
||||
changes:
|
||||
- sqlFile:
|
||||
encoding: utf8
|
||||
path: classpath:db/changelog/202504301339.sql
|
||||
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
import sys
|
||||
import signal
|
||||
from config.settings import load_config, check_config_file
|
||||
from config.settings import load_config
|
||||
from core.websocket_server import WebSocketServer
|
||||
from core.ota_server import SimpleOtaServer
|
||||
from core.utils.util import check_ffmpeg_installed
|
||||
@@ -31,7 +31,6 @@ async def wait_for_exit():
|
||||
|
||||
|
||||
async def main():
|
||||
check_config_file()
|
||||
check_ffmpeg_installed()
|
||||
config = load_config()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 如果您是一名开发者,建议阅读以下内容。如果不是开发者,可以忽略这部分内容。
|
||||
# 在开发中,在项目根目录创建data目录,将【config.yaml】复制一份,改成【.config.yaml】,放进data目录中
|
||||
# 系统会优先读取【data/.config.yaml】文件的配置。
|
||||
# 这样做,可以避免在提交代码的时候,错误地提交密钥信息,保护您的密钥安全。
|
||||
# 在开发中,请在项目根目录创建data目录,然后在data目录创建名称为【.config.yaml】的空文件
|
||||
# 然后你想修改覆盖修改什么配置,就修改【.config.yaml】文件,而不是修改【config.yaml】文件
|
||||
# 系统会优先读取【data/.config.yaml】文件的配置,如果【.config.yaml】文件里的配置不存在,系统会自动去读取【config.yaml】文件的配置。
|
||||
# 这样做,可以最简化配置,保护您的密钥安全。
|
||||
|
||||
# #####################################################################################
|
||||
# #############################以下是服务器基本运行配置####################################
|
||||
@@ -158,7 +158,7 @@ selected_module:
|
||||
# 不想开通意图识别,就设置成:nointent
|
||||
# 意图识别可使用intent_llm。优点:通用性强,缺点:增加串行前置意图识别模块,会增加处理时间,这个意图识别暂时不支持控制音量大小等iot操作
|
||||
# 意图识别可使用function_call,缺点:需要所选择的LLM支持function_call,优点:按需调用工具、速度快,理论上能全部操作所有iot指令
|
||||
# 默认免费的ChatGLMLLM就已经支持function_call,但是如果像追求稳定建议把LLM设置成:DoubaoLLM,使用的具体model_name是:doubao-pro-32k-functioncall-241028
|
||||
# 默认免费的ChatGLMLLM就已经支持function_call,但是如果像追求稳定建议把LLM设置成:DoubaoLLM,使用的具体model_name是:doubao-1-5-pro-32k-250115
|
||||
Intent: function_call
|
||||
|
||||
# 意图识别,是用于理解用户意图的模块,例如:播放音乐
|
||||
|
||||
@@ -31,37 +31,19 @@ def load_config():
|
||||
|
||||
# 加载默认配置
|
||||
default_config = read_config(default_config_path)
|
||||
custom_config = read_config(custom_config_path)
|
||||
|
||||
# 加载用户自定义配置(如果存在)
|
||||
if os.path.exists(custom_config_path):
|
||||
custom_config = read_config(custom_config_path)
|
||||
if custom_config.get("manager-api", {}).get("url"):
|
||||
config = get_config_from_api(custom_config)
|
||||
else:
|
||||
# 合并配置
|
||||
config = merge_configs(default_config, custom_config)
|
||||
else:
|
||||
config = default_config
|
||||
|
||||
if config.get("manager-api", {}).get("url"):
|
||||
config = get_config_from_api(config)
|
||||
|
||||
# 初始化目录
|
||||
ensure_directories(config)
|
||||
_config_cache = config
|
||||
return config
|
||||
|
||||
|
||||
def get_config_file():
|
||||
"""获取配置文件路径,优先使用私有配置文件(若存在)。
|
||||
|
||||
Returns:
|
||||
str: 配置文件路径(相对路径或默认路径)
|
||||
"""
|
||||
default_config_file = "config.yaml"
|
||||
config_file = default_config_file
|
||||
if os.path.exists(get_project_dir() + "data/." + default_config_file):
|
||||
config_file = "data/." + default_config_file
|
||||
return config_file
|
||||
|
||||
|
||||
def get_config_from_api(config):
|
||||
"""从Java API获取配置"""
|
||||
# 初始化API客户端
|
||||
@@ -128,23 +110,29 @@ def ensure_directories(config):
|
||||
def merge_configs(default_config, custom_config):
|
||||
"""
|
||||
递归合并配置,custom_config优先级更高
|
||||
|
||||
|
||||
Args:
|
||||
default_config: 默认配置
|
||||
custom_config: 用户自定义配置
|
||||
|
||||
|
||||
Returns:
|
||||
合并后的配置
|
||||
"""
|
||||
if not isinstance(default_config, Mapping) or not isinstance(custom_config, Mapping):
|
||||
if not isinstance(default_config, Mapping) or not isinstance(
|
||||
custom_config, Mapping
|
||||
):
|
||||
return custom_config
|
||||
|
||||
|
||||
merged = dict(default_config)
|
||||
|
||||
|
||||
for key, value in custom_config.items():
|
||||
if key in merged and isinstance(merged[key], Mapping) and isinstance(value, Mapping):
|
||||
if (
|
||||
key in merged
|
||||
and isinstance(merged[key], Mapping)
|
||||
and isinstance(value, Mapping)
|
||||
):
|
||||
merged[key] = merge_configs(merged[key], value)
|
||||
else:
|
||||
merged[key] = value
|
||||
|
||||
return merged
|
||||
|
||||
return merged
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import sys
|
||||
from loguru import logger
|
||||
from config.config_loader import load_config
|
||||
from config.settings import check_config_file
|
||||
|
||||
SERVER_VERSION = "0.3.13"
|
||||
|
||||
@@ -32,6 +33,7 @@ def formatter(record):
|
||||
|
||||
|
||||
def setup_logging():
|
||||
check_config_file()
|
||||
"""从配置文件中读取日志配置,并设置日志输出格式和级别"""
|
||||
config = load_config()
|
||||
log_config = config["log"]
|
||||
|
||||
@@ -1,53 +1,33 @@
|
||||
import os
|
||||
from collections.abc import Mapping
|
||||
from config import logger
|
||||
from config.config_loader import read_config, get_project_dir, load_config
|
||||
|
||||
TAG = __name__
|
||||
logger = logger.setup_logging()
|
||||
|
||||
default_config_file = "config.yaml"
|
||||
|
||||
|
||||
def find_missing_keys(new_config, old_config, parent_key=""):
|
||||
"""
|
||||
递归查找缺失的配置项
|
||||
返回格式:[缺失配置路径]
|
||||
"""
|
||||
missing_keys = []
|
||||
|
||||
if not isinstance(new_config, Mapping):
|
||||
return missing_keys
|
||||
|
||||
for key, value in new_config.items():
|
||||
# 构建当前配置路径
|
||||
full_path = f"{parent_key}.{key}" if parent_key else key
|
||||
|
||||
# 检查键是否存在
|
||||
if key not in old_config:
|
||||
missing_keys.append(full_path)
|
||||
continue
|
||||
|
||||
# 递归检查嵌套字典
|
||||
if isinstance(value, Mapping):
|
||||
sub_missing = find_missing_keys(
|
||||
value, old_config[key], parent_key=full_path
|
||||
)
|
||||
missing_keys.extend(sub_missing)
|
||||
return missing_keys
|
||||
config_file_valid = False
|
||||
|
||||
|
||||
def check_config_file():
|
||||
global config_file_valid
|
||||
if config_file_valid:
|
||||
return
|
||||
"""
|
||||
简化的配置检查,仅提示用户配置文件的使用情况
|
||||
"""
|
||||
custom_config_file = get_project_dir() + "data/." + default_config_file
|
||||
if not os.path.exists(custom_config_file):
|
||||
logger.bind(tag=TAG).info("提示: 使用默认配置文件。如需自定义配置,请创建 data/.config.yaml 文件")
|
||||
else:
|
||||
logger.bind(tag=TAG).info(f"提示: 使用自定义配置文件 data/.config.yaml,配置将覆盖默认值")
|
||||
|
||||
raise FileNotFoundError(
|
||||
"找不到data/.config.yaml文件,请按教程确认该配置文件是否存在"
|
||||
)
|
||||
|
||||
# 检查是否从API读取配置
|
||||
config = load_config()
|
||||
if config.get("read_config_from_api", False):
|
||||
logger.bind(tag=TAG).info("提示: 从API获取配置")
|
||||
print("从API读取配置")
|
||||
old_config_origin = read_config(custom_config_file)
|
||||
if old_config_origin.get("selected_module") is not None:
|
||||
error_msg = "您的配置文件好像既包含智控台的配置又包含本地配置:\n"
|
||||
error_msg += "\n建议您:\n"
|
||||
error_msg += "1、将根目录的config_from_api.yaml文件复制到data下,重命名为.config.yaml\n"
|
||||
error_msg += "2、按教程配置好接口地址和密钥\n"
|
||||
raise ValueError(error_msg)
|
||||
config_file_valid = True
|
||||
|
||||
@@ -53,6 +53,8 @@ async def handleTextMessage(conn, message):
|
||||
# 如果是唤醒词,且关闭了唤醒词回复,就不用回答
|
||||
await send_stt_message(conn, text)
|
||||
await send_tts_message(conn, "stop", None)
|
||||
elif is_wakeup_words:
|
||||
await startToChat(conn, "嘿,你好呀")
|
||||
else:
|
||||
# 否则需要LLM对文字内容进行答复
|
||||
await startToChat(conn, text)
|
||||
|
||||
@@ -27,9 +27,14 @@ class TTSProvider(TTSProviderBase):
|
||||
else:
|
||||
self.voice = config.get("voice")
|
||||
|
||||
self.speed_ratio = float(config.get("speed_ratio", 0.1))
|
||||
self.volume_ratio = float(config.get("volume_ratio", 0.1))
|
||||
self.pitch_ratio = float(config.get("pitch_ratio", 0.1))
|
||||
# 处理空字符串的情况
|
||||
speed_ratio = config.get("speed_ratio", "1.0")
|
||||
volume_ratio = config.get("volume_ratio", "1.0")
|
||||
pitch_ratio = config.get("pitch_ratio", "1.0")
|
||||
|
||||
self.speed_ratio = float(speed_ratio) if speed_ratio else 1.0
|
||||
self.volume_ratio = float(volume_ratio) if volume_ratio else 1.0
|
||||
self.pitch_ratio = float(pitch_ratio) if pitch_ratio else 1.0
|
||||
|
||||
self.api_url = config.get("api_url")
|
||||
self.authorization = config.get("authorization")
|
||||
|
||||
@@ -89,18 +89,35 @@ class TTSProvider(TTSProviderBase):
|
||||
self.reference_audio = parse_string_to_list(config.get("reference_audio"))
|
||||
self.reference_text = parse_string_to_list(config.get("reference_text"))
|
||||
self.format = config.get("format", "wav")
|
||||
self.channels = int(config.get("channels", 1))
|
||||
self.rate = int(config.get("rate", 44100))
|
||||
|
||||
self.api_key = config.get("api_key", "YOUR_API_KEY")
|
||||
have_key = check_model_key("FishSpeech TTS", self.api_key)
|
||||
if not have_key:
|
||||
return
|
||||
self.normalize = config.get("normalize", True)
|
||||
self.max_new_tokens = int(config.get("max_new_tokens", 1024))
|
||||
self.chunk_length = int(config.get("chunk_length", 200))
|
||||
self.top_p = float(config.get("top_p", 0.7))
|
||||
self.repetition_penalty = float(config.get("repetition_penalty", 1.2))
|
||||
self.temperature = float(config.get("temperature", 0.7))
|
||||
|
||||
# 处理空字符串的情况
|
||||
channels = config.get("channels", "1")
|
||||
rate = config.get("rate", "44100")
|
||||
max_new_tokens = config.get("max_new_tokens", "1024")
|
||||
chunk_length = config.get("chunk_length", "200")
|
||||
|
||||
self.channels = int(channels) if channels else 1
|
||||
self.rate = int(rate) if rate else 44100
|
||||
self.max_new_tokens = int(max_new_tokens) if max_new_tokens else 1024
|
||||
self.chunk_length = int(chunk_length) if chunk_length else 200
|
||||
|
||||
# 处理空字符串的情况
|
||||
top_p = config.get("top_p", "0.7")
|
||||
temperature = config.get("temperature", "0.7")
|
||||
repetition_penalty = config.get("repetition_penalty", "1.2")
|
||||
|
||||
self.top_p = float(top_p) if top_p else 0.7
|
||||
self.temperature = float(temperature) if temperature else 0.7
|
||||
self.repetition_penalty = (
|
||||
float(repetition_penalty) if repetition_penalty else 1.2
|
||||
)
|
||||
|
||||
self.streaming = str(config.get("streaming", False)).lower() in (
|
||||
"true",
|
||||
"1",
|
||||
|
||||
@@ -20,12 +20,29 @@ class TTSProvider(TTSProviderBase):
|
||||
self.ref_audio_path = config.get("ref_audio_path")
|
||||
self.prompt_text = config.get("prompt_text")
|
||||
self.prompt_lang = config.get("prompt_lang", "zh")
|
||||
self.top_k = int(config.get("top_k", 5))
|
||||
self.top_p = float(config.get("top_p", 1))
|
||||
self.temperature = float(config.get("temperature", 1))
|
||||
|
||||
# 处理空字符串的情况
|
||||
top_k = config.get("top_k", "5")
|
||||
top_p = config.get("top_p", "1")
|
||||
temperature = config.get("temperature", "1")
|
||||
batch_threshold = config.get("batch_threshold", "0.75")
|
||||
batch_size = config.get("batch_size", "1")
|
||||
speed_factor = config.get("speed_factor", "1.0")
|
||||
seed = config.get("seed", "-1")
|
||||
repetition_penalty = config.get("repetition_penalty", "1.35")
|
||||
|
||||
self.top_k = int(top_k) if top_k else 5
|
||||
self.top_p = float(top_p) if top_p else 1
|
||||
self.temperature = float(temperature) if temperature else 1
|
||||
self.batch_threshold = float(batch_threshold) if batch_threshold else 0.75
|
||||
self.batch_size = int(batch_size) if batch_size else 1
|
||||
self.speed_factor = float(speed_factor) if speed_factor else 1.0
|
||||
self.seed = int(seed) if seed else -1
|
||||
self.repetition_penalty = (
|
||||
float(repetition_penalty) if repetition_penalty else 1.35
|
||||
)
|
||||
|
||||
self.text_split_method = config.get("text_split_method", "cut0")
|
||||
self.batch_size = int(config.get("batch_size", 1))
|
||||
self.batch_threshold = float(config.get("batch_threshold", 0.75))
|
||||
|
||||
self.split_bucket = str(config.get("split_bucket", True)).lower() in (
|
||||
"true",
|
||||
@@ -37,19 +54,19 @@ class TTSProvider(TTSProviderBase):
|
||||
"1",
|
||||
"yes",
|
||||
)
|
||||
self.speed_factor = float(config.get("speed_factor", 1.0))
|
||||
|
||||
self.streaming_mode = str(config.get("streaming_mode", False)).lower() in (
|
||||
"true",
|
||||
"1",
|
||||
"yes",
|
||||
)
|
||||
self.seed = int(config.get("seed", -1))
|
||||
|
||||
self.parallel_infer = str(config.get("parallel_infer", True)).lower() in (
|
||||
"true",
|
||||
"1",
|
||||
"yes",
|
||||
)
|
||||
self.repetition_penalty = float(config.get("repetition_penalty", 1.35))
|
||||
|
||||
self.aux_ref_audio_paths = parse_string_to_list(
|
||||
config.get("aux_ref_audio_paths")
|
||||
)
|
||||
|
||||
@@ -18,13 +18,22 @@ class TTSProvider(TTSProviderBase):
|
||||
self.prompt_text = config.get("prompt_text")
|
||||
self.prompt_language = config.get("prompt_language")
|
||||
self.text_language = config.get("text_language", "audo")
|
||||
self.top_k = int(config.get("top_k", 15))
|
||||
self.top_p = float(config.get("top_p", 1.0))
|
||||
self.temperature = float(config.get("temperature", 1.0))
|
||||
|
||||
# 处理空字符串的情况
|
||||
top_k = config.get("top_k", "15")
|
||||
top_p = config.get("top_p", "1.0")
|
||||
temperature = config.get("temperature", "1.0")
|
||||
sample_steps = config.get("sample_steps", "32")
|
||||
speed = config.get("speed", "1.0")
|
||||
|
||||
self.top_k = int(top_k) if top_k else 15
|
||||
self.top_p = float(top_p) if top_p else 1.0
|
||||
self.temperature = float(temperature) if temperature else 1.0
|
||||
self.sample_steps = int(sample_steps) if sample_steps else 32
|
||||
self.speed = float(speed) if speed else 1.0
|
||||
|
||||
self.cut_punc = config.get("cut_punc", "")
|
||||
self.speed = float(config.get("speed", 1.0))
|
||||
self.inp_refs = parse_string_to_list(config.get("inp_refs"))
|
||||
self.sample_steps = int(config.get("sample_steps", 32))
|
||||
self.if_sr = str(config.get("if_sr", False)).lower() in ("true", "1", "yes")
|
||||
|
||||
def generate_filename(self, extension=".wav"):
|
||||
|
||||
@@ -21,7 +21,11 @@ class TTSProvider(TTSProviderBase):
|
||||
else:
|
||||
self.voice = config.get("voice", "alloy")
|
||||
self.response_format = "wav"
|
||||
self.speed = float(config.get("speed", 1.0))
|
||||
|
||||
# 处理空字符串的情况
|
||||
speed = config.get("speed", "1.0")
|
||||
self.speed = float(speed) if speed else 1.0
|
||||
|
||||
self.output_file = config.get("output_dir", "tmp/")
|
||||
check_model_key("TTS", self.api_key)
|
||||
|
||||
|
||||
@@ -21,8 +21,15 @@ class VADProvider(VADProviderBase):
|
||||
(get_speech_timestamps, _, _, _, _) = self.utils
|
||||
|
||||
self.decoder = opuslib_next.Decoder(16000, 1)
|
||||
self.vad_threshold = float(config.get("threshold", 0.5))
|
||||
self.silence_threshold_ms = int(config.get("min_silence_duration_ms", 1000))
|
||||
|
||||
# 处理空字符串的情况
|
||||
threshold = config.get("threshold", "0.5")
|
||||
min_silence_duration_ms = config.get("min_silence_duration_ms", "1000")
|
||||
|
||||
self.vad_threshold = float(threshold) if threshold else 0.5
|
||||
self.silence_threshold_ms = (
|
||||
int(min_silence_duration_ms) if min_silence_duration_ms else 1000
|
||||
)
|
||||
|
||||
def is_vad(self, conn, opus_packet):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user