How do I make Python’s speech recognition module take my YouTube search query

I’m working on a voice assistant using Python. I would like to make Python take my search query and automatically type it in the YouTube search bar. I’m able to open YouTube but I’m not able to make Python take my search query. Microsoft keeps sending these messages.

Look for an app in the Microsoft store

I’ve been trying this for days now and all the tutorials/questions don’t help me out.

My code…

import datetime
import webbrowser
from import Service
from import Options
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import ChromeDriverManager
import speech_recognition as sr
import pyttsx3
import pyaudio
import os
import random
import gtts


service = Service('C:UsersAdminPycharmProjectspythonProjectchromedriver.exe')
chrome_options = Options()
chrome_options.add_argument(r'--user-data-dir=C:UsersAdminAppDataLocalGoogleChromeUser DataDefault')
driver = webdriver.Chrome(service=service, options=chrome_options)

r1 = sr.Recognizer()
r2 = sr.Recognizer()
r3 = sr.Recognizer()

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

with sr.Microphone() as source:
 engine.say("Hey I'm your bot, Trevor! What can I do for you today?")
 audio = r3.listen(source)

# From here

if 'YouTube' in r2.recognize_google(audio):
    r2 = sr.Recognizer()

    with sr.Microphone() as source:

        print("Type what you want to see.", end='')
        audio = r2.listen(source)
        keyword = audio

        search = input()
        url = ('')
        result = search+url

        get = r2.recognize_google(audio)
    except sr.UnknownValueError:
        print('Error on your side')
    except sr.RequestError:
        print('Error on my side')

# Till here is the code to run a YouTube vid

PS: The code is indented as per Pycharm’s indentation

pls, help me out and give me a solution.

Source: Python-3x Questions