


I can't generate google/youtube research results in my speech recognition code
I'm trying to build a chatbot that can interact with people and help them update quickly. Below is the code I'm using to get search results from youtube/google. Please tell me where is the problem?
maya_google_search.pyCode:
import speech_recognition import pyttsx3 import pywhatkit from wikipedia import wikipedia import wikipedia as googlescrap import webbrowser engine = pyttsx3.init("sapi5") voices = engine.getproperty("voices") engine.setproperty("voice", voices[1].id) engine.setproperty("rate", 150) def speak(audio): engine.say(audio) engine.runandwait() def takecommand(): r = speech_recognition.recognizer() with speech_recognition.microphone() as source: print("listening.............") r.pause_threshold = 1 r.energy_threshold = 300 audio = r.listen(source,0,4) try: print("understanding............") query = r.recognize_google(audio, language='en-in') print(f"you said: {query}\n") except exception as e: print("say that again") speak("say that again") return "none" return query query = takecommand().lower() def googlesearch(query): if "google" in query: query = query.replace("maya", "") query = query.replace("google search", "") query = query.replace("google", "") speak("this is what i found on google.....") try: pywhatkit.search(query) result = googlescrap.summary(query,sentences=2) speak("according to google..........") speak(result) except: speak("no speakable output available") def youtubesearch(query): if "youtube" in query: query = query.replace("maya", "") query = query.replace("youtube search", "") query = query.replace("youtube", "") speak("this is what i found for your search!") web = "https://www.youtube.com/results?search_query=" + query webbrowser.open(web) pywhatkit.playonyt(query) speak("done, sir")
maya_ai.pyCode:
import pyttsx3 import speech_recognition engine = pyttsx3.init("sapi5") voices = engine.getProperty("voices") engine.setProperty("voice", voices[1].id) engine.setProperty("rate", 150) def speak(audio): engine.say(audio) engine.runAndWait() def takeCommand(): r = speech_recognition.Recognizer() with speech_recognition.Microphone() as source: print("listening.............") r.pause_threshold = 1 r.energy_threshold = 300 audio = r.listen(source,0,4) try: print("Understanding............") query = r.recognize_google(audio, language='en-in') print(f"You said: {query}\n") # speak(query) except Exception as e: print("Say that again") return "None" return query if __name__ == "__main__": while True: query = takeCommand().lower() if "wake up" in query: from maya_greeting import greetMe greetMe() while True: query = takeCommand().lower() if "go to sleep" in query: speak("Ok sir, You can call me anytime...") break elif "hello" in query: speak("Hello Sir, how are you?") elif "i am fine" in query: speak("That's really great to know sir....") elif "how are you": speak("i am perfectly alright sir.") elif "thank you" in query: speak("you're welcome sir") elif "google" in query: from maya_google_search import Googlesearch Googlesearch(query) elif "youtube" in query: from maya_google_search import Youtubesearch Youtubesearch(query) elif "wikipedia" in query: from maya_google_search import Wikisearch Wikisearch(query)
If I say google sundar pichai, it will just print what I said and say I'm fine sir, or nothing.
Please help me solve this problem.
Correct Answer
Change
elif "how are you":
for
elif "how are you" in query:
Then you need to add the final else
statement in case none of the previous conditions trigger
The above is the detailed content of I can't generate google/youtube research results in my speech recognition code. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

Using python in Linux terminal...

Fastapi ...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...
