Skip to content

Help with basic audio fingerprinting #34

@Sammyalhashe

Description

@Sammyalhashe

I am currently following this tutorial to identify a fingerprint generated by the extra tools: https://docs.acrcloud.com/reference/identification-api.

What I am currently testing is the ability to have an mp3 file fingerprinted, then that fingerprint put right back into the identification API and see if it responds correctly. Unfortunately the documentation on error codes is quite limiting and right now all I have is that I receive a 3006 code which refers to invalid arguments. This doesn't give much indication of what's wrong with what I am doing here.

I was hoping for a bit of guidance here with the code I have and my usage of the API. Basically my code looks like this:

# generate the fingerprint from an mp3 file
fingerprint = create_fingerprint_by_file(f"tools/{filename.name}",0, 6, False, 0)

# setup form data for request
request_url = f"http://{os.environ['ACR_CLOUD_HOST']}/v1/identify"
http_method = "POST"
http_uri = "/v1/identify"
data_type = "fingerprint"
access_key = os.environ["ACR_CLOUD_ACCESS_KEY"]
access_secret = os.environ["ACR_CLOUD_ACCESS_SECRET"]
signature_version = "1"
timestamp = time.time()

string_to_sign = (
    http_method
    + "\n"
    + http_uri
    + "\n"
    + access_key
    + "\n"
    + data_type
    + "\n"
    + signature_version
    + "\n"
    + str(timestamp)
)

sign = base64.b64encode(
    hmac.new(
        access_secret.encode("ascii"),
        string_to_sign.encode("ascii"),
        digestmod=hashlib.sha1,
    ).digest()
).decode("ascii")

# actually send request.
data = {
    "access_key": access_key,
    "sample_bytes": fingerprint,
    "timestamp": str(timestamp),
    "signature": sign,
    "data_type": data_type,
    "signature_version": signature_version,
}
response = requests.post(request_url, data=data)
response.encoding = "utf-8"
print(response.text)

# parse the response
return parseAcrFingerprintResponse(response.json())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions