Skip to content

Commit

Permalink
Fix Python syntax errors and undefined names
Browse files Browse the repository at this point in the history
  • Loading branch information
cclauss committed Apr 15, 2018
1 parent 26f49a6 commit 7d82c53
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
16 changes: 6 additions & 10 deletions examples/Python/demo4.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def audioRecorderCallback(fname):
print "converting audio to text"
print("converting audio to text")
r = sr.Recognizer()
with sr.AudioFile(fname) as source:
audio = r.record(source) # read the entire audio file
Expand All @@ -29,9 +29,9 @@ def audioRecorderCallback(fname):
# instead of `r.recognize_google(audio)`
print(r.recognize_google(audio))
except sr.UnknownValueError:
print "Google Speech Recognition could not understand audio"
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print "Could not request results from Google Speech Recognition service; {0}".format(e)
print("Could not request results from Google Speech Recognition service; {0}".format(e))

os.remove(fname)

Expand All @@ -51,8 +51,8 @@ def interrupt_callback():
return interrupted

if len(sys.argv) == 1:
print "Error: need to specify model name"
print "Usage: python demo.py your.model"
print("Error: need to specify model name")
print("Usage: python demo.py your.model")
sys.exit(-1)

model = sys.argv[1]
Expand All @@ -61,7 +61,7 @@ def interrupt_callback():
signal.signal(signal.SIGINT, signal_handler)

detector = snowboydecoder.HotwordDetector(model, sensitivity=0.38)
print "Listening... Press Ctrl+C to exit"
print("Listening... Press Ctrl+C to exit")

# main loop
detector.start(detected_callback=detectedCallback,
Expand All @@ -70,7 +70,3 @@ def interrupt_callback():
sleep_time=0.01)

detector.terminate()




9 changes: 7 additions & 2 deletions examples/Python/demo_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
import signal
import time

try:
raw_input # Python 2
except NameError:
raw_input = input # Python 3

stop_program = False

# This a demo that shows running Snowboy in another thread
Expand Down Expand Up @@ -40,8 +45,8 @@ def signal_handler(signal, frame):
try:
num1 = int(raw_input("Enter the first number to add: "))
num2 = int(raw_input("Enter the second number to add: "))
print "Sum of number: {}".format(num1 + num2)
print("Sum of number: {}".format(num1 + num2))
except ValueError:
print "You did not enter a number."
print("You did not enter a number.")

threaded_detector.terminate()
22 changes: 11 additions & 11 deletions examples/Python/snowboydecoder_arecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import wave
import os
import sys
import logging
import subprocess
import threading
Expand Down Expand Up @@ -180,16 +181,16 @@ def start(self, detected_callback=play_audio_file,
callback = detected_callback[ans-1]
if callback is not None:
callback()
matrix_demos_dir = "/home/pi/matrix-creator-hal/build/demos/"
beamforming_result_path = "/tmp/beamforming_result.flac"
cwd = os.getcwd()
print("Running from " + cwd)
os.system(matrix_demos_dir + "micarray_recorder")
print("Voice recording complete")
os.system("sox -r 16000 -c 1 -e signed -b 16 " + cwd + "/mic_16000_s16le_channel_8.raw /tmp/channel_8.wav")
os.system("flac -f -s /tmp/channel_8.wav -o /tmp/beamforming_result.flac")
print("Conversion from raw to flac complete")
#wsk_transcribe_audio("/tmp/beamforming_result.flac")
matrix_demos_dir = "/home/pi/matrix-creator-hal/build/demos/"
beamforming_result_path = "/tmp/beamforming_result.flac"
cwd = os.getcwd()
print("Running from " + cwd)
os.system(matrix_demos_dir + "micarray_recorder")
print("Voice recording complete")
os.system("sox -r 16000 -c 1 -e signed -b 16 " + cwd + "/mic_16000_s16le_channel_8.raw /tmp/channel_8.wav")
os.system("flac -f -s /tmp/channel_8.wav -o /tmp/beamforming_result.flac")
print("Conversion from raw to flac complete")
#wsk_transcribe_audio("/tmp/beamforming_result.flac")
logger.debug("finished.")

def terminate(self):
Expand All @@ -199,4 +200,3 @@ def terminate(self):
"""
self.recording = False
self.record_thread.join()

6 changes: 2 additions & 4 deletions examples/Python3/demo4.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import snowboydecoder
import sys
import signal
Expand Down Expand Up @@ -69,7 +71,3 @@ def interrupt_callback():
sleep_time=0.01)

detector.terminate()




8 changes: 4 additions & 4 deletions examples/REST_API/training_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_wave(fname):
try:
[_, wav1, wav2, wav3, out] = sys.argv
except ValueError:
print "Usage: %s wave_file1 wave_file2 wave_file3 out_model_name" % sys.argv[0]
print("Usage: %s wave_file1 wave_file2 wave_file3 out_model_name" % sys.argv[0])
sys.exit()

data = {
Expand All @@ -46,7 +46,7 @@ def get_wave(fname):
if response.ok:
with open(out, "w") as outfile:
outfile.write(response.content)
print "Saved model to '%s'." % out
print("Saved model to '%s'." % out)
else:
print "Request failed."
print response.text
print("Request failed.")
print(response.text)

0 comments on commit 7d82c53

Please sign in to comment.