1、简介
TTS(Text To Speech) 译为从文本到语音,TTS是人工智能AI的一个模组,是人机对话的一部分,即让机器能够说话。
2、ggts
2.1 简介
https://pypi.org/project/gTTS/
gTTS(Google Text-to-Speech),一个 Python 库和 CLI 工具,用于与 Google 翻译文本转语音 API 交互。
gTTS(Google Text-to-Speech),一个 Python 库和 CLI 工具,用于与 Google Translate 的文本转语音 API 交互。 将语音数据写入文件、类似文件的对象 (bytestring) 以进行进一步的音频操作。
2.2 安装
pip install gTTS
2.3 代码
gtts-cli 'hello' --output hello.mp3
或
from gtts import gTTS
tts = gTTS('hello')
tts.save('hello.mp3')
<font color=red>执行失败了。
3、SAPI
SAPI是微软Speech API , 是微软公司推出的语音接口,而从WINXP开始,系统上就已经有语音识别的功能了,可是用武之地相当之少,他并没有给出一些人性化的自定义方案,仅有的语音操控命令显得相当鸡胁。 操作window dll的库,它可以实现很多功能,十分强大。
import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("hello")
4、SpeechLib
comtypes依赖pyttsx3包。( comtypes Required-by: pyttsx3 ) 安装:
pip install comtypes
代码:
from comtypes.client import CreateObject
engine = CreateObject('SAPI.SpVoice')
stream = CreateObject('SAPI.SpFileStream')
from comtypes.gen import SpeechLib # 导这个包必须放在 上面3行代码 后面,否则运行时会报错。
infile = 'demo.txt'
outfile = 'demo_audio.wav'
stream.Open(outfile, SpeechLib.SSFMCreateForWrite)
engine.AudioOutputStream = stream
# 读取文本内容
f = open(infile, 'r', encoding='utf-8')
theText = f.read()
f.close()
engine.speak(theText)
stream.close()
结语
如果您觉得该方法或代码有一点点用处,可以给作者点个赞,或打赏杯咖啡;
╮( ̄▽ ̄)╭
如果您感觉方法或代码不咋地
//(ㄒoㄒ)//,就在评论处留言,作者继续改进;
o_O???
如果您需要相关功能的代码定制化开发,可以留言私信作者;
(✿◡‿◡)
感谢各位大佬童鞋们的支持!
( ´ ▽´ )ノ ( ´ ▽´)っ!!!