forked from adi0509/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticle_Text_To_Speech.py
38 lines (28 loc) · 1.05 KB
/
Article_Text_To_Speech.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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")