说话人识别API出错:"无法找到资源或路径。"

时间:2016-10-12 22:03:29

标签: python python-2.7 microsoft-cognitive

我尝试使用Jupyter Python运行说话人识别API的注册个人资料代码。

不幸的是,我收到了一个错误:

{ "error": { "code": "NotFound", "message": "Resource or path can't be found." } }

以下是代码:

#Loading .wav file   
     w = wave.open("Harshil_recording_final.wav", "rb")
     binary_data = w.readframes(w.getnframes())
#User Enrollment
    headers = {
        # Request headers
        'Content-Type': 'application/octet-stream',
        'Ocp-Apim-Subscription-Key': '*subscription-key*',
    }

    params = urllib.urlencode({
        # Request parameters
        'identificationProfileId':user1,
        'shortAudio': 'true',
    })

    body = w

    try:
        conn = httplib.HTTPSConnection('api.projectoxford.ai')
        conn.request("POST",  "/spid/v1.0/identificationProfiles/{identificationProfileId}/enroll?%s" % params, str(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))

1 个答案:

答案 0 :(得分:1)

identificationProfileId是URL路径的一部分,而不是查询参数。您应该执行以下操作:

params = urllib.urlencode({
        # Request parameters
        'shortAudio': 'true',
    })
...
conn.request("POST", "/spid/v1.0/identificationProfiles/{0}/enroll?{1}".format(user1, params), body, headers)