猫史档案馆


【编程成神之路1-2】让计算机呐喊起来吧(pyttsx3探究)

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


 

center_image

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

emotion_编程猫_紧张

图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

求回复!!!
emotion_编程猫_厉害了


回复

上一页1 页 / 共 1下一页
86135clc86135clc

sofa

点赞0


评论


算法超人算法超人

点赞0


评论


天下第一皮卡丘天下第一皮卡丘

巨佬

点赞0


评论


墨染云天墨染云天

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


评论


yh12i31yh12i31

有用!感谢!

点赞0


评论


伴雪纷飞伴雪纷飞

挖坟

点赞0


评论