Служба познания Azure: как передать несколько ID-идентификаторов профилей в API распознавания динамиков - PullRequest
0 голосов
/ 29 сентября 2019

У меня проблемы с когнитивным сервисом Azure.Я использую REST / API и библиотеку запросов Python.Я должен установить identityProfileIds, но я не знаю, как вставить 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())

1 Ответ

2 голосов
/ 29 сентября 2019

Вам необходимо отправить в сцепленном формате следующим образом,

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
...