Skip to content

Commit

Permalink
Speech Recognition sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
kalebujordan committed Sep 12, 2020
0 parents commit cc87ecc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import speech_recognition as sr

recognizer = sr.Recognizer()

with sr.Microphone() as source:
print("Adjusting noise ")
recognizer.adjust_for_ambient_noise(source, duration=1)
print("Recording for 4 seconds")
recorded_audio = recognizer.listen(source, timeout=4)
print("Done recording")

try:
print("Recognizing the text")
text = recognizer.recognize_google(
recorded_audio,
language="en-US"
)

print("Decoded Text : {}".format(text))

except Exception as ex:

print(ex)


sr.Microphone.list_microphone_names()
21 changes: 21 additions & 0 deletions app_audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import speech_recognition as sr

recognizer = sr.Recognizer()

''' recording the sound '''

with sr.AudioFile("./sample_audio/speech.wav") as source:
recorded_audio = recognizer.listen(source)
print("Done recording")

''' Recorgnizing the Audio '''
try:
print("Recognizing the text")
text = recognizer.recognize_google(
recorded_audio,
language="en-US"
)
print("Decoded Text : {}".format(text))

except Exception as ex:
print(ex)
Binary file added sample_audio/speech.wav
Binary file not shown.

0 comments on commit cc87ecc

Please sign in to comment.