-2

So i was making an AI which was siri-based whenever i say open youtube or google or any site, it opens it in microsoft edge which i dont want. I want them to open them in google chrome. Yes my default browser is chrome

this is my code:

#Importing Modules
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os

#Setting up engine
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

#fuction for making engine audio based
def speak(audio):
    engine.say(audio)
    engine.runAndWait()

#Function for Wishing good morning, afternoon and evening
def wishme():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")

    else:
        speak("Good Evening!")

    speak("I am Reeuzaki, you can call me L. How may i help you")

def takeCommand():
    #it takes microphone input and return strings based output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in') #Using google for voice recognition.
        print(f"User said: {query}\n")  #User query will be printed.

    except Exception as e:
        # print(e)    
        print("Say that again please...")   #Say that again will be printed in case of improper voice 
        return "None" #None string will be returned
    return query

#main
if __name__ == "__main__":
    wishme()
    while True:
        query = takeCommand().lower()
        
    # Logic for executing tasks based on query
        
        #Sites
        if 'wikipedia' in query:  #if wikipedia found in the query then this block will be executed
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2) 
            speak("According to Wikipedia")
            print(results)
            speak(results)

        elif 'open youtube' in query:
                    webbrowser.open("youtube.com")


        elif 'open google' in query:
            webbrowser.open("google.com")

        elif 'open udemy' in query:
            webbrowser.open("udemy.com")
Sayse
  • 42,633
  • 14
  • 77
  • 146
BOLTz
  • 1
  • 3
  • 1
    I wouldn't say thats acceptable, you could use that "much more detail" to describe what you've tried and researched to try and solve it yourself. – Sayse Oct 15 '20 at 13:38

1 Answers1

0

Try to change: webbrowser.open("youtube.com") to webbrowser.get('chrome').open("youtube.com")

Dmytro Huz
  • 1,514
  • 2
  • 14
  • 22