예제 #1
0
 def run(self):
     self.mic = microphone.Microphone()
     self.FILE=self.mic.listen()
     self.NewSession.emit()
     if os.path.getsize(self.FILE)>0:
         #讯飞语音识别
         res = msc_wrapper.sendwav(self.FILE)
         if res and u'失败' in res:
             msc_wrapper.regEnd()
             msc_wrapper.regStart()
         else:
             if res:self.regResult.emit(res.decode('utf-8'))
     #Google语音识别
     '''
     url = 'http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=zh-CN&maxresults=10'
     audio=open(self.FILE,'rb').read()
     headers = {'Content-Type' : 'audio/L16; rate=16000'}
     try:
         req = urllib2.Request(url, audio, headers)
         response = urllib2.urlopen(req,timeout=10)
         print response.read().decode('UTF-8')
         exec('rest ='+ str(response.read().decode('UTF-8')))
         if rest:
             if rest['status'] == 0:
                 googlevoice.get(str(rest['hypotheses'][0]['utterance']))
         print "translate end",self.ResultNum,self.FILE
     except Exception,e:
         print e
     '''
     
     #res=requests.post(url,data=audio,timeout=0.3,headers=headers)
     #print res.text
     os.remove(self.FILE)
예제 #2
0
    def run(self):
        self.mic = microphone.Microphone()
        self.FILE = self.mic.listen()
        self.NewSession.emit()
        if os.path.getsize(self.FILE) > 0:
            #讯飞语音识别
            res = msc_wrapper.sendwav(self.FILE)
            if res and u'失败' in res:
                msc_wrapper.regEnd()
                msc_wrapper.regStart()
            else:
                if res: self.regResult.emit(res.decode('utf-8'))
        #Google语音识别
        '''
        url = 'http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=zh-CN&maxresults=10'
        audio=open(self.FILE,'rb').read()
        headers = {'Content-Type' : 'audio/L16; rate=16000'}
        try:
            req = urllib2.Request(url, audio, headers)
            response = urllib2.urlopen(req,timeout=10)
            print response.read().decode('UTF-8')
            exec('rest ='+ str(response.read().decode('UTF-8')))
            if rest:
                if rest['status'] == 0:
                    googlevoice.get(str(rest['hypotheses'][0]['utterance']))
            print "translate end",self.ResultNum,self.FILE
        except Exception,e:
            print e
        '''

        #res=requests.post(url,data=audio,timeout=0.3,headers=headers)
        #print res.text
        os.remove(self.FILE)
예제 #3
0
 def out(self):
     if not "firstboot" in self.sys_dict:self.firstboot = "1"
     #停止讯飞语音识别
     msc_wrapper.regEnd()
     #删除WAV缓存
     for file in os.listdir(paltform_path("wav")):
         try:os.remove(paltform_path("wav/"+file))
         except:pass
     #保存INI数据    
     self.Config_write()
     #关闭
     self.close
     sys.exit()
예제 #4
0
 def out(self):
     if not "firstboot" in self.sys_dict: self.firstboot = "1"
     #停止讯飞语音识别
     msc_wrapper.regEnd()
     #删除WAV缓存
     for file in os.listdir(paltform_path("wav")):
         try:
             os.remove(paltform_path("wav/" + file))
         except:
             pass
     #保存INI数据
     self.Config_write()
     #关闭
     self.close
     sys.exit()