def recognize(self, wav_audio_buffer):
     try:
         res = ""
         fp = acrcloud_extr_tool.create_fingerprint(wav_audio_buffer, False)
         if not fp:
             return res
         res = self.do_recogize(self.host, fp, self.query_type, self.access_key, self.access_secret, self.timeout)
     except Exception as e:
         print "recognize error " + str(e)
     return res
Exemple #2
0
 def recognize(self, wav_audio_buffer):
     try:
         res = ''
         fp = acrcloud_extr_tool.create_fingerprint(wav_audio_buffer, False)
         if fp == None:
             return ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.AUDIO_ERROR_CODE)
         elif len(fp) <= 0:
             return ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.NO_RESULT_CODE)
         res = self.do_recogize(self.host, fp, self.query_type, self.access_key, self.access_secret, self.timeout)
         try:
             json.loads(res)
         except Exception as e:
             res = ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.JSON_ERROR_CODE, str(res))
     except Exception as e:
         res = ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.UNKNOW_ERROR_CODE, str(e))
     return res
Exemple #3
0
    def recognize(self, wav_audio_buffer):
        res = ''
        try:
            query_data = {}
            if self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_AUDIO or self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_BOTH:
                query_data['sample'] = acrcloud_extr_tool.create_fingerprint(wav_audio_buffer, False)

            if self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_HUMMING or self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_BOTH:
                query_data['sample_hum'] = acrcloud_extr_tool.create_humming_fingerprint(wav_audio_buffer)

            res = self.do_recogize(self.host, query_data, self.query_type, self.access_key, self.access_secret, self.timeout)

            try:
                json.loads(res)
            except Exception as e:
                res = ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.JSON_ERROR_CODE, str(res))
        except Exception as e:
            res = ACRCloudStatusCode.get_result_error(ACRCloudStatusCode.UNKNOW_ERROR_CODE, str(e))
        return res
Exemple #4
0
 def recognize(self, wav_audio_buffer):
     try:
         res = ''
         fp = acrcloud_extr_tool.create_fingerprint(wav_audio_buffer, False)
         if fp == None:
             return ACRCloudStatusCode.get_result_error(
                 ACRCloudStatusCode.AUDIO_ERROR_CODE)
         elif len(fp) <= 0:
             return ACRCloudStatusCode.get_result_error(
                 ACRCloudStatusCode.NO_RESULT_CODE)
         res = self.do_recogize(self.host, fp, self.query_type,
                                self.access_key, self.access_secret,
                                self.timeout)
         try:
             json.loads(res)
         except Exception as e:
             res = ACRCloudStatusCode.get_result_error(
                 ACRCloudStatusCode.JSON_ERROR_CODE, str(res))
     except Exception as e:
         res = ACRCloudStatusCode.get_result_error(
             ACRCloudStatusCode.UNKNOW_ERROR_CODE, str(e))
     return res