Skip to main content

适用于 Python 2 和 3 的文本转语音 (TTS) 库。无需互联网连接或延迟即可工作。支持多种 TTS 引擎,包括 Sapi5、nsss 和 espeak。

项目描述

pyttsx3是 Python 中的文本到语音转换库。与其他库不同,它可以离线工作,并且与 Python 2 和 3 兼容。

安装

pip install pyttsx3

如果您收到诸如No module named win32com.clientNo module named win32No module named win32api等错误,则需要额外安装pypiwin32

用法 :

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
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()

"""Saving Voice to a file"""
# On linux make sure that 'espeak' and 'ffmpeg' are installed
engine.save_to_file('Hello World', 'test.mp3')
engine.runAndWait()

图书馆的完整文档

https://pyttsx3.readthedocs.io/en/latest/

包含的 TTS 引擎:

  • sapi5

  • nsss

随意包装另一个文本到语音引擎以与pyttsx3一起使用。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

内置分布

pyttsx3-2.90-py3-none-any.whl (39.5 kB 查看哈希

已上传 py3