Skip to content

Instantly share code, notes, and snippets.

@ProjectEli
Created May 5, 2021 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ProjectEli/e7182f0873f8d28dbbf5eeab6781a034 to your computer and use it in GitHub Desktop.
Save ProjectEli/e7182f0873f8d28dbbf5eeab6781a034 to your computer and use it in GitHub Desktop.
Voice recognition with speech_recognition and google speech to text API
import speech_recognition
recognizer = speech_recognition.Recognizer()
with speech_recognition.Microphone() as src:
try:
audio = recognizer.adjust_for_ambient_noise(src)
print("Threshold Value After calibration:" + str(recognizer.energy_threshold))
print("Please speak:")
audio = recognizer.listen(src)
speech_to_txt = recognizer.recognize_google(audio,language="ko-KR").lower()
print(speech_to_txt)
except Exception as ex:
print("Sorry. Could not understand.")
print("err name: " + str(ex))
if (speech_to_txt == "안녕하세요"):
print("답변: 네 저도 안녕하세요")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment