windows电脑简单实时tts语音播报wsay;python pyttsx3语言实时播报text-to-speech;微软edge-tts 音色自然离线不实时

1、wsay

参考:
https://github.com/p-groarke/wsay

下载安装:
https://github.com/p-groarke/wsay/releases/tag/v1.5.0
下载exe文件,并把加入环境变量就可
在这里插入图片描述
在这里插入图片描述

使用

# Say something.
wsay "Hello there."

wsay  "你好"

在这里插入图片描述

Video_20230813075925

2、pyttsx3

参考:
https://zhuanlan.zhihu.com/p/507369886
https://blog.51cto.com/u_12891/6705605

安装:

pip install pyttsx3 -i https://pypi.tuna.tsinghua.edu.cn/simple --user

使用:
直接调用 pyttsx3.speak()

import pyttsx3

#语音播放 
pyttsx3.speak("How are you?")
pyttsx3.speak("I am fine, thank you")


pyttsx3.speak("具体来说,这个命令中的参数-NL表示创建本地端口转发。它将本地机器的7860端口与远程服务器的192.168.19.14:7860端口进行连接。实际上,当本地机器收到对本地7860端口的请求时,请求将被转发到远程服务器的192.168.19.14:7860端口。通过这个隧道建立的通信是安全的,因为SSH使用了加密来保护数据的传输。这意味着在本地机器和远程服务器之间传输的数据被加密,只有具有正确密钥的两端才能解密和读取数据。在隧道建立后,您可以在本地机器上通过访问localhost:7860来与远程服务器上的服务进行通信。本地机器上的请求会被转发到远程服务器,并得到响应。这样,您可以通过安全的通道在本地机器和远程服务器之间进行通信。")

在这里插入图片描述

3、微软edge-tts 音色自然离线不实时

参考:https://github.com/rany2/edge-tts

安装:
pip install edge-tts

使用:

edge-tts --text "Hello, world!" --write-media hello.mp3 --write-subtitles hello.vtt

指定语言音色选择:

edge-tts --list-voices   ##查看支持的

edge-tts --voice ar-EG-SalmaNeural  ##添加 --voice 
如果要声音播报,需要安装mpv 命令行视频播放工具,下载:https://mpv.io/installation/

下载windows zip文件加压后需要路径加入环境变量
在这里插入图片描述

安装好就可以命令行播放声音:

播放速度会比较延迟,相当于也是先把文字转化成语音mp3文件后,再进行播放mp3;优点是音色很棒,接近真人

edge-playback --text "Hello, world!"

edge-playback --text "这个错误表明在尝试进行SSL连接时,出现了证书验证问题。具体来说,问题出在证书验证过程中,证书验证失败的原因是" --voice zh-CN-XiaoxiaoNeural

这里如果报ssl错误,参考https://github.com/rany2/edge-tts/issues/110,在edge-tts报里面文件更改ssl,主要是在C:\Us****p\Lib\site-packages\edge_tts 路径下list_voices.py、communicate.py文件中更改添加;然后再运行edge-playback 播放声音命令即可

verify_ssl=False,

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42357472/article/details/132256328