Skip to content

Commit cd39055

Browse files
committed
allow user to disable/enable speech synthesis
1 parent eb9f858 commit cd39055

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

config/config.obj_detect.sample.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## ATTENTION: Do not modify 'config.object_detection.sample.yml' !! You should create a copy named 'config.object_detection.yml' and modify that one !!
44

55

6+
# see https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md
67
model_name: 'ssd_mobilenet_v1_coco_11_06_2017'
78
model_dl_base_path: 'http://download.tensorflow.org/models/object_detection/'
89
model_dl_file_format: '.tar.gz'
@@ -21,3 +22,6 @@ input_video: 0
2122

2223
# visualize the results of the object detection
2324
visualizer_enabled: True
25+
26+
# synthesize speech (using Amazon Polly as of now)
27+
speech_enabled: True

obj_detect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# ## Download Model
4747
MODEL_FILE = cfg['model_name'] + cfg['model_dl_file_format']
4848
if not os.path.isfile(PATH_TO_CKPT):
49-
print('Model not found. We will download it now.')
49+
print('Model not found. Downloading it now.')
5050
opener = urllib.request.URLopener()
5151
opener.retrieve(cfg['model_dl_base_path'] + MODEL_FILE, '../' + MODEL_FILE)
5252
tar_file = tarfile.open('../' + MODEL_FILE)
@@ -82,7 +82,7 @@
8282
# TODO: Usually FPS calculation lives in a separate thread. As is now, the interval is a minimum value for each iteration.
8383
fps = FPS(cfg['fps_interval']).start()
8484
vis = Visualizer(cfg['visualizer_enabled'])
85-
proc = Processor()
85+
proc = Processor(cfg['speech_enabled'])
8686

8787
while(input.isActive()):
8888
# startTime=datetime.now()

stuff/helper.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def fps(self):
5151

5252

5353
class Visualizer:
54-
def __init__(self, enabled):
55-
self._enabled = enabled
54+
def __init__(self, visualizer_enabled):
55+
self._enabled = visualizer_enabled
5656
self._windowPlaced = False
5757
self._screen = display.Display().screen().root.get_geometry()
5858

@@ -86,8 +86,10 @@ def cleanup(self):
8686

8787

8888
class Processor:
89-
def __init__(self):
90-
self._speech = SpeechSynthesizer()
89+
def __init__(self, speech_enabled):
90+
self._speech_enabled = speech_enabled
91+
if self._speech_enabled:
92+
self._speech = SpeechSynthesizer()
9193

9294
def process(self, boxes, scores, classes, num, image_shape):
9395

@@ -115,7 +117,7 @@ def getIndefiniteArticle(word):
115117
"""
116118
return 'an' if word[:1].lower() in 'aeiou' else 'a'
117119

118-
if(len(obj) > 0):
120+
if(self._speech_enabled and len(obj) > 0):
119121
self._speech.request("I am " + str(obj[0][1]) + "% certain I see " + getIndefiniteArticle(obj[0][0]) + " " + obj[0][0])
120122

121123
def cleanup(self):

0 commit comments

Comments
 (0)