1 Star 0 Fork 1

高鑫 / Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Article_Text_To_Speech.py 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
randerson112358 提交于 2019-09-03 14:06 . Create Article_Text_To_Speech.py
#Import the libraries
from newspaper import Article
import nltk
from gtts import gTTS
import os
#Get the article
article = Article('https://hackernoon.com/future-of-python-language-bright-or-dull-uv41u3xwx')
article.download() #Download the article
article.parse() #Parse the article
nltk.download('punkt') #Download the 'punkt' package
article.nlp() #Apply Natural Language Processing (NLP)
#Get the articles text
mytext = article.text
#Print the text
print(mytext)
# Language in which you want to convert
#language = 'pt-br' #Portuguese (Brazil)
language = 'en' #English
# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)
# Saving the converted audio in a mp3 file named
# read_article
myobj.save("read_article.mp3")
# Playing the converted file
os.system("start read_article.mp3") #This command is for windows only for either operating systems download mpg321 and use os.system("mpg321 read_article.mp3")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/gaoxin1999/Python.git
git@gitee.com:gaoxin1999/Python.git
gaoxin1999
Python
Python
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891