Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
class HearingModule:
    def __init__(self):
        self.speech = Pygsr()

    def listen(self, t):
        self.speech.record(t)
        phrase, complete_response = self.speech.sepeech_to_text('en_EN')
        return phrase

    def connected(self):
        if self.speech:
            return True
        return False
Exemplo n.º 6
0
class Recorder:
    def __init__(self):
        global logger
        logger = logging.getLogger(__name__)
        self.speech = Pygsr()

    def record_command(self):
        ''' Records audio and sends it to google to translate to text.

        '''
        self.speech.record(settings.RECORD_LENGTH)
        result = self.speech.speech_to_text()
        line = None
        if result:
            line = result[0].lower()
        if not line:
            logger.warn('No command recorded.')
            return None
        logger.info(line)
        command = Command(line)
        logger.info(command)
        return command
Exemplo n.º 7
0
Arquivo: test_wit.py Projeto: Xqua/wit
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.º 8
0
 def _voice_input(self, duration):
     speech = Pygsr()
     speech.record(duration)
     phrase, complete_response = speech.speech_to_text(self.lang)
     return phrase
Exemplo n.º 9
0
from pygsr import Pygsr
import sys
import os

def set_proc_name(newname):
    from ctypes import cdll, byref, create_string_buffer
    libc = cdll.LoadLibrary('libc.so.6')
    buff = create_string_buffer(len(newname)+1)
    buff.value = newname
    libc.prctl(15, byref(buff), 0, 0, 0)

def get_proc_name():
    from ctypes import cdll, byref, create_string_buffer
    libc = cdll.LoadLibrary('libc.so.6')
    buff = create_string_buffer(128)
    # 16 == PR_GET_NAME from <linux/prctl.h>
    libc.prctl(16, byref(buff), 0, 0, 0)
    return buff.value

set_proc_name('Mwave_gspeech')

speech = Pygsr()
speech.record(2) # duration in seconds (3)
phrase, complete_response = speech.speech_to_text('en-US') # select the language
os.remove('audio')
os.remove('audio.flac')
print phrase
Exemplo n.º 10
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.º 11
0
            f.close()
	    Popen(['mplayer', 'data.mp3', '-really-quiet']).wait()
            #os.system('mplayer -ao alsa -noconsolecontrols data.mp3')

if __name__ == '__main__':
    x = Record()
    x.setup()
    recorded = False
    response = None
    while response is not 'exit':
        x.read()
        rms = audioop.rms(x.data, 2)
        print rms
        if rms > x.threshold:
            speech = Pygsr()
            speech.record(5)
            phrase, complete_response = speech.speech_to_text('en_EN')
            response = x.custom(phrase)
            if response == False:
                response = x.Wolfram(phrase)
                if response == False:
                    response = x.cleverbot(phrase)
            print('PHRASEPHRASEPHRASE')
            print(phrase)
            print(response)
            x.speak(response)
            recorded = True
            rms = 0
        x.setup()
            
Exemplo n.º 12
0
#!/usr/bin/python

from pygsr import Pygsr
speech = Pygsr()
speech.record(3)
phrase, complete_response = speech.speech_to_text('de_DE')
print phrase
Exemplo n.º 13
0
from pygsr import Pygsr
speech = Pygsr()
speech.record(3)  # duration in seconds (3)
phrase, complete_response = speech.speech_to_text(
    'es_ES')  # select the language
print phrase
Exemplo n.º 14
0
 def listen(self):
     speech = Pygsr()
     speech.record(2)
     phrase, complete_response = speech.speech_to_text('en_IN')
     print phrase
Exemplo n.º 15
0
 def listen(self):
     speech = Pygsr()
     speech.record(2)
     phrase, complete_response = speech.speech_to_text('en_IN')
     print phrase