代码拉取完成,页面将自动刷新
#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")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。