用户:
算法超人查看:0 回复:6 评论:0 创建时间:2021-02-23T18:44:54

下面是图中的代码<!!!>

图1:
import pyttsx3
s = pyttsx3.init() # 实例化,此行代码必要,否则无法运行
s.say('This program is great')# 说英文
s.say('这个程序太棒了') # 说中文
s.runAndWait() # 这个嘛……反正没有无法发出声音
图2:
import pyttsx3
s = pyttsx3.init() # 实例化,此行代码必要,否则无法运行
voices = s.getProperty('voices')# 获取当前语音声音的详细信息
s.setProperty('voice', voices[0].id) # 声音1
s.say('sound')
s.setProperty('voice', voices[1].id) # 声音2
s.say('new sound')
s.runAndWait() # 这个嘛……反正没有无法发出声音
图3:
def text2audio(words,name):
import pyttsx3
s = pyttsx3.init()
s.save_to_file(words, f"./{name}.mp3") # 导出音频
s.runAndWait() # 此时这个同样必要
text2audio('Yes I can','result')
图4:
import pyttsx3
engine = pyttsx3.init()
rate = engine.getProperty('rate')# 获取语速信息
engine.setProperty('rate',100) # 设置语速
volume = engine.getProperty('volume')# 获取音量信息
engine.setProperty('volume', 1)# 设置音量最小为0,最大为1
engine.say('文字'*10) #读的内容
engine.runAndWait()
往期回顾:
https://shequ.codemao.cn/community/362014
求回复!!!
墨染云天imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"width="834"height="834"
点赞0
评论