Search code examples
python-3.xazure-cognitive-servicesvoice-recognition

Microsoft Cognitive Services - Speaker Recognition API - Verification - error-SpeakerInvalid


I am still facing the error in the verification process

{"error":{"code":"BadRequest","message":"SpeakerInvalid"}}'

My audio is correct as it is getting enrolled easily

##code for API CALL speaker verification 

import http.client, urllib.request, urllib.parse, urllib.error, base64
subscription_key = 'XXXXXXXXXXXXXXXXXXXXXXX'

headers = {
# Request headers
"Content-Type": 'multipart/form-data',
"Ocp-Apim-Subscription-Key": subscription_key,
}

params = urllib.parse.urlencode({
    'verificationProfileId':'445b849b-6418-4443-961b-77bd88196223',

})

#body = {
#}
try:
    conn = http.client.HTTPSConnection('speaker-recognition-api.cognitiveservices.azure.com')
    body = open('pp.wav','rb') //pp.wav is my audio file
    conn.request("POST", "/spid/v1.0/verify?verificationProfileId=445b849b-6418-4443-961b-77bd88196223?%s" % params, body, headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))

Solution

  • I could reproduce your problem. You are getting this error cause there is a ? in the end of your url, however behind verify there is already a ?. So if you want to add params to your request url you should use & just like the sample code in this API doc:Speaker Recognition - Verification .

    enter image description here

    Below is my work code.

    try:
        conn = http.client.HTTPSConnection('geospeaker.cognitiveservices.azure.com')
    
    
        body=open("output4.wav","rb")
        conn.request("POST", "/spid/v1.0/verify?verificationProfileId=1ae143b0-c301-4345-9295-3e34ad367092?%s" % params, body, headers)
        response = conn.getresponse()
        data = response.read()
        print(data)
        conn.close()
    except OSError as e:
        print("[Errno {0}] {1}".format(e.errno, e.strerror))
    

    enter image description here