首页 > 编程语言 >python文本转语音库Pyttsx3

python文本转语音库Pyttsx3

时间:2023-04-10 22:12:40浏览次数:59  
标签:engine current voice pyttsx3 python volume rate Pyttsx3 文本

python文本转语音库Pyttsx3: https://github.com/nateshmbhat/pyttsx3

Installation :

pip install pyttsx3

Linux installation requirements :

If you are on a linux system and if the voice output is not working , then :
Install espeak , ffmpeg and libespeak1 as shown below:

sudo apt update && sudo apt install espeak ffmpeg libespeak1

Usage :

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()

Single line usage with speak function with default options

import pyttsx3
pyttsx3.speak("I will speak this text")

Changing Voice , Rate and Volume :

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()

Full documentation of the Library

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

标签:engine,current,voice,pyttsx3,python,volume,rate,Pyttsx3,文本
From: https://www.cnblogs.com/sdlyxyf/p/17304493.html

相关文章

  • python+selenium写自动化脚本遇到的坑
    1.定位不到元素网速不好定位的元素还没有刷新出来使用等待有三种强制等待,显式等待,隐式等待动态ID不要复制xpath,要手写。判断是动态ID的方法,多次关闭浏览器再打开网址,查看ID是否会发生变化下拉框,文件无法定位还没有解决......
  • python统计list中出现最多的数字
    要统计一个Python列表中出现最多的数字,可以使用Python内置的collections模块中的Counter类。Counter类可以用于统计可迭代对象中每个元素的出现次数,返回一个字典,其中键是元素,值是元素出现的次数。然后,可以使用Python内置的max()函数找到字典中的最大值。以下是一个示例代码:from......
  • 深入理解 python 虚拟机:字节码教程(2)——控制流是如何实现的?
    深入理解python虚拟机:字节码教程(2)——控制流是如何实现的?在本篇文章当中主要给大家分析python当中与控制流有关的字节码,通过对这部分字节码的了解,我们可以更加深入了解python字节码的执行过程和控制流实现原理。控制流实现控制流这部分代码主要涉及下面几条字节码指令,......
  • 【享元设计模式详解】C/Java/JS/Go/Python/TS不同语言实现
    简介享元模式(FlyweightPattern),是一种结构型设计模式。主要用于减少创建对象的数量,以减少内存占用和提高性能。它摒弃了在每个对象中保存所有数据的方式,通过共享多个对象所共有的相同状态,让你能在有限的内存容量中载入更多对象。当程序需要生成数量巨大的相似对象时,可能对内存有......
  • python的pytest框架
    pytest和unittest的区别:1.安装需求不同。pytest为第三方单元测试库,需额外安装;unittest为标准库,无需额外安装。2.用例编写规则不同。pytest编写规则较为简单,兼容性较好;unittest需按照固定的格式编写,较为复杂。 pytest优点:能够支持简单的单元测试和复杂的功能测试,还可以用来做s......
  • python可视化工具——seaborn模块
    python可视化工具——seaborn模块参考Python数据可视化的完整版操作指南(建议收藏)导入模块importseabornassnssns.set()#初始化图形样式,若没有该命令,图形将具有与matplotlib相同的样式读取数据df=pd.read_csv('D:\Graduate\python_studying\datasets-master\\t......
  • 编辑大量文本的情况vscode比notepad++性能更好
    尝试操作几十万行的文本的时候Notepad++直接卡死了二十多万行的文本选中需要卡几秒,剪切粘贴文本需要卡几秒文本替换需要跑几十秒,再多一些的话容易卡崩 使用vscode进行剪切粘贴批量替换之类的操作基本是不卡秒执行的 一次性选中多行的方法:使用ctrl+G可以跳转到指定行ct......
  • 安装python第三方库报:is not a supported wheel on this platform
    1,在cmd中输入pipdebug--verbose,如下图圈红的就是当前python使用的标签,所以可以把cryptography-40.0.1-pp39-pypy39_pp73-win_amd64.whl改成cryptography-40.0.1-py39-none-any.whl就能安装成功 ......
  • opencv-python 4.16. 基于GrabCut算法的交互式前景提取
    理论GrabCut算法由英国剑桥微软研究院的CarstenRother,VladimirKolmogorov和AndrewBlake设计。在他们的论文:"GrabCut":interactiveforegroundextractionusingiteratedgraphcuts中提出了一种基于最小用户交互的前景提取算法,其结果为GrabCut。从用户的角度来看,它是如何工......
  • 翻译文本 API说明示例
    t_text-翻译文本名称 类型 必须 描述key String 是 调用key(必须以GET方式拼接在URL中)secret String 是 调用密钥(获取key和secret)api_name String 是 API接口名称(包括在请求地址中)[item_search,item_get,item_search_shop等]cache String 否 [yes,no]默认yes,将调用缓存的数据,速度比......