Beispiel #1
0
    def __init__(self, config):
        self.config = config
        self.host = config.get('host', 'ap-southeast-1.api.acrcloud.com')
        self.query_type = config.get('query_type', 'fingerprint')
        self.access_key = config.get('access_key')
        self.access_secret = config.get('access_secret')
        self.timeout = config.get('timeout', 5)
        self.debug = config.get('debug', False)
        if not self.access_key or not self.access_secret:
            print('recognize init(none access_key or access_secret)')
            sys.exit(1)

        if self.debug:
            acrcloud_extr_tool.set_debug()
    def __init__(self, config):
        self.config = config
        self.host = config.get("host", "ap-southeast-1.api.acrcloud.com")
        self.query_type = config.get("query_type", "fingerprint")
        self.access_key = config.get("access_key")
        self.access_secret = config.get("access_secret")
        self.timeout = config.get("timeout", 5)
        self.debug = config.get("debug", False)
        if not self.access_key or not self.access_secret:
            print "recognize init(none access_key or access_secret)"
            sys.exit(1)

        if self.debug:
            acrcloud_extr_tool.set_debug()
Beispiel #3
0
    def __init__(self, config):
        self.config = config
        self.host = config.get('host', 'ap-southeast-1.api.acrcloud.com')
        self.query_type = config.get('query_type', 'fingerprint')
        self.access_key = config.get('access_key')
        self.access_secret = config.get('access_secret')
        self.timeout = config.get('timeout', 5)
        self.debug = config.get('debug', False)
        if not self.access_key or not self.access_secret:
            print('recognize init(none access_key or access_secret)')
            sys.exit(1)

        if self.debug:
            acrcloud_extr_tool.set_debug()
Beispiel #4
0
    def __init__(self, config):
        self.config = config
        self.host = config.get('host', 'ap-southeast-1.api.acrcloud.com')
        self.query_type = 'fingerprint'
        self.access_key = config.get('access_key')
        self.access_secret = config.get('access_secret')
        self.timeout = config.get('timeout', 5)
        self.recognize_type = config.get('recognize_type', ACRCloudRecognizeType.ACR_OPT_REC_AUDIO)
        if self.recognize_type > 2 or self.recognize_type < 0:
            self.recognize_type = ACRCloudRecognizeType.ACR_OPT_REC_AUDIO
        self.debug = config.get('debug', False)
        if not self.access_key or not self.access_secret:
            print 'recognize init(none access_key or access_secret)'
            sys.exit(1)

        if self.debug:
            acrcloud_extr_tool.set_debug()
Beispiel #5
0
    def __init__(self, config):
        self.config = config
        self.host = config.get('host', 'ap-southeast-1.api.acrcloud.com')
        self.query_type = config.get('query_type', 'fingerprint')
        self.access_key = config.get('access_key')
        self.access_secret = config.get('access_secret')
        self.timeout = config.get('timeout', 5)
        self.recognize_type = config.get(
            'recognize_type', ACRCloudRecognizeType.ACR_OPT_REC_AUDIO)
        if self.recognize_type > 2 or self.recognize_type < 0:
            self.recognize_type = ACRCloudRecognizeType.ACR_OPT_REC_AUDIO
        self.debug = config.get('debug', False)
        if not self.access_key or not self.access_secret:
            print('recognize init(none access_key or access_secret)')
            sys.exit(1)

        self.filter_energy_min = config.get('filter_energy_min', 100)
        self.silence_energy_threshold = config.get('silence_energy_threshold',
                                                   1200)
        self.silence_rate_threshold = config.get('silence_rate_threshold', 0.7)

        if self.debug:
            acrcloud_extr_tool.set_debug()
Beispiel #6
0
    def recognize_by_filebuffer(self, file_buffer, start_seconds):
        try:
            res = ''
            fp = acrcloud_extr_tool.create_fingerprint_by_filebuffer(
                file_buffer, start_seconds, 12, False)
            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


if __name__ == '__main__':
    config = {
        'host': 'ap-southeast-1.api.acrcloud.com',
        'access_key': 'XXXXXXXX',
        'access_secret': 'XXXXXXXX',
        'timeout': 5
    }

    re = ACRCloudRecognizer(config)
    buf = open(sys.argv[1], 'rb').read()
    #buft = buf[1024000:192000+1024001]

    acrcloud_extr_tool.set_debug()
    #print(acrcloud_extr_tool.__doc__)
    #print(re.recognize_by_file(sys.argv[1], 10))
    print(re.recognize_by_filebuffer(buf, 10))
    #print re.recognize(buft)
Beispiel #7
0
    }

    @staticmethod
    def get_result_error(res_code, msg=''):
        if ACRCloudStatusCode.CODE_MSG.get(res_code) == None:
            return None
        res = {'status':{'msg':ACRCloudStatusCode.CODE_MSG[res_code], 'code':res_code}}
        if msg:
            res = {'status':{'msg':ACRCloudStatusCode.CODE_MSG[res_code]+':'+msg, 'code':res_code}}
        return json.dumps(res)


if __name__ == '__main__':
    config = {
        'host':'ap-southeast-1.api.acrcloud.com',
        'access_key':'XXXXXXXX',
        'access_secret':'XXXXXXXX',
        'timeout':5
    }


    re = ACRCloudRecognizer(config)
    buf = open(sys.argv[1], 'rb').read()
    #buft = buf[1024000:192000+1024001]

    acrcloud_extr_tool.set_debug()
    #print(acrcloud_extr_tool.__doc__)
    #print(re.recognize_by_file(sys.argv[1], 10))
    print(re.recognize_by_filebuffer(buf, 10))
    #print re.recognize(buft)