Skip to main content

Listen news Program in Python





 import requests
import json
import time

def speak(str):
    from win32com.client import Dispatch
    speak = Dispatch("SAPI.SpVoice")
    speak.speak(str)


if __name__  == '__main__':
    speak("Today News")
    url = "https://newsapi.org/v2/top-headlines?country=in&apiKey=b6feb64fbeba
            4744ab535e40d6cefb71"
    news = requests.get(url).text
    news_dict = json.loads(news)
    a =  news_dict['articles']
    for article in a:
        speak(article['title'])
        print(article['title'])
        time.sleep(2)
        speak("Next News ")
       
           


Comments