Reputation: 11
so i'm creating a speech to search script in python for youtube using selenium and speech recognition module and it's working perfectly except for one thing and its that it listens to my voice for too long or waits for my input for too long so is there a way to put a timer on the input? here's my code:
import speech_recognition as sr
from selenium import webdriver
r=sr.Recognizer()
drive=webdriver.Chrome()
def gotosite():
drive.get("https://youtube.com")
with sr.Microphone() as source:
print("speak:")
audio = r.listen(source)
text = r.recognize_google(audio)
print("You said: {}".format(text))
searchbox = drive.find_element_by_xpath(
"/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div/div[1]/input")
searchbox.send_keys(text)
searchbutton = drive.find_element_by_xpath(
"/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/button")
searchbutton.click()
gotosite()
Upvotes: 0
Views: 643
Reputation: 44
use audio = r.listen(source, timeout=3)
in place of audio = r.listen(source)
Upvotes: 1