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

python文本转语音

时间:2023-03-25 20:12:00浏览次数:38  
标签:packages install python gtts 2021 语音 requests 文本 wind

 

pip install gtts

 

(wind_2021) J:\test>pip install gtts
Collecting gtts
  Downloading gTTS-2.3.1-py3-none-any.whl (28 kB)
Collecting requests<3,>=2.27
  Using cached requests-2.28.2-py3-none-any.whl (62 kB)
Requirement already satisfied: click<8.2,>=7.1 in e:\anaconda3\install\envs\wind_2021\lib\site-packages (from gtts) (8.1.3)
Requirement already satisfied: colorama in e:\anaconda3\install\envs\wind_2021\lib\site-packages (from click<8.2,>=7.1->gtts) (0.4.4)
Requirement already satisfied: certifi>=2017.4.17 in e:\anaconda3\install\envs\wind_2021\lib\site-packages (from requests<3,>=2.27->gtts) (2020.12.5)
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.1.0-cp38-cp38-win_amd64.whl (96 kB)
     |████████████████████████████████| 96 kB 625 kB/s
Requirement already satisfied: urllib3<1.27,>=1.21.1 in e:\anaconda3\install\envs\wind_2021\lib\site-packages (from requests<3,>=2.27->gtts) (1.26.4)
Requirement already satisfied: idna<4,>=2.5 in e:\anaconda3\install\envs\wind_2021\lib\site-packages (from requests<3,>=2.27->gtts) (2.10)
Installing collected packages: charset-normalizer, requests, gtts
  Attempting uninstall: requests
    Found existing installation: requests 2.25.1
    Uninstalling requests-2.25.1:
      Successfully uninstalled requests-2.25.1
Successfully installed charset-normalizer-3.1.0 gtts-2.3.1 requests-2.28.2

(wind_2021) J:\test>
(wind_2021) J:\test>

 

from gtts import gTTS
import os

# Define the text to convert to speech
text = "Hello, world!"

# Create a gTTS object
tts = gTTS(text=text, lang="en")

# Save the speech as an MP3 file
tts.save("hello.mp3")

# Play the speech using the default audio player
os.system("mpg321 hello.mp3")

 

 

#################

标签:packages,install,python,gtts,2021,语音,requests,文本,wind
From: https://www.cnblogs.com/herd/p/17255478.html

相关文章

  • python模块之tkinter
    tkinter图形化界面GUI1、导入模块tkinter  importtkinterastk2、操作创建窗口window=tk.Tk()设置窗口大小geometry('宽*高')设置窗口标题title('标题')......
  • 一个pid的python代码
    需在jupyter中运行,并安装ipywidgetsscipymatplotlibnumpy以及ipykernelfromipywidgetsimportinteract,fixedfromscipy.signalimportltiimportmatplotlib.py......
  • Python程序使用代理
    包括jupyter以内的python程序使用代理添加一下代码:#导入模块importos#设置代理proxy='http://127.0.0.1:1080'#代理地址os.environ['http_proxy']=proxyos......
  • 【Python】Logging模块简介 & 开启不同颜色日志输出
    ✨Logging模块简介PythonLogging模块是一个内置的日志处理工具,可以用于记录和输出应用程序的运行状态。该模块提供了一个灵活的方式来控制日志记录的输出和格式,包括记录......
  • Android开发-Android常用组件-TextView文本框
    04   常用组件4.1 TextViewTextView(文本框),用于显示文本的一个控件。文本的字体尺寸单位为sp:sp:scaledpixels(放大像素).主要用于字体显示。文本......
  • SDL显示文本
      SDL(SimpleDirectMediaLayer)是一套开放源代码的跨平台多媒体开发库,使用C语言写成。SDL提供了数种控制图像、声音、输出入的函数,让开发者只要用相同或是相似的代码就可以......
  • python tts播放文字
    参考以下代码:importpyttsx3#创建TTS引擎对象engine=pyttsx3.init()#设置语音属性engine.setProperty('rate',218)#设置语速为150engine.setProperty('vo......
  • python字典的值的路径集合,获取所有值的key路径,字典的键路径,
    #回溯算法获取字典所有值的键的集合defget_dict_path(data):ret=[]path=[]deftraceback(path,data):iflen(path)>0andnotisinstance(data,......
  • 《渗透测试》WEB攻防-Python考点&CTF与CMS-SSTI模版注入&PYC反编译 2022 Day23
    1     1PY反编译-PYC编译文件反编译源码1.1pyc文件是py文件编译后生成的字节码文件(bytecode),pyc文件经过python解释器最终会生成机器码运行。因此pyc文......
  • Python爬虫基础——05-高级数据类型
    2.10,数据类型高级2.10.1字符串高级:字符串常见操作包括:获取长度lenlen函数可以获取字符串的长度。查找内容find查找指定内容在字符串中是否存在,如果存在就返回该内容在字符......