Exemplo n.º 1
0
def witAI():
    #loading pygsr Python google speach recognition
    speech = Pygsr()
    raw_input("Ready ?")
    speech.record(5)  # duration in seconds (3)
    try:
        phrase, complete_response = speech.speech_to_text(
            'en_US')  # select the language
    except:
        phrase = "Tell me a joke !"
    print phrase

    phrase = phrase.strip().replace(" ", "%20").encode(
        'ascii')  #if not ascii, curl crashes

    #Wit.ai curl URL
    curl_url = "https://api.wit.ai/message?q=%s" % phrase
    #Auth headers
    curl_header = ["Authorization: Bearer YW3P2YITCYYXGHVLMIE7R7G7BBJODBG4"]
    #debug
    print curl_url
    answer = get_curl(curl_url, curl_header)
    print answer
    result = json.loads(answer)  #parse answer
    return result
Exemplo n.º 2
0
def start():
    speech = Pygsr()
    # duration in seconds
    speech.record(4)

    output = "log.csv"
    input = "audio.flac"
    if input[-5:] != '.flac':
        input += '*.flac'
    files = glob.glob(input)

    for flac in files:
        print "opening %s:" % flac
        valid_result = False
        tries = 0
        with open(flac, 'rb') as f:
            result = GoogleSpeechAPI(f)
            print "Audio is %.03f seconds long" % result.length
            f.seek(0)
            with Timer() as t:
                result.start()
        print "Result took %.03f sec" % t.interval
        print result.result

        out = ''.join(result.result)
        split3 = ""
        try:
            split1 = [x.strip() for x in out.split(':')]
            split2 = split1[3]
            split3 = [x.strip() for x in split2.split(',')]
            #[1:-1] is to remove double quotes from string
            print split3[0][1:-1]
            return split3[0][1:-1]
        except Exception, e:
            print "Exception"
Exemplo n.º 3
0
    def srprocess(self,threadname):
        speech = Pygsr()
		speech.record(3)
		try:
		    phrase, complete_response = speech.speech_to_text('ar_AE')
		except:
		    phrase = ''
		    global do_flage
		    do_flage = False
		self.save_text(phrase+' ')     
Exemplo n.º 4
0
 def __init__(self):
     self.speech = Pygsr()
Exemplo n.º 5
0
from pygsr import Pygsr
speech = Pygsr()
# duration in seconds (3)
speech.record(3)
# select the language and obtain the result
phrase, complete_response = speech.speech_to_text('es_ES')
print phrase
Exemplo n.º 6
0
 def listen(self):
     speech = Pygsr()
     speech.record(2)
     phrase, complete_response = speech.speech_to_text('en_IN')
     print phrase
Exemplo n.º 7
0
 def __init__(self):
     global logger
     logger = logging.getLogger(__name__)
     self.speech = Pygsr()