Skip to content

Commit

Permalink
Merge pull request #78 from sudoskys/tts_azure_vits
Browse files Browse the repository at this point in the history
TTS 异步支持,添加网络请求库,AZURE 添加
  • Loading branch information
FrostleafChan committed Dec 20, 2022
2 parents af0272d + 89cbca4 commit 6d62d99
Show file tree
Hide file tree
Showing 7 changed files with 354 additions and 149 deletions.
68 changes: 47 additions & 21 deletions App/Event.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,64 @@ def save_csonfig():
json.dump(_csonfig, f, indent=4, ensure_ascii=False)


def TTS_Support_Check(text, user_id):
async def TTS_Support_Check(text, user_id):
global _tts_conf
"""
处理消息文本并构造请求返回字节流或者空。隶属 Event 文件
:return:
"""
from openai_async.utils.Talk import Talk
if not _tts_conf["status"]:
return
lang_type = Talk.get_language(text)
if not lang_type in ["chinese"]:
return
if _tts_conf["type"] == "vits":
from openai_async.utils.Talk import Talk
if Talk.get_language(text) != "chinese":
return
if len(text) > _tts_conf["vits"]["limit"]:
_vits_config = _tts_conf["vits"]
if len(text) > _vits_config["limit"]:
return
# 简单处理文本
_new_text = f"[ZH]{text}[ZH]"
result = TTS_Clint.request_vits_server(url=_tts_conf["vits"]["api"],
params=TTS_REQ(task_id=user_id,
text=_new_text,
model_name=_tts_conf["vits"]["model_name"],
speaker_id=_tts_conf["vits"]["speaker_id"]))
# 接受数据
result, e = await TTS_Clint.request_vits_server(url=_vits_config["api"],
params=TTS_REQ(task_id=user_id,
text=_new_text,
model_name=_vits_config["model_name"],
speaker_id=_vits_config["speaker_id"]))
if not result:
logger.error(f"RUN:{user_id} --vits: {text}:{len(text)} TTS failed")
logger.error(f"TTS:{user_id} --type:vits --content: {text}:{len(text)} --{e}")
return
try:
data = TTS_Clint.decode_wav(result["audio"])
except:
logger.error(f"RUN:{user_id} --vits: {text}:{len(text)} decode tts data failed")
logger.info(f"TTS:{user_id} --type:vits --content: {text}:{len(text)}")
# 返回字节流
return result
# USE AZURE
elif _tts_conf["type"] == "azure":
_azure_config = _tts_conf["azure"]
_new_text = text
_speaker = _azure_config["speaker"].get(lang_type)

if len(text) > _azure_config["limit"]:
return
else:
logger.info(f"RUN:{user_id} --vits: {text}:{len(text)}")
return data
return

if not _speaker:
logger.info(f"TTS:{user_id} --type:azure --content: {text}:{len(text)} --this type lang not supported")
return

result, e = await TTS_Clint.request_azure_server(key=_azure_config["key"],
location=_azure_config["location"],
text=_new_text,
speaker=_speaker
)
if not result:
logger.error(f"TTS:{user_id} --type:azure --content: {text}:{len(text)} --{e}")
return

logger.info(f"TTS:{user_id} --type:azure --content: {text}:{len(text)}")
# 返回字节流
return result
else:
# 啥也没有
return


