Skip to content

Instantly share code, notes, and snippets.

@psavarmattas
Last active January 28, 2021 05:42
Show Gist options
  • Save psavarmattas/27fa3e9d68c7ff0b9b7170b1fcb6d073 to your computer and use it in GitHub Desktop.
Save psavarmattas/27fa3e9d68c7ff0b9b7170b1fcb6d073 to your computer and use it in GitHub Desktop.
News Text to Speech in Python
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