python - Azure认知服务: how to pass multiple identificationProfileIds in Speaker Recognition API

标签 python azure python-requests azure-cognitive-services

我在使用 Azure 认知服务时遇到一些问题。我正在使用 REST/API 和 python 请求库。我必须设置identificationProfileIds,但我不知道如何在此帖子请求中插入2个或更多id_person。

trump = "4aeXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
obama = "6c6XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 

requests.post("https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/{identificationProfileIds}/enroll?shortAudio=False".format(identificationProfileIds = [obama + trump] ),
headers={"Ocp-Apim-Subscription-Key": "XXXXXXX", "Content-Type": "multipart/form-data"},
 data = open('XXXXXXX_16000_mono_16bit.wav', 'rb').read())

最佳答案

您需要按如下方式以串联格式发送,

url = 'https://westus.api.cognitive.microsoft.com/spid/v1.0/identify'

identificationProfileIds = ''
for value in profile_ids.values():
    identificationProfileIds += value + ','
identificationProfileIds = identificationProfileIds[:-1]
print(identificationProfileIds)

params = {
    'identificationProfileIds': identificationProfileIds,
    'shortAudio': True,
}

json_data = {
    "locale": "en-us",
}

headers = {
    "Ocp-Apim-Subscription-Key": key,
    'Content-Type': 'application/json',
}

try:
    response = requests.post(url, data=data, json=json_data, headers=headers, params=params)
    print('response:', response.status_code)
    if response.status_code == 202:
        print(response.headers['Operation-Location'])
        return response.headers['Operation-Location']
    else:
        print('Error:{}, {}, {}'.format(response.status_code, response.text, response.content))
        return False
except Exception as e:
    print('[Errno {0}] {1}'.format(e.errno, e.strerror))
    return False

关于python - Azure认知服务: how to pass multiple identificationProfileIds in Speaker Recognition API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58150934/

相关文章:

python - 完全同时生成Python线程?

python - 如何在 Python 套接字应用程序中接受 GET 请求?

python - sys.exit 在尝试 : 后无法按预期工作

azure - 未找到功能。尝试将作业类和方法公开

c# - ConfigurationBuilder 无法在 azure 函数中工作

python - 使用 Python 计算内容长度

python - python有没有比较和交换操作

azure - 是否可以通过用户租户上的 ARM 模板在 Azure 上自动注册应用程序?

python - 使用 Python 请求 POST 到 cgi 脚本

Python requests.get 失败并显示 403 forbidden,即使在使用 header 和 Session 对象之后