0% found this document useful (0 votes)
7 views1 page

Voice-Activated Web Search Script

The document contains a Python script that utilizes speech recognition to listen to user input through a microphone. It converts the spoken words into text using Google's Speech Recognition API and performs a web search based on the recognized text. The script also includes error handling for various exceptions that may occur during the process.

Uploaded by

shamilaalva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

Voice-Activated Web Search Script

The document contains a Python script that utilizes speech recognition to listen to user input through a microphone. It converts the spoken words into text using Google's Speech Recognition API and performs a web search based on the recognized text. The script also includes error handling for various exceptions that may occur during the process.

Uploaded by

shamilaalva
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import speech_recognition as sr

import webbrowser
import pyttsx3

def speak(text):
engine = [Link]()
[Link](text)
[Link]()

def main():
recognizer = [Link]()
microphone = [Link]()

with microphone as source:


print("Please say something...")
speak("Please say something...")
recognizer.adjust_for_ambient_noise(source) # Adjust for ambient noise
try:
audio = [Link](source, timeout=5) # Listen for the user's
input
query = recognizer.recognize_google(audio) # Recognize speech using
Google Web Speech API
print(f"You said: {query}")
speak(f"You said: {query}")
[Link](f"[Link] # Perform
web search
except [Link]:
print("Sorry, I could not understand the audio.")
speak("Sorry, I could not understand the audio.")
except [Link] as e:
print(f"Could not request results from Google Speech Recognition
service; {e}")
speak("Could not request results from the speech recognition service.")
except Exception as e:
print(f"An error occurred: {e}")
speak("An error occurred.")

if __name__ == "__main__":
main()

You might also like