def getAnswer(fileName): client = StreamingHoundClient(CLIENT_KEY, CLIENT_ID) client.setLocation(37.388309, -121.973968) #fname = "whatistheweatherthere.wav" fname = fileName print "============== %s ===================" % fname audio = wave.open(fname) samples = audio.readframes(BUFFER_SIZE) finished = False client.start(MyListener()) while not finished: finished = client.fill(samples) time.sleep( 0.032) ## simulate real-time so we can see the partial transcripts samples = audio.readframes(BUFFER_SIZE) if len(samples) == 0: break client.finish() global gotAnswer while not gotAnswer: pass gotAnswer = False return outputString
class HoundifyEngine(PersonalAssistantBase, HoundListener): def __init__(self, context): self.context = context self.client_id = context.config.get("houndify", "client_id") self.client_key = context.config.get("houndify", "client_key") def ask_text(self, what): print("you said: " + what) def open(self): self.client = StreamingHoundClient(self.client_id, self.client_key, sampleRate=16000) self.client.setLocation(37.388309, -121.973968) self._active = True self.client.start(self) def send(self, in_data, frame_count): self._active = not self.client.fill(in_data) def close(self): self.client.finish() pass def getresponse(self): return self.outputString def get_result(self): return self.Result def onPartialTranscript(self, transcript): pass def onFinalResponse(self, response): print "response: " + str(response) string = response["AllResults"][0]["SpokenResponseLong"] self.outputString = string self.Result = HoundifyResult(response) self._active = False def onTranslatedResponse(self, response): print "Translated response: " + response def onError(self, err): print "ERROR"
def getAnswer(fileName): client = StreamingHoundClient(CLIENT_KEY, CLIENT_ID) client.setLocation(37.388309, -121.973968) fname = fileName print "============== %s ===================" % fname audio = wave.open(fname) samples = audio.readframes(BUFFER_SIZE) finished = False client.start(MyListener()) while not finished: finished = client.fill(samples) time.sleep(0.032) ## simulate real-time so we can see the partial transcripts samples = audio.readframes(BUFFER_SIZE) if len(samples) == 0: break client.finish() global gotAnswer while not gotAnswer: pass gotAnswer = False return outputString
def open(self): self.client = StreamingHoundClient(self.client_id, self.client_key, sampleRate=16000) self.client.setLocation(37.388309, -121.973968) self._active = True self.client.start(self)