python 中文语音播报_python pywin32 pyttsx 语音 播报 朗读

本文介绍了如何使用Python库pyttsx和pywin32进行中文语音播报。pyttsx仅支持英文和普通机器人声音,可以调整语速和音量。而pywin32则能支持中文,提供了更多的语音选项。
摘要由CSDN通过智能技术生成

pyttsx

pip install pyttsx3

只支持英文 普通机器人声音

import pyttsx3

engine = pyttsx3.init()

engine.say("hello world")

engine.runAndWait()

设置属性,语速和声音大小

import pyttsx3

engine = pyttsx3.init() # object creation

""" RATE"""

rate = engine.getProperty('rate') # getting details of current speaking rate

print(rate) # printing current voice rate

engine.setProperty('rate', 125) # setting up new voice rate

"""VOLUME"""

volume = engine.getProperty('volume') # getting to know current volume level (min=0 and max=1)

print(volume) # printing current volume level

engine.setProperty('volume', 1.0) # setting up volume level between 0 and 1

"""VOICE"""

voices = engine.getProperty('voices') # getting details of current voice

# engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male

engine.setProperty('voice', voices[1].id) # changing index, changes voices. 1 for female

engine.say("Hello World!")

engine.say('My current speaking rate is ' + str(rate))

engine.runAndWait()

engine.stop()

pywin32  如果安装conda则已经带有

pip install pywin32

是一般的机器人声音,支持中英

import win32com.client

speaker = win32com.client.Dispatch("SAPI.SpVoice")

speaker.Speak("hello 世界")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值