import os import pyttsx3 # is a text-to-speech conversion library in Python import speech_recognition as sr # Library for performing speech recognition, pip install SpeechRecognition import pyjokes # pip install pyjokes. A Python module that returns a random joke from the Internet from google_news_feed import GoogleNewsFeed # pip install google_news_feed gnf = GoogleNewsFeed(language='en',country='US') joke_keywords = ["joke", "funny", "fun", "humor", "jokes"] joke_reaction = "OK sure, I'm very funny! Here's a joke for you." def create_joke() -> str: my_joke = pyjokes.get_joke(language="en", category="neutral") return my_joke news_keywords = ["news", "latest"] news_reaction = "OK sure, I'll get you some news about the Netherlands!" def create_news() -> str: results = gnf.query("the netherlands") return results[0] def spreek(text: str): engine = pyttsx3.init() engine.say(text) engine.runAndWait() def herken_stem() -> str: r = sr.Recognizer() with sr.Microphone() as source: while True: audio = r.listen(source) try: said = r.recognize_google(audio) print(said) return said.lower() except Exception as e: print("niets gehoord") WAKE_UP_TEXT = "wake up" def start_programma(): print("Start") while True: spreek("What is the magic word?") print("Listening") text = herken_stem() if text.find(WAKE_UP_TEXT) >= 0: break; spreek("Hi, it's me, I'm ready for action!") while True: text = herken_stem() spreek("OK, I understand, you said, " + text) if any(keyword in text for keyword in joke_keywords): spreek(joke_reaction) spreek(create_joke()) if any(keyword in text for keyword in news_keywords): spreek(news_reaction) spreek(create_news()) spreek("What else can I do for you?") start_programma()