async def Forget(bot, message, config):
Expand Down Expand Up @@ -354,7 +380,7 @@ async def Text(bot, message, config, reset: bool = False):
start_name="Girl:",
web_enhance_server=config.Enhance_Server
)
voice = TTS_Support_Check(text=_req, user_id=message.from_user.id)
voice = await TTS_Support_Check(text=_req, user_id=message.from_user.id)
if voice:
if not message.chat.is_forum:
msg = await bot.send_audio(chat_id=message.chat.id, audio=voice, title="Voice")
Expand Down Expand Up @@ -413,7 +439,7 @@ async def private_Chat(bot, message, config):
method=types,
web_enhance_server=config.Enhance_Server
)
voice = TTS_Support_Check(text=_req, user_id=message.from_user.id)
voice = await TTS_Support_Check(text=_req, user_id=message.from_user.id)
if voice:
if not message.chat.is_forum:
msg = await bot.send_audio(chat_id=message.chat.id, audio=voice, title="Voice")
Expand Down
37 changes: 35 additions & 2 deletions README.EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,47 @@ that are not in the preset will not be completed.
"type": "vits",
"vits": {
"api": "http://127.0.0.1:9557/tts/generate",
"limit": 20,
"limit": 70,
"model_name": "some.pth",
"speaker_id": 1
"speaker_id": 0
},
"azure": {
"key": [
"123"
],
"limit": 70,
"speaker": {
"chinese": "zh-CN-XiaoxiaoNeural"
},
"location": "japanwest"
}
}
}
```

**Redis**

- slightly

**TTS**

- status switch
- type Type

*VITS*

- vits:limit text within length will be converted
- vits:model_name The name of the model, some.pth, in the model folder
- vits:speaker_id The ID of the speaker, see the model config

*Azure*

- azure:limit The text within the length will be converted
- azure:
speaker[list-of-all-sound-engines](https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support?tabs=stt-tts)
- auzre:location Server resource address
- auzre:key api key

#### VITS Voice Support Description(ONLY CN NOW)

This technology provides an emulated voice interaction technique.
Expand Down
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,37 +185,62 @@ add_api_key - 增加 Api key
"type": "vits",
"vits": {
"api": "http://127.0.0.1:9557/tts/generate",
"limit": 20,
"limit": 70,
"model_name": "some.pth",
"speaker_id": 1
"speaker_id": 0
},
"azure": {
"key": [
"123"
],
"limit": 70,
"speaker": {
"chinese": "zh-CN-XiaoxiaoNeural"
},
"location": "japanwest"
}
}
}
```

redis:
**Redis**

- ?
-

tts:
**TTS**

- status 开关
- type 类型

#### Azure 支持说明

https://azure.microsoft.com/en-us/pricing/details/cognitive-services/speech-services/

*Azure*

- azure:limit 长度内的文本会被转换
- azure:speaker
说话人, [所有声音引擎列表](https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support?tabs=stt-tts)
- auzre:location 服务器资源地址
- auzre:key api key

#### VITS 语音支持说明(ONLY CN NOW)

Api 后端请使用我打包改造的 MoeGoe https://github.com/sudoskys/MoeGoe 本机运行

*VITS*

- vits:limit 长度内的文本会被转换
- vits:model_name 模型名字,some.pth,在 model 文件夹下的
- vits:speaker_id 说话人的ID,具体看模型config

#### VITS 语音支持说明(ONLY CN NOW)

这项技术提供了一种仿真的语音交互技术。

Api 后端为我打包改造的 MoeGoe https://github.com/sudoskys/MoeGoe

安装依赖,运行 `server.py` 文件可以默认使用。

模型下面请查询 MoeGoe 项目的 Readme,并注意模型相应的协议。

如果不说话,可能是文本的长度超过了设定的 limit。长度为直接取 `len()`
模型下载请查询 MoeGoe 项目的 Readme,并注意模型相应的协议。
如果不生效,可能是文本的长度超过了设定的 limit 。
长度为直接取 `len()`

## 运行

Expand Down
4 changes: 2 additions & 2 deletions openai_async/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def get_session(proxy: str = ""):
loop = asyncio.get_event_loop()
session = __session_pool.get(loop, None)
if session is None:
if proxy != "":
proxies = {"all": proxy}
if proxy:
proxies = {"all://": proxy}
session = httpx.AsyncClient(timeout=300, proxies=proxies)
else:
session = httpx.AsyncClient(timeout=300)
Expand Down
Loading

0 comments on commit 6d62d99

Please sign in to comment.