<commit_before>import os, sys, subprocess, threading, time, json, re, signal, snowboydecoder
import requests
from requests.auth import HTTPBasicAuth
from ws4py.client.threadedclient import WebSocketClient
from watson_developer_cloud import ConversationV1
import Adafruit_PCA9685

STTusername = os.environ['WTTSusername']
STTpassword = os.environ['WTTSpassword']
WAusername = os.environ['WCusername']
WApassword = os.environ['WCpassword']
WAworkspace_id = os.environ['WCworkspace']

conversation = ConversationV1(
    username=WAusername,
    password=WApassword,
version='2018-02-16')

print "STT Username: " + str(STTusername)
print "STT Password: " + str(STTpassword)
print "WA Username: " + str(WAusername)
print "WA Password: " + str(<PASSWORD>)
print "WA Workspace: " + str(WAworkspace_id)

r = requests.get('https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api', auth=HTTPBasicAuth(STTusername, STTpassword))
print r.status_code
auth_token = (r.content)

# Initialising TTS global variables
speech_received = False # has speech been returned by Watson?
transcript = "silence"	# default value for speech if nothing returned

# Initialise snowboy global variables
model = "./K9.pmdl"
interrupted = False

# Initialise the PWM device using the default address
#pwm = Adafruit_PCA9685.PCA9685()
#pwm.set_pwm_freq(100)  # Set frequency to 100 Hz
pwm=0

# Create names for each PWM channel
PWM_eye = 0
PWM_hover = 1

def signal_handler(signal, frame):
	global interrupted
	interrupted = True

def interrupt_callback():
	global interrupted
	return interrupted

signal.signal(signal.SIGINT, signal_handler)
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)

class SpeechToTextClient(WebSocketClient):

    def __init__(self):
        ws_url = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize'
        self.listening = False
        try:
            WebSocketClient.__init__(self, ws_url,
            headers=[("X-Watson-Authorization-Token",auth_token)])
            self.connect()
        except: print "Failed to open WebSocket."

    def opened(self):
        print "opened(self) and self.send"
        self.send('{"action":"start","content-type":"audio/l16;rate=16000","inactivity_timeout":1,"interim_results": true}')
        self.stream_audio_thread = threading.Thread(target=self.stream_audio)
        self.stream_audio_thread.start()
    def received_message(self, message):
        global speech_received
        global transcript
        global pwm
        message = json.loads(str(message))
        print "Received: " + str(message)
        if "state" in message and not speech_received:
            if message["state"] == "listening":
                self.listening = True
                set_PWM(PWM_eye,100)
                print "Speak now..."
        if "results" in message:
            self.listening = False
            speech_received = True
            print "Sending stop transcription message"
            self.send('{"action": "stop"}')
            results = re.search('transcript\'\: u\'(.*)\'\}\]', str(message))
            if results:<commit_msg>Remove interim results<commit_after>import os, sys, subprocess, threading, time, json, re, signal, snowboydecoder
import requests
from requests.auth import HTTPBasicAuth
from ws4py.client.threadedclient import WebSocketClient
from watson_developer_cloud import ConversationV1
import Adafruit_PCA9685

STTusername = os.environ['WTTSusername']
STTpassword = os.environ['WTTSpassword']
WAusername = os.environ['WCusername']
WApassword = os.environ['WCpassword']
WAworkspace_id = os.environ['WCworkspace']

conversation = ConversationV1(
    username=WAusername,
    password=<PASSWORD>,
version='2018-02-16')

print "STT Username: " + str(STTusername)
print "STT Password: " + str(STTpassword)
print "WA Username: " + str(WAusername)
print "WA Password: " + str(WApassword)
print "WA Workspace: " + str(WAworkspace_id)

r = requests.get('https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api', auth=HTTPBasicAuth(STTusername, STTpassword))
print r.status_code
auth_token = (r.content)

# Initialising TTS global variables
speech_received = False # has speech been returned by Watson?
transcript = "silence"	# default value for speech if nothing returned

# Initialise snowboy global variables
model = "./K9.pmdl"
interrupted = False

# Initialise the PWM device using the default address
#pwm = Adafruit_PCA9685.PCA9685()
#pwm.set_pwm_freq(100)  # Set frequency to 100 Hz
pwm=0

# Create names for each PWM channel
PWM_eye = 0
PWM_hover = 1

def signal_handler(signal, frame):
	global interrupted
	interrupted = True

def interrupt_callback():
	global interrupted
	return interrupted

signal.signal(signal.SIGINT, signal_handler)
detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)

class SpeechToTextClient(WebSocketClient):

    def __init__(self):
        ws_url = 'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize'
        self.listening = False
        try:
            WebSocketClient.__init__(self, ws_url,
            headers=[("X-Watson-Authorization-Token",auth_token)])
            self.connect()
        except: print "Failed to open WebSocket."

    def opened(self):
        print "opened(self) and self.send"
        self.send('{"action":"start","content-type":"audio/l16;rate=16000","inactivity_timeout":1}')
        self.stream_audio_thread = threading.Thread(target=self.stream_audio)
        self.stream_audio_thread.start()
    def received_message(self, message):
        global speech_received
        global transcript
        global pwm
        message = json.loads(str(message))
        print "Received: " + str(message)
        if "state" in message and not speech_received:
            if message["state"] == "listening":
                self.listening = True
                set_PWM(PWM_eye,100)
                print "Speak now..."
        if "results" in message:
            self.listening = False
            speech_received = True
            print "Sending stop transcription message"
            self.send('{"action": "stop"}')
            results = re.search('transcript\'\: u\'(.*)\'\}\]', str(message))
            if results:
{'fraction_non_alphanumeric': 0.11133955400917286, 'fraction_numerical': 0.0151826664557963, 'mean_word_length': 3.6844444444444444, 'pattern_counts': {'":': 11, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1313820', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1888, 'n_words': 448}