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"
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
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"
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+' ')
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
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
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
def _voice_input(self, duration): speech = Pygsr() speech.record(duration) phrase, complete_response = speech.speech_to_text(self.lang) return phrase
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
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
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()
#!/usr/bin/python from pygsr import Pygsr speech = Pygsr() speech.record(3) phrase, complete_response = speech.speech_to_text('de_DE') print phrase
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
def listen(self): speech = Pygsr() speech.record(2) phrase, complete_response = speech.speech_to_text('en_IN') print phrase
def listen(self): speech = Pygsr() speech.record(2) phrase, complete_response = speech.speech_to_text('en_IN') print phrase