I have a Python voice-enabled chatbot that plays and records audio. However, the chatbot is also recognizing its own audio output as input. Is there a way to prevent this? Is there a specific app that can be used to route audio from one app to another?
def play_audio(file_name):
audio_path = os.path.join(path, file_name)
data, fs = sf.read(audio_path)
sd.play(data, fs)
sd.wait()
def rec_audio():
recog = sr.Recognizer()
with sr.Microphone() as source:
print("Listening... From Site Rec..")
audio = recog.listen(source)
data = ""
try:
data = recog.recognize_google(audio)
print("User: " + data)
except sr.UnknownValueError:
print("Machine coudn't process..")
play_audio("voice break.mp3")
except sr.RequestError as ex:
print("Google side" + str(ex))
play_audio("RequestError.mp3")
return data
both of these code run simultaneously using threading. is there any way to route the audios??
I wanted the machine not to recognize its own playback audio but to observe the audio only from the microphone..
Use this to see all the inputs that you have on your device -
sr.Microphone()encompasses many inputs.For example, I got:
Now, use this code to listen to ONLY the input that you want:
As you didn't post which modules you are using or the full code for testing I can't verify that this will solve your problem, but I believe it should.