Skip to content

Instantly share code, notes, and snippets.

@Lord-V15
Last active September 12, 2023 01:56
Show Gist options
  • Save Lord-V15/5220a5ad7f44199b89acdae4c77e2807 to your computer and use it in GitHub Desktop.
Save Lord-V15/5220a5ad7f44199b89acdae4c77e2807 to your computer and use it in GitHub Desktop.
MICROSOFT AZURE SPEAKER RECOGNITION IN PYTHON

For anyone in the future who's gonna try this service from Azure, let me give you an easy way out. I spent a lot of time on Speaker Recognition and the official docs say something and the samples given do something else. I will use the official REST API Docs for the text-independent method.

CREATE PROFILE 👇

import http.client
import json

conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')

headers = {'Ocp-Apim-Subscription-Key': 'YOUR_KEY',
    'Content-type': 'application/json'}

foo = {'locale': 'en-us'}
json_data = json.dumps(foo)

conn.request(method='POST', url='/speaker/verification/v2.0/text-independent/profiles', 
             body=json_data, headers=headers)
response = conn.getresponse().read().decode()
conn.close()

print(response)

ENROLL PROFILE 👇

conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')

headers = {'Ocp-Apim-Subscription-Key': 'YOUR_KEY'}

with open('YOUR_WAV_FILE', 'rb') as data:
    conn.request(method='POST', 
                url=f'/speaker/verification/v2.0/text-independent/profiles/{profileId}/enrollments?ignoreMinLength=true', 
                body=data, headers=headers)
    response = conn.getresponse().read().decode()
    conn.close()
    print(response)

LIST PROFILES 👇

conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')

headers = {'Ocp-Apim-Subscription-Key': 'YOUR_KEY'}

conn.request(method='GET', url='/speaker/verification/v2.0/text-independent/profiles?$top=10', 
             headers=headers)
response = conn.getresponse().read().decode()
conn.close()
print(response)

And you can now make your own calls using this method and following the docs link I mentioned above.

Cheers and Good Luck ! 🍻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment