Skip to content

Commit ee70e07

Browse files
committed
✨ feat(config): 添加 tts_prefix 配置项
- 在 Config 类中添加 tts_prefix 配置项 - 优化 matcher.py 中的命令前缀处理逻辑 - 更新 README.md 中的配置项说明 - 将版本号从 0.3.1 升级到 0.3.2
1 parent a4cd0d5 commit ee70e07

File tree

4 files changed

+35
-30
lines changed

4 files changed

+35
-30
lines changed

README.md

+18-17
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ git clone https://github.com/Cvandia/nonebot-plugin-fishspeech-tts
7373

7474
**在.env中添加以下配置**
7575

76-
| 基础配置 | 类型 |必填项| 默认值 | 说明 |
77-
|:-----:|:----:|:----:|:---:|:----:|
78-
|tts_is_online|bool||True|是否使用云端api|
79-
|tts_chunk_length|literal||"normal"|请求时音频分片长度,默认为normal,可选:short, normal, long|
80-
|tts_audio_path|str||"./data/参考音频"|语音素材路径,默认为"./data/参考音频"|
76+
| 基础配置 | 类型 | 必填项 | 默认值 | 说明 |
77+
| :--------------: | :-----: | :----: | :---------------: | :---------------------------------------------------------: |
78+
| tts_is_online | bool || True | 是否使用云端api |
79+
| tts_chunk_length | literal || "normal" | 请求时音频分片长度,默认为normal,可选:short, normal, long |
80+
| tts_audio_path | str || "./data/参考音频" | 语音素材路径,默认为"./data/参考音频" |
81+
| tts_prefix | str || None | 语音素材前缀,默认为None |
8182

8283
**注:参考音频的文件名格式为:[角色名]音频对应的文字标签.[音频后缀名]**
8384

@@ -90,18 +91,18 @@ ___
9091

9192
如果你想使用官方的api,请将配置项`tts_is_online`设置为`True`并配置以下
9293

