Skip to content

Commit

Permalink
feat: 增加微软edge-tts文本转语音的支持(#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzpan committed Apr 15, 2023
1 parent bb5a0ce commit 727e4f4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</p>

* 模块化。功能插件、语音识别、语音合成、对话机器人都做到了高度模块化,第三方插件单独维护,方便继承和开发自己的插件。
* 中文支持。集成百度、科大讯飞、阿里、腾讯、OpenAI Whisper、Apple 等多家中文语音识别和语音合成技术,且可以继续扩展。
* 中文支持。集成百度、科大讯飞、阿里、腾讯、OpenAI Whisper、Apple、微软Edge等多家中文语音识别和语音合成技术,且可以继续扩展。
* 对话机器人支持。支持基于 [AnyQ](https://wukong.hahack.com/#/anyq) 的本地对话机器人,并支持接入图灵机器人、ChatGPT 等在线对话机器人。
* 全局监听,离线唤醒。支持 [Porcupine](https://github.com/Picovoice/porcupine)[snowboy](https://github.com/Kitt-AI/snowboy) 两套离线语音指令唤醒引擎,并支持 Muse [脑机唤醒](https://wukong.hahack.com/#/bci) 以及行空板摇一摇唤醒等其他唤醒方式。
* 灵活可配置。支持定制机器人名字,支持选择语音识别和合成的插件。
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pvporcupine
pvrecorder
openai
apscheduler
asyncio
asyncio
edge-tts
39 changes: 39 additions & 0 deletions robot/TTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import subprocess
import uuid

import asyncio
import edge_tts

from aip import AipSpeech
from . import utils, config, constants
from robot import logging
Expand Down Expand Up @@ -336,6 +339,42 @@ def get_speech(self, phrase):
logger.critical(f"{self.SLUG} 合成失败!", stack_info=True)


class EdgeTTS(AbstractTTS):
"""
edge-tts 引擎
voice: 发音人,默认是 zh-CN-XiaoxiaoNeural
全部发音人列表:命令行执行 edge-tts --list-voices 可以打印所有语音
"""

SLUG = "edge-tts"

def __init__(self, voice="Tingting", **args):
super(self.__class__, self).__init__()
self.voice = voice

@classmethod
def get_config(cls):
# Try to get ali_yuyin config from config
return config.get("edge-tts", {})

async def async_get_speech(self, phrase):
try:
tmpfile = os.path.join(constants.TEMP_PATH, uuid.uuid4().hex + ".mp3")
tts = edge_tts.Communicate(text=phrase, voice=self.voice)
await tts.save(tmpfile)
logger.info(f"{self.SLUG} 语音合成成功,合成路径:{tmpfile}")
return tmpfile
except Exception as e:
logger.critical(f"{self.SLUG} 合成失败:{str(e)}!", stack_info=True)
return None

def get_speech(self, phrase):
event_loop = asyncio.get_event_loop ( )
tmpfile = event_loop.run_until_complete(self.async_get_speech(phrase))
return tmpfile



class MacTTS(AbstractTTS):
"""
macOS 系统自带的TTS
Expand Down
17 changes: 12 additions & 5 deletions static/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ lru_cache:
# 语音合成服务配置
# 可选值:
# han-tts - HanTTS
# baidu-tts - 百度语音合成(推荐)
# baidu-tts - 百度语音合成
# xunfei-tts - 讯飞语音合成
# ali-tts - 阿里语音合成(推荐)
# tencent-tts - 腾讯云语音合成(推荐)
# ali-tts - 阿里语音合成
# tencent-tts - 腾讯云语音合成
# azure-tts - 微软语音合成
# mac-tts - macOS 系统自带TTS(mac 系统推荐)
tts_engine: baidu-tts
# edge-tts - 基于 Edge 的 TTS(推荐)
tts_engine: edge-tts

# 语音识别服务配置
# 可选值:
Expand Down Expand Up @@ -168,10 +169,16 @@ han-tts:
# macOS 自带的 TTS 服务
# 注意:仅 macOS 系统可用!
mac-tts:
# 命令行执行 say -v '?' 可以打印所有语音
# 命令行执行 say -v '?' 可以打印所有音色
# 中文推荐 Tingting(普通话)或者 Sinji(粤语)
voice: Tingting

# 基于 edge 浏览器的在线 TTS 服务
edge-tts:
# 命令行执行 edge-tts --list-voices 可以打印所有音色
# 中文推荐 `zh` 开头的音色
voice: zh-CN-XiaoxiaoNeural

# NLU 引擎
# 可选值:
# unit - 百度 UNIT
Expand Down

0 comments on commit 727e4f4

Please sign in to comment.