【问题标题】:How to implement the Microsoft Speaker Recognition / Verification API in Python?如何在 Python 中实现 Microsoft 说话人识别/验证 API?
【发布时间】:2020-03-17 14:46:54
【问题描述】:

我想为说话人验证项目实施 Microsoft 认知服务中的说话人识别 API。我已经有一个说话人识别 API 密钥。我直接从文档中获得了示例 Python 代码(在文档的底部):

https://westus.dev.cognitive.microsoft.com/docs/services/563309b6778daf02acc0a508/operations/563309b7778daf06340c9652

    ########### Python 3.2 #############
    import http.client, urllib.request, urllib.parse, urllib.error, base64

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

    params = urllib.parse.urlencode({
    })

    try:
        conn = http.client.HTTPSConnection('westus.api.cognitive.microsoft.com')
        conn.request("POST", "/spid/v1.0/verificationProfiles?%s" % params, "{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))

    ####################################

这是第一步的代码示例,创建并保存语音配置文件。

要进行说话人验证,我们需要执行 3 个步骤: 1) 创建个人资料 2) 创建注册 3) 验证

我现在已经卡在第一步了。这是我第一次使用 API,所以我不太确定我必须更改 Python 代码的哪些部分。我知道我需要在 'Ocp-Apim-Subscription-Key' 中插入我的 API 密钥,但除此之外,还有什么?例如,如果我在该特定字段中添加我的 API 密钥并让代码运行,我会收到此错误消息。

b'{"error":{"code":"BadRequest","message":"locale is not specified"}}'

例如,我需要在哪里插入语言环境(“en-us”)?从文档中我并不清楚我需要编辑什么。如果您能指导我在 API 调用中插入/添加什么内容,我将不胜感激。

提前非常感谢!

【问题讨论】:

    标签: azure speech-recognition microsoft-cognitive voice-recognition azure-cognitive-services


    【解决方案1】:

    当您创建说话人识别配置文件时,它必须与区域设置相关联,并且您在请求正文中指定此区域设置。正文应该是一个 JSON 对象,如下所示:

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

    要使示例正常工作,您需要将“{body}”替换为实际的正文值,如下所示:

    conn.request("POST", "/spid/v1.0/verificationProfiles?%s" % params, "{\"locale\":\"en-US\"}", headers)
    

    【讨论】:

    • 感谢您的快速回复!它奏效了,我还成功实施了注册和验证步骤。重点是将每一步中的"{body}"替换成需要的信息。
    猜你喜欢
    • 1970-01-01
    • 2020-06-13
    • 2020-06-16
    • 2020-06-04
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多