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()