From dd133d3738162e184f206d112ea4a39ba43f0781 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 30 Aug 2014 17:44:47 +0100 Subject: Handle all Google Speech options --- client/stt.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'client/stt.py') diff --git a/client/stt.py b/client/stt.py index bcfdfba..9191bf5 100644 --- a/client/stt.py +++ b/client/stt.py @@ -79,7 +79,7 @@ class PocketSphinxSTT(object): print "JASPER: " + result[0] print "===================" - return result[0] + return [result[0]] """ Speech-To-Text implementation which relies on the Google Speech API. @@ -138,14 +138,18 @@ class GoogleSTT(object): response = self.http.post(url, data=data, headers=headers) response.encoding = 'utf-8' response_read = response.text - decoded = json.loads(response_read.split("\n")[1]) - - text = decoded['result'][0]['alternative'][0]['transcript'] - if text: - print "===================" - print "JASPER: " + text - print "===================" - return text + + response_parts = response_read.strip().split("\n") + decoded = json.loads(response_parts[-1]) + if decoded['result']: + texts = [alt['transcript'] for alt in decoded['result'][0]['alternative']] + if texts: + print "===================" + print "JASPER: " + ', '.join(texts) + print "===================" + return texts + else: + return [] except Exception: traceback.print_exc() -- cgit v1.3.1