目录
Full dictionary is not installed for ‘zh’
报错:Can't access (r) file 'zh_rules'
chattts 对话式,可以生成语气,笑声
GitHub - 2noise/ChatTTS: ChatTTS is a generative speech model for daily dialogue.
edge_tts 麒麟系统效果不错
edge-tts是github上的一个开源项目,可以免费将文本转为语音,别看它只有2.8k star,替代科大讯飞的收费TTS服务完全没问题,因为这个项目实际是调用的微软edge的在线语音合成服务,支持40多种语言,300多种声音,效果毋容置疑。
https://github.com/rany2/edge-tts
pip install edge-tts
import edge_tts
import asyncio
async def text_to_speech(text, output_file):
communicate = edge_tts.Communicate(text, "zh-CN-XiaoxiaoNeural")
await communicate.save(output_file)
text = "赵晓红,检录通过"
output_file = "hello1.mp3"
asyncio.run(text_to_speech(text, output_file))
男播音员:
async def text_to_speech(text, output_file):
# communicate = edge_tts.Communicate(text, "zh-CN-YunjianNeural")
# communicate = edge_tts.Communicate(text, "zh-CN-YunxiNeural")
communicate = edge_tts.Communicate(text, "zh-CN-YunyangNeural")
await communicate.save(output_file)
播报人列表:
Text to Speech Voice (zh-HK, HiuGaaiNeural), Gender: Female, Locale: zh-HK
Text to Speech Voice (zh-HK, HiuMaanNeural), Gender: Female, Locale: zh-HK
Text to Speech Voice (zh-HK, WanLungNeural), Gender: Male, Locale: zh-HK
Text to Speech Voice (zh-CN, XiaoxiaoNeural), Gender: Female, Locale: zh-CN
Text to Speech Voice (zh-CN, XiaoyiNeural), Gender: Female, Locale: zh-CN
Text to Speech Voice (zh-CN, YunjianNeural), Gender: Male, Locale: zh-CN
Text to Speech Voice (zh-CN, YunxiNeural), Gender: Male, Locale: zh-CN
Text to Speech Voice (zh-CN, YunxiaNeural), Gender: Male, Locale: zh-CN
Text to Speech Voice (zh-CN, YunyangNeural), Gender: Male, Locale: zh-CN
Text to Speech Voice (zh-CN-liaoning, XiaobeiNeural), Gender: Female, Locale: zh-CN-liaoning
Text to Speech Voice (zh-TW, HsiaoChenNeural), Gender: Female, Locale: zh-TW
Text to Speech Voice (zh-TW, YunJheNeural), Gender: Male, Locale: zh-TW
Text to Speech Voice (zh-TW, HsiaoYuNeural), Gender: Female, Locale: zh-TW
Text to Speech Voice (zh-CN-shaanxi, XiaoniNeural), Gender: Female, Locale: zh-CN-shaanxi
播报人代码:
import sys
from gtts import gTTS
import edge_tts
import asyncio
def text_to_speech(text, lang='zh'):
tts = gTTS(text=text, lang=lang)
tts.save("output.mp3")
def edge_tts_demo():
import edge_tts
import asyncio
async def text_to_speech(text, output_file):
communicate = edge_tts.Communicate(text, "zh-CN-XiaoxiaoNeural")
await communicate.save(output_file)
text = "赵晓红,检录通过"
output_file = "hello1.mp3"
asyncio.run(text_to_speech(text, output_file))
async def list_voices():
voices = await edge_tts.list_voices()
for voice in voices:
if 'zh' in voice['Name']:
print(f"Name: {voice['Name']}, Gender: {voice['Gender']}, Locale: {voice['Locale']}")
async def text_to_speech(text, voice_name, output_file):
communicate = edge_tts.Communicate(text, voice_name)
await communicate.save(output_file)
print(f'Speech saved to {output_file}')
if __name__ == "__main__":
# tts = gTTS(text="赵晓红,检录通过", lang="zh")
# tts.save("hello1.mp3")
# List available Chinese voices
asyncio.run(list_voices())
# Example usage with a specific voice
text = "赵晓红,检录通过"
voice_name = "zh-CN-XiaoxiaoNeural" # Replace with the desired voice name
output_file = "hello2.mp3"
asyncio.run(text_to_speech(text, voice_name, output_file))
# text_to_speech("赵晓红,检录通过")
gtts语音播报,Windows正常,麒麟系统卡死
import sys
from gtts import gTTS
def text_to_speech(text, lang='zh'):
tts = gTTS(text=text, lang=lang)
tts.save("output.mp3")
if __name__ == "__main__":
tts = gTTS(text="赵晓红,检录通过", lang="zh-tw")
tts.save("hello1.mp3")
# text_to_speech("赵晓红,检录通过")
espeak语音tts
linux espeak语音tts
安装:sudo apt install espeak
使用:
#中文男声
espeak -v zh 你好
#中文女声
espeak -v zh+f3 你好
#粤语男声
espeak -v zhy 你好
Full dictionary is not installed for ‘zh’
注意:espeak -v zh 你好 (Full dictionary is not installed for ‘zh’)
解决方法:https://www.cnblogs.com/Hfolsvh/p/15057694.html
##1、重新下载语音包https://github.com/caixxiong/espeak-data/
git clone https://github.com/caixxiong/espeak-data/
cd espeak-data/
unzip espeak-data.zip
cd espeak-data/
##2、拷贝解压文件到原安装包对应目录
sudo cp -r * /usr/lib/x86_64-linux-gnu/espeak-data
##3、编译中文、粤语包
sudo espeak --compile=zh
sudo espeak --compile=zhy
报错:Can't access (r) file 'zh_rules'
麒麟系统 解决
下载
https://github.com/nvaccess/espeak
把dictsource目录拷贝到:
/usr/lib/aarch64-linux-gnu/espeak-data/
cd /usr/lib/aarch64-linux-gnu/espeak-data/
espeak –compile=zh
然后编译通过了。
##4、编译成功后需要把原来wget下载的espeak-data目录全部整体删除,不然可能报espeak -v zhy 你好
Can't read data file: '/home/loong/espeak-data/phontab'
Failed to load espeak-data
解决方法:rm -rf espeak-data
2、pyttsx3 ubuntu使用
参考:https://blog.youkuaiyun.com/Wickedstepmother/article/details/130993164
pyttsx3包主要就是调用电脑自带的声音tts工具,windows是调用微软自带的声音库;linux就是调用安装的espeak
安装
pip install pyttsx3 -i https://pypi.tuna.tsinghua.edu.cn/simple --user
使用
import pyttsx3
engine = pyttsx3.init()
engine.setProperty('voice','zh') ##可以替换zhy 粤语;zh+f3中文女声
engine.say("你好,晚上吃什么?")
engine.runAndWait()
原文链接:https://blog.youkuaiyun.com/weixin_42357472/article/details/134340397