【问题标题】:Azure cognitive service: how to pass multiple identificationProfileIds in Speaker Recognition APIAzure 认知服务:如何在说话人识别 API 中传递多个 IdentificationProfileId
【发布时间】:2019-09-29 13:02:32
【问题描述】:

我在使用 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())

【问题讨论】:

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


    【解决方案1】:

    您需要以如下的连接格式发送,

    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
    
    猜你喜欢
    • 2020-06-16
    • 2017-06-08
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    相关资源
    最近更新 更多