Ask coding questions

← Back to all posts
Speech recognition!!
OathOfCode (27)

Can a developer put in the speech_recognition library!

import speech_recognition
import pyttsx

speech_engine = pyttsx.init('sapi5') # see
speech_engine.setProperty('rate', 150)

def speak(text):

recognizer = speech_recognition.Recognizer()

def listen():
with speech_recognition.Microphone() as source:
audio = recognizer.listen(source)

	return recognizer.recognize_sphinx(audio)
	# or: return recognizer.recognize_google(audio)
except speech_recognition.UnknownValueError:
	print("Could not understand audio")
except speech_recognition.RequestError as e:
	print("Recog Error; {0}".format(e))

return ""

speak("Say something!")
speak("I heard you say " + listen())

Answered by 21natzil (1176) [earned 5 cycles]
View Answer
21natzil (1176)

That's a very cool library! You would have to read it from an audio file however, because at the moment cannot connect to your system's microphone. If you're having trouble finding the packages, click the option bar to the left, and then switch to package search. Search for the pyttsx and enable that, and then also search for SpeechRecognition, and enable that.

PyCoder01 (72)

@21natzil wdym read it from an audio file? I followed a tutorial on VS Code and it worked. But wdym read it from a audio file?

OathOfCode (27)

@PyCoder01 I do know how to use speech recognition in VS Code. I am trying to get it to work in

PyCoder01 (72)

@OathOfCode Yes I know how to make it work in could you friend me on discord

OathOfCode (27)

@PyCoder01 Sure thing! My discord name is Aero so once you see it you'll know who it is.

TheCoderPro9 (0)

yeah, I am trying to make a virtual assistant and speech recognition is not working