Esempio n. 1
0
    def recognize_by_file(self,
                          file_path,
                          start_seconds,
                          rec_length=10,
                          user_params={}):
        res = ''
        try:
            query_data = {}
            if self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_AUDIO or self.recognize_type == ACRCloudRecognizeType.ACR_OPT_REC_BOTH:
                audio_fingerprint_opt = {
                    'filter_energy_min': self.filter_energy_min,
                    'silence_energy_threshold': self.silence_energy_threshold,
                    'silence_rate_threshold': self.silence_rate_threshold
                }
                query_data[
                    'sample'] = acrcloud_extr_tool.create_fingerprint_by_file(
                        file_path, start_seconds, rec_length, False,
                        audio_fingerprint_opt)
            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_by_file(
                        file_path, start_seconds, rec_length)

            res = self.do_recogize(self.host, query_data, self.query_type,
                                   self.access_key, self.access_secret,
                                   self.timeout, user_params)
            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
Esempio n. 2
0
    def recognize_by_file(self, file_path, start_seconds, rec_length=10):
        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_by_file(
                        file_path, start_seconds, rec_length, 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_by_file(
                        file_path, start_seconds, rec_length)

            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
 def recognize_by_file(self, file_path, start_seconds):
     try:
         res = ""
         fp = acrcloud_extr_tool.create_fingerprint_by_file(file_path, start_seconds, 12, 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
Esempio n. 4
0
 def recognize_by_file(self, file_path, start_seconds):
     try:
         res = ''
         fp = acrcloud_extr_tool.create_fingerprint_by_file(
             file_path, start_seconds, 12, 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
Esempio n. 5
0
 def recognize_by_file(self, file_path, start_seconds):
     try:
         res = ''
         fp = acrcloud_extr_tool.create_fingerprint_by_file(file_path, start_seconds, 12, 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
Esempio n. 6
0
 def recognize_by_file(self, file_path, start_seconds):
     try:
         res = ''
         fp = acrcloud_extr_tool.create_fingerprint_by_file(file_path, start_seconds, 12, 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