forked from Uberi/speech_recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensorflow_commands.py
26 lines (20 loc) · 961 Bytes
/
tensorflow_commands.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python3
import time
import speech_recognition as sr
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio # noqa
# obtain audio from the microphone
r = sr.Recognizer()
m = sr.Microphone()
with m as source:
r.adjust_for_ambient_noise(source)
def callback(recognizer, audio):
try:
# You can download the data here: http://download.tensorflow.org/models/speech_commands_v0.01.zip
spoken = recognizer.recognize_tensorflow(audio, tensor_graph='speech_recognition/tensorflow-data/conv_actions_frozen.pb', tensor_label='speech_recognition/tensorflow-data/conv_actions_labels.txt')
print(spoken)
except sr.UnknownValueError:
print("Tensorflow could not understand audio")
except sr.RequestError as e:
print("Could not request results from Tensorflow service; {0}".format(e))
stop_listening = r.listen_in_background(m, callback, phrase_time_limit=0.6)
time.sleep(100)