93-
| 配置项 | 类型 | 必填项 | 默认值 | 说明 |
94-
|:-----:|:----:|:----:|:---:|:----:|
95-
|online_authorization|str||"xxxxx"|官网api鉴权秘钥,详见[链接](https://fish.audio/zh-CN/go-api/api-keys/)|
96-
|online_model_first|bool||True|如果你想调用官方模型,通过自己的参考音频,定制角色音色,将此项设为`False`。当然,如果你没有准备参考音频,也会调用官网已经有的音色,具体详见[链接](https://fish.audio/zh-CN/)|
94+
| 配置项 | 类型 | 必填项 | 默认值 | 说明 |
95+
| :------------------: | :---: | :----: | :-----: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
96+
| online_authorization | str || "xxxxx" | 官网api鉴权秘钥,详见[链接](https://fish.audio/zh-CN/go-api/api-keys/) |
97+
| online_model_first | bool || True | 如果你想调用官方模型,通过自己的参考音频,定制角色音色,将此项设为`False`。当然,如果你没有准备参考音频,也会调用官网已经有的音色,具体详见[链接](https://fish.audio/zh-CN/) |
9798

9899
---
99100

100101
如果你想使用[自搭](#离线搭建fish-speech)或者其他的[fish-speech](https://github.com/fishaudio/fish-speech)项目的api,请将配置项`tts_is_online`设置为`Fasle`并配置以下
101102

102-
| 配置项 | 类型 | 必填项 | 默认值 | 说明 |
103-
|:----:|:----:|:----:|:---:|:----:|
104-
|offline_api_url|str||"http://127.0.0.1:8080"|你的`fish-speech`api地址|
103+
| 配置项 | 类型 | 必填项 | 默认值 | 说明 |
104+
| :-------------: | :---: | :----: | :---------------------: | :----------------------: |
105+
| offline_api_url | str || "http://127.0.0.1:8080" | 你的`fish-speech`api地址 |
105106

106107
## ⭐ 使用
107108

@@ -110,11 +111,11 @@ ___
110111
111112
### 指令:
112113

113-
| 指令 | 需要@ | 范围 | 说明 |权限|
114-
|:---:|:---:|:---:|:---:|:---:|
115-
|xxx说xxx|根据配置|all|tts语音生成|all|
116-
|语音列表||all|获取所有角色列表|all|
117-
|语音余额||all|查询api余额|all|
114+
| 指令 | 需要@ | 范围 | 说明 | 权限 |
115+
| :------: | :------: | :---: | :--------------: | :---: |
116+
| xxx说xxx | 根据配置 | all | tts语音生成 | all |
117+
| 语音列表 || all | 获取所有角色列表 | all |
118+
| 语音余额 || all | 查询api余额 | all |
118119

119120
## 🌙 Todo
120121
- [x] 添加更多配置项

nonebot_plugin_fishspeech_tts/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Config(BaseModel):
1313
tts_is_online: bool = True
1414
tts_chunk_length: Literal["normal", "short", "long"] = "normal"
1515
tts_audio_path: str = "./data/参考音频"
16+
tts_prefix: Optional[str] = None
1617

1718
# 区分配置
1819
online_authorization: Optional[str] = "xxxxx"

nonebot_plugin_fishspeech_tts/matcher.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,25 @@
1414
"""
1515

1616

17-
IS_ONLINE = config.tts_is_online # True 为在线模式,False 为本地模式
18-
PREFIX = list(get_driver().config.command_start)[0] # 命令前缀
19-
20-
21-
chunk_length_map = {
17+
is_online = config.tts_is_online # True 为在线模式,False 为本地模式
18+
prefix = (
19+
config.tts_prefix
20+
if config.tts_prefix
21+
else list(get_driver().config.command_start)[0]
22+
) # 命令前缀
23+
24+
CHUNKLENGTH_MAP = {
2225
"normal": ChunkLength.NORMAL,
2326
"short": ChunkLength.SHORT,
2427
"long": ChunkLength.LONG,
2528
}
2629

27-
CHUNKLENGTH = chunk_length_map.get(
30+
chunk_length = CHUNKLENGTH_MAP.get(
2831
config.tts_chunk_length, ChunkLength.NORMAL
2932
) # 请求语音长度
3033

3134

32-
tts_handler = on_regex(rf"^{PREFIX}(.+?)说([\s\S]*)", block=False)
35+
tts_handler = on_regex(rf"^{prefix}(.+?)说([\s\S]*)", block=False)
3336
speaker_list = on_command(
3437
"语音列表", aliases={"语音角色列表"}, block=True, rule=to_me()
3538
)
@@ -54,16 +57,16 @@ async def tts_handle(message: UniMsg):
5457
try:
5558
fish_audio_api = FishAudioAPI()
5659
fish_speech_api = FishSpeechAPI()
57-
if IS_ONLINE:
60+
if is_online:
5861
await tts_handler.send("正在通过在线api合成语音, 请稍等")
5962
request = await fish_audio_api.generate_servettsrequest(
60-
text, speaker, CHUNKLENGTH
63+
text, speaker, chunk_length
6164
)
6265
audio = await fish_audio_api.generate_tts(request)
6366
else:
6467
await tts_handler.send("正在通过本地api合成语音, 请稍等")
6568
request = await fish_speech_api.generate_servettsrequest(
66-
text, speaker, CHUNKLENGTH
69+
text, speaker, chunk_length
6770
)
6871
audio = await fish_speech_api.generate_tts(request)
6972
await UniMessage.voice(raw=audio).finish()
@@ -77,7 +80,7 @@ async def speaker_list_handle(event: Event):
7780
try:
7881
fish_audio_api = FishAudioAPI()
7982
fish_speech_api = FishSpeechAPI()
80-
if IS_ONLINE:
83+
if is_online:
8184
_list = fish_audio_api.get_speaker_list()
8285
await speaker_list.finish("语音角色列表: " + ", ".join(_list))
8386
else:
@@ -91,7 +94,7 @@ async def speaker_list_handle(event: Event):
9194
async def balance_handle(event: Event):
9295
try:
9396
fish_audio_api = FishAudioAPI()
94-
if IS_ONLINE:
97+
if is_online:
9598
await balance.send("正在查询在线语音余额, 请稍等")
9699
balance_float = await fish_audio_api.get_balance()
97100
await balance.finish(f"语音余额为: {balance_float}")

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "nonebot-plugin-fishspeech-tts"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
description = "小样本TTS,通过调用在线或本地api发送TTS语音"
55
authors = ["Cvandia <106718176+Cvandia@users.noreply.github.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)