Last active
January 28, 2021 05:42
-
-
Save psavarmattas/27fa3e9d68c7ff0b9b7170b1fcb6d073 to your computer and use it in GitHub Desktop.
News Text to Speech in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyttsx3 | |
import requests | |
import json | |
import time | |
url = ('https://newsapi.org/v2/top-headlines?' | |
'country = in&' | |
'apiKey =') | |
url += 'YOUR_API_KEY_HERE' | |
engine = pyttsx3.init() | |
voices = engine.getProperty('voices') | |
engine.setProperty('voice', voices[1].id) | |
rate = engine.getProperty('rate') | |
engine.setProperty('rate', 150) | |
try: | |
response = requests.get(url) | |
except: | |
engine.talk("can, t access link, plz check you internet ") | |
news = json.loads(response.text) | |
for new in news['articles']: | |
# print(str(new['title']), "\n\n") | |
news_title = (str(new['title'])) | |
# print(str(new['description']), "\n\n") | |
news_description = (str(new['description'])) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment