Skip to content

Commit d550d3a

Browse files
shahjui2000prateekiiest
authored andcommitted
Update stt.py (prateekiiest#161)
1 parent 4f6ad2a commit d550d3a

File tree

1 file changed

+13
-10
lines changed
  • Code-Sleep-Python/speech-to-text

1 file changed

+13
-10
lines changed
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import speech_recognition as sr
22

33
r = sr.Recognizer()
4+
flag = 1
5+
while flag=1:
6+
7+
with sr.Microphone() as source:
8+
print("Say something... ")
9+
audio = r.listen(source)
410

5-
with sr.Microphone() as source:
6-
print("Say something... ")
7-
audio = r.listen(source)
8-
9-
try:
10-
print("Google thinks you said: {}".format(r.recognize_google(audio)))
11-
except sr.UnkownValueError:
12-
print("Couldn't understand")
13-
except sr.RequestError as e:
14-
print("Couldn't request results; {}".format(e))
11+
try:
12+
print("Google thinks you said: {}".format(r.recognize_google(audio)))
13+
flag = 0
14+
except sr.UnkownValueError:
15+
print("Couldn't understand your voice. Please speak again.")
16+
except sr.RequestError as e:
17+
print("Couldn't request results. Please speak again.; {}".format(e))

0 commit comments

Comments
 (0)