Beispiel #1
0
def maluuba_knowledge(text):

    text = text.split()
    text = "+".join(text)
    print text
    webbrowser.open("www.google.com/?#newwindow=1&q=" + text)
    robot_voice.robot_voice("here are google results about your question")
Beispiel #2
0
def detect():
    file_name=camera()
    if file_name=="":
        robot_voice.robot_voice("The system did not receive a shot, can't initiate face recognition.")
        return 
    else:
        data = {
                'api_key': 'ec1b919cb0c3498c90ceca359240dbba',
                'api_secret': '68bc15bbd0324b928d1004b47987be33',
                'uids':'master@smarthome_example',
                'attributes':'all'
            }
        f=open(file_name,'rb')
        files={'file':f}
        #files = {'file': open(file_name,'rb')}
        url = 'http://api.skybiometry.com/fc/faces/recognize.json'
        req = requests.post(url, data=data, files=files)
        response=req.content
        response_transformed=json.loads(response)
        print response_transformed
        attribute=((response_transformed['photos'][0]['tags'])[0]['attributes'])
        issmile=attribute['smiling']['value']
        print issmile
        f.close()
        
        os.remove(file_name)
        return issmile
Beispiel #3
0
def maluuba_navigation(r):
    # print r.entities
    text = r.entities["destination"][0].encode("utf-8")
    text = text.split()
    text = "+".join(text)
    # print text
    webbrowser.open("maps.google.com/?q=" + text)
    robot_voice.robot_voice("here is the location you are looking for")
Beispiel #4
0
Datei: ui.py Projekt: guanw/GP
 def OnDetect(self,event):
     issmile=detect.detect()
     if issmile=='false':
         robot_voice.robot_voice("I think you are not in a good mood. Let me play something for you.")
         play_music.play_music()
     elif issmile=='true':
         robot_voice.robot_voice("That's a big nice smile of you! Did you have a good day?")
     elif issmile==-1:
         print("don't even know if this person is the master")
Beispiel #5
0
def main():
    content=weather_description()
    content=json.loads(content)
    minDegree=content['data']['weather'][0]['tempMinC']
    maxDegree=content['data']['weather'][0]['tempMaxC']
    weather=content['data']['weather'][0]['weatherDesc'][0]['value']
    text="It's "+weather+" outside with a lowest degree of "+minDegree+" and a highest degree of "+maxDegree
    print text
    robot_voice.robot_voice(text)
Beispiel #6
0
def maluuba_search(r, text):
    # print r.entities
    if r.action == u"SEARCH_WIKIPEDIA":
        text = r.entities["searchterm"][0].encode("utf-8")
        webbrowser.open("https://en.wikipedia.org/wiki/" + text)
        robot_voice.robot_voice("here are wiki results about your question")
    elif r.action == u"SEARCH_GOOGLE":
        text = r.entities["searchterm"][0].encode("utf-8")
        text = text.split()
        text = "+".join(text)
        webbrowser.open("www.google.com/?#newwindow=1&q=" + text)
        robot_voice.robot_voice("here are google results about your question")
Beispiel #7
0
def recordSound():
    pa = PyAudio() 
    stream = pa.open(format=paInt16, channels=1, rate=SAMPLING_RATE, input=True, 
                    frames_per_buffer=NUM_SAMPLES) 

    save_count = 0 
    save_buffer = [] 

    while True: 
        
        string_audio_data = stream.read(NUM_SAMPLES) 
        
        audio_data = np.fromstring(string_audio_data, dtype=np.short) 
        
        large_sample_count = np.sum( audio_data > LEVEL )

        global ProgressBar
        ProgressBar=np.max(audio_data)
        #print np.max(audio_data) 
        #print "progressbar in thread:",ProgressBar
        
        if large_sample_count > COUNT_NUM: 
            save_count = SAVE_LENGTH 
        else: 
            save_count -= 1 

        if save_count < 0: 
            save_count = 0 

        if save_count > 0: 
            
            save_buffer.append( string_audio_data ) 
        else: 
            
            if len(save_buffer) > 0:  
                filename="recordSound.wav"
                save_wave_file(filename, save_buffer) 
                save_buffer = [] 
                print filename, "saved"

                print "record end, transform begin"
                cmd_path1='flac.exe recordSound.wav recordSound.flac -f'
                os.system(cmd_path1)
                print "transform finish"

                FILE='recordSound.flac'
                #url = 'http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=en-US'
                url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=en_US&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw'
                #url = 'https://www.google.com/speech-api/v2/recognize?output=json&lang=en_US&key=AIzaSyCnl6MRydhw_5fLXIdASxkLJzcJh5iX0M4'
                audio=open(FILE,'rb').read()
                headers = {'Content-Type' : 'audio/x-flac; rate=16000'}
                req = urllib2.Request(url, audio, headers)
                response = urllib2.urlopen(req)
                content=response.read()
                #print content,type(content)
                #print content,type(content)
                number1=content.find("result")
                number2=content.find("result",number1+1)
                number2=number2+40
                number3=content.find('"',number2)
                t=content[number2:number3]
                print t
                
                if t=="":        #t[u'hypotheses']==[]:
                    robot_voice.robot_voice("Speak louder, please. I can't hear you clearly")
                else:
                    
                    c=t
                    #values = {'content1' : c.encode("utf-8")}
                    #print values
                    url="http://"+ip_address()+":9080/" #"http://192.168.1.103:9080/"
                    print url
                    data = {}  
      
                    data['content1'] = c.encode("utf-8")   
     
      
                    url_values = urllib.urlencode(data)    
                    print url_values      
                    full_url = url + '?' + url_values  
                    print full_url
                    data = urllib2.urlopen(full_url)  
                    print "content1 sent!"