diff --git a/Calculatenumbers.py b/Calculatenumbers.py new file mode 100644 index 0000000..1219a75 --- /dev/null +++ b/Calculatenumbers.py @@ -0,0 +1,48 @@ +import wolframalpha +import pyttsx3 +import speech_recognition + +# Initialize the text-to-speech engine +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +for voice in voices: + if "zira" in voice.name.lower(): + engine.setProperty("voice", voice.id) + break +engine.setProperty("rate", 170) + +def speak(audio): + engine.say(audio) + engine.runAndWait() + +def WolfRamAlpha(query): + apikey = "HEVXUJ-T9P3G7YK76" + requester = wolframalpha.Client(apikey) + response = requester.query(query) + try: + answer = next(response.results).text + # print(answer) + speak(answer) + return answer + except StopIteration: + speak("I'm sorry, I don't have an answer to that question") + return None + +def Calc(query): + Term = str(query) + Term = Term.replace("plus", "+") + Term = Term.replace("minus", "-") + Term = Term.replace("multiply", "*") + Term = Term.replace("divide", "/") + Term = Term.replace("Daisy", "") + + Final = str(Term) + try: + result = WolfRamAlpha(Final) + if result: + print(result) + # speak(result) + except Exception as e: + print(f"Error: {e}") + speak("I'm sorry, I don't have an answer to that question") + diff --git a/__pycache__/Calculatenumbers.cpython-312.pyc b/__pycache__/Calculatenumbers.cpython-312.pyc new file mode 100644 index 0000000..1d7a7ca Binary files /dev/null and b/__pycache__/Calculatenumbers.cpython-312.pyc differ diff --git a/__pycache__/newsread.cpython-312.pyc b/__pycache__/newsread.cpython-312.pyc new file mode 100644 index 0000000..94fa450 Binary files /dev/null and b/__pycache__/newsread.cpython-312.pyc differ diff --git a/daisy_main.py b/daisy_main.py index 43ba7b5..8ae8057 100644 --- a/daisy_main.py +++ b/daisy_main.py @@ -9,6 +9,8 @@ import keyboard import random import webbrowser +import wolframalpha + engine = pyttsx3.init("sapi5") voices = engine.getProperty("voices") @@ -147,6 +149,16 @@ def convert_to_datetime(alarm_time_str): elif "wikipedia" in query: from SearchNow import searchWikipedia searchWikipedia(query) + elif "news" in query: + from newsread import latest_news + latest_news() + elif "calculate" in query: + from Calculatenumbers import WolfRamAlpha + from Calculatenumbers import Calc + query = query.replace("calculate", "") + query = query.replace("Daisy", "") + Calc(query) + elif "temperature" in query: search = "temperature here is " url=f"https://www.google.com/search?q={search}" diff --git a/newsread.py b/newsread.py new file mode 100644 index 0000000..606b1a1 --- /dev/null +++ b/newsread.py @@ -0,0 +1,55 @@ +import requests +import json +import pyttsx3 + +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +for voice in voices: + if "zira" in voice.name.lower(): + engine.setProperty("voice", voice.id) + break +engine.setProperty("rate", 170) +def speak(text): + engine.say(text) + engine.runAndWait() + +def latest_news(): + apidict = { + "business": "https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=3529f3b21a4c43c796e555937e7802f8", + "entertainment": "https://newsapi.org/v2/top-headlines?country=in&category=entertainment&apiKey=3529f3b21a4c43c796e555937e7802f8", + "health": "https://newsapi.org/v2/top-headlines?country=in&category=health&apiKey=3529f3b21a4c43c796e555937e7802f8", + "science": "https://newsapi.org/v2/top-headlines?country=in&category=science&apiKey=3529f3b21a4c43c796e555937e7802f8", + "sports": "https://newsapi.org/v2/top-headlines?country=in&category=sports&apiKey=3529f3b21a4c43c796e555937e7802f8", + "technology": "https://newsapi.org/v2/top-headlines?country=in&category=technology&apiKey=3529f3b21a4c43c796e555937e7802f8", + "general": "https://newsapi.org/v2/top-headlines?country=in&category=general&apiKey=3529f3b21a4c43c796e555937e7802f8" + } + + speak("Which news category would you like to hear? [business, entertainment, health, science, sports, technology, general]") + field = input("Which news category would you like to hear? [business, entertainment, health, science, sports, technology, general] : ").lower() + + url = apidict.get(field) + if not url: + speak("Invalid category") + return + + news = requests.get(url).text + news_dict = json.loads(news) + speak("Here are some top news headlines") + arts = news_dict["articles"] + for article in arts: + title = article["title"] + speak(title) + print(title) + news_url = article["url"] + print(f"For more info visit: {news_url}") + + a = input("Would you like to read more news? [yes/no] : ") + if a.lower() == "no": + break + else: + continue + speak("That's all for now") + + + +