<commit_before>#http://doc.aldebaran.com/2-5/naoqi/audio/alspeechrecognition-api.html
import signal
import qi
import argparse
import sys
from os.path import expanduser
import os
import time



class SpeechRecognition(object):
    USE_GOOGLE = True
    CHANNELS = [0, 0, 1, 0]
    audio_recorder = None
    recording = False

    def __init__(self, vocab, app):
        super(SpeechRecognition, self).__init__()

        app.start()
        self.session = app.session

        self.__shutdown_requested = False
        signal.signal(signal.SIGINT, self.signal_handler)

        #Starting services
        self.asr_service = self.session.service("ALSpeechRecognition")
        self.asr_service.setLanguage("English")

        self.audio_recorder = self.session.service("ALAudioRecorder")

        self.memory_service  = self.session.service("ALMemory")

        #establishing test vocabulary
        #vocabulary = ["yes", "no", "please", "hello", "goodbye", "hi, there", "go to the kitchen"]
        with open(vocab) as f:
            content = f.readlines()
        # you may also want to remove whitespace characters like `\n` at the end of each line
        vocabulary = [x.strip() for x in content]
        print "Vocabulary read", vocabulary

        self.asr_service.pause(True)
        #self.asr_service.removeAllContext()
        try:
            self.asr_service.setVocabulary(vocabulary, False)
            #self.asr_service.setParameter("Sensitivity", 0.1)
            self.asr_service.setParameter("NbHypotheses", 3)
        except:
            print "error setting vocabulary"
        self.asr_service.pause(False)

    def start(self):
        # Start the speech recognition engine with user Test_ASR
        self.subscribe_name = "Test_ASR" + str(time.time())
        self.asr_service.subscribe(self.subscribe_name)
        #print 'Speech recognition engine started'

        #subscribe to event WordRecognized
        self.subWordRecognized = self.memory_service.subscriber("WordRecognized")
        #self.idSubWordRecognized = self.subWordRecognized.signal.connect(self.onWordRecognized)

        # speech detected
        self.subSpeechDet = self.memory_service.subscriber("SpeechDetected")
        #self.idSubSpeechDet = self.subSpeechDet.signal.connect(self.onSpeechDetected)

        # enable
        self.subEnable = self.memory_service.subscriber("ASR_enable")
        self.idSubEnable = self.subEnable.signal.connect(self.onEnable)

        #subscribe to google asr transcription
        #if self.USE_GOOGLE:
            #self.audio_recorder.stopMicrophonesRecording()
            #self.googleAsrRecognized = self.memory_service.subscriber("GoogleAsrRecognized")
            #self.idGoogleAsrRecognized = self.googleAsrRecognized.signal.connect(self.onGoogleASR)
<commit_msg>stop blipblip<commit_after>#http://doc.aldebaran.com/2-5/naoqi/audio/alspeechrecognition-api.html
import signal
import qi
import argparse
import sys
from os.path import expanduser
import os
import time



class SpeechRecognition(object):
    USE_GOOGLE = True
    CHANNELS = [0, 0, 1, 0]
    audio_recorder = None
    recording = False

    def __init__(self, vocab, app):
        super(SpeechRecognition, self).__init__()

        app.start()
        self.session = app.session

        self.__shutdown_requested = False
        signal.signal(signal.SIGINT, self.signal_handler)

        #Starting services
        self.asr_service = self.session.service("ALSpeechRecognition")
        self.asr_service.setLanguage("English")

        self.audio_recorder = self.session.service("ALAudioRecorder")

        self.memory_service  = self.session.service("ALMemory")

        #establishing test vocabulary
        #vocabulary = ["yes", "no", "please", "hello", "goodbye", "hi, there", "go to the kitchen"]
        with open(vocab) as f:
            content = f.readlines()
        # you may also want to remove whitespace characters like `\n` at the end of each line
        vocabulary = [x.strip() for x in content]
        print "Vocabulary read", vocabulary

        self.asr_service.pause(True)
        #self.asr_service.removeAllContext()
        try:
            self.asr_service.setVocabulary(vocabulary, False)
            #self.asr_service.setParameter("Sensitivity", 0.1)
            self.asr_service.setParameter("NbHypotheses", 3)
            self.asr_service.setAudioExpression(False)
        except:
            print "error setting vocabulary"
        self.asr_service.pause(False)

    def start(self):
        # Start the speech recognition engine with user Test_ASR
        self.subscribe_name = "Test_ASR" + str(time.time())
        self.asr_service.subscribe(self.subscribe_name)
        #print 'Speech recognition engine started'

        #subscribe to event WordRecognized
        self.subWordRecognized = self.memory_service.subscriber("WordRecognized")
        #self.idSubWordRecognized = self.subWordRecognized.signal.connect(self.onWordRecognized)

        # speech detected
        self.subSpeechDet = self.memory_service.subscriber("SpeechDetected")
        #self.idSubSpeechDet = self.subSpeechDet.signal.connect(self.onSpeechDetected)

        # enable
        self.subEnable = self.memory_service.subscriber("ASR_enable")
        self.idSubEnable = self.subEnable.signal.connect(self.onEnable)

        #subscribe to google asr transcription
        #if self.USE_GOOGLE:
            #self.audio_recorder.stopMicrophonesRecording()
            #self.googleAsrRecognized = self.memory_service.subscriber("GoogleAsrRecognized")
            #self.idGoogleAsrRecognized = self.googleAsrRecognized.signal.connect(self.onGoogleASR)

{'fraction_non_alphanumeric': 0.09665427509293681, 'fraction_numerical': 0.003186404673393521, 'mean_word_length': 2.976073187895848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '4122610', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1653, 'n_words': 330}