Check if text is egual to "x" speech_recognition Python - python

I'm working with speech_recognition python and I want to know if It's possible to check if the text that I've said is egual to "x"
Here is my code :
import speech_recognition
import speech_recognition as sr
import pyttsx3
recognizer = speech_recognition.Recognizer()
while True:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic, duration=0.2)
audio = recognizer.listen(mic)
text = recognizer.recognize_google(audio, language="fr-FR")
text = text.lower()
print(text)
except speech_recognition.UnknownValueError():
print("I don't understand sir")
continue
I've checked
if (text == "x"):
But it didn't works

Related

How to make voice detection in python faster?

I have some voice detection code and it works! but, it runs really slowly. Can I do anything to make it faster?
import speech_recognition
import pyttsx3
recognizer = speech_recognition.Recognizer()
while True:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic, duration=0.2)
audio = recognizer.listen(mic)
text = recognizer.recognize_google(audio)
text = text.lower()
print(f" {text}")
except speech_recognition.UnknownValueError():
recognizer = speech_recognition.Recognizer()
continue
Try creating mic once instead of each iteration:
import speech_recognition
import pyttsx3
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as mic:
while True:
try:
recognizer.adjust_for_ambient_noise(mic, duration=0.2)
audio = recognizer.listen(mic)
text = recognizer.recognize_google(audio)
text = text.lower()
print(f" {text}")
except speech_recognition.UnknownValueError():
pass

I can't run my code - python, speech_recognition

import speech_recognition
robot_ear = speech_recognition.Recognizer()
with speech_recognition.Microphone() as mic:
print("Robot: i'm Listening")
audio = robot_ear.listen(mic)
try:
you = robot_ear.recognize_google(audio)
except:
you == ""
print("You: " + you)
I run but and i say but It doesn't print anything, my name of the code is not speech_recognition.

Reduce speech recognition latency

In SpeechRecognition, when I start speech recognition and speak, I'm recognized a few seconds after the end of the talk, but can't I shorten the time it takes for my words to end and become recognized?
import speech_recognition as sr
from speech_recognition import *
import pyaudio
import os
translator = googletrans.Translator()
r = Recognizer()
m = Microphone()
while 1 == True:
with m as source:
print('ready')
audio = r.listen(source)
Text = r.recognize_google(audio, language='en')
print(Text)

how to compare voice with list in python

here is my code I'm using pocketsphinx I want to compare my voice with these words but it's not working.
from pocketsphinx import LiveSpeech
import speech_recognition as sr
'''The start of Speech system is here,'''
def chair_offline():
words = ["LEFT","RIGHT","FORWARD","BACKWARD","STOP","RUN"]
r = sr.Recognizer()
for audioo in LiveSpeech():
res = str(audioo)
if res in words:
print(res)
else:
print("sorry modle not train")
chair_offline()

integrate speech recognition and tkinter

I'm doing a project on speech recognition and am trying to use Tkinter to create a GUI for my project...the SR part works well but when I integrate it with Tkinter it doesn't work...please help. (am new to programming so please don't mind my code:) )
#MY CODE
import speech_recognition as sr
import tkinter as tk
obj = tk.Tk()
obj.title("SpeechToText")
obj.geometry('400x200')
obj.resizable(0,0)
def rec():
r = sr.Recognizer()
msg.configure(text="Say something")
while True:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
txt = "".format(r.recognize_google(audio).get())
msg.configure(text=txt)
except Exception as e:
print(e)
break
msg = tk.Label()
msg.grid(row=0,column=0)
btn = tk.Button(text="Start",command=rec)
btn.grid(row=2,column=0)
obj.mainloop()
I would like it to display the translated text in the label but it doesn't. It only shows "say something" even after speaking.
Try this, I blocked out the msg.configure(text='Say Somethin'). This line makes the recorded text being reformatted to 'Say Something' and not the text that was recorded. Hope this helps.
import speech_recognition as sr
import tkinter as tk
obj = tk.Tk()
obj.title("SpeechToText")
obj.geometry('400x200')
obj.resizable(0,0)
def rec():
r = sr.Recognizer()
#msg.configure(text="Say something")
while True:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
txt = r.recognize_google(audio)
msg.configure(text=txt)
print(txt)
except Exception as e:
print(e)
break
msg = tk.Label()
msg.grid(row=0,column=0)
btn = tk.Button(text="Start",command=rec)
btn.grid(row=2,column=0)
obj.mainloop()

Categories

Resources