Microsoft Speaker Recognition API:为什么“verify”API调用返回“无法找到资源或路径”。

时间:2016-11-14 05:35:37

标签: ruby rest voice-recognition microsoft-cognitive

这是我正在调用的验证函数:

def verify(verificationProfileId, pathToVoicePrint)

        soundFile = File.read(pathToVoicePrint)
        uri = URI("https://api.projectoxford.ai/spid/v1.0/verify?verificationProfileId=#{verificationProfileId}")
        uri.query = URI.encode_www_form({
        })

        request = Net::HTTP::Post.new(uri.request_uri)
        # Request headers
        request['Content-Type'] = 'multipart/form-data'
        # Request headers
        request['Ocp-Apim-Subscription-Key'] = @subscriptionKey
        # Request body
        request.body = soundFile

        response = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
            http.request(request)
        end
        return response
    end

我直接从此页面获得此代码:https://dev.projectoxford.ai/docs/services/563309b6778daf02acc0a508/operations/56406930e597ed20c8d8549c

此API调用的JSON响应是:

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

此错误消息未在文档的任何位置列出。我也在测试其他功能,例如注册,我使用相同的参数(verificationProfileId和pathToVoicePrint),这些功能都有效,所以我知道它们是正确的。

1 个答案:

答案 0 :(得分:1)

dev.projectoxford.ai上的ruby代码段是错误的,因为在URI ctor中设置了查询,但随后在后续行中被清除。所以你要么:

uri = URI("https://api.projectoxford.ai/spid/v1.0/verify?verificationProfileId=#{verificationProfileId}")
# don't overwrite the uri.query

uri = URI("https://api.projectoxford.ai/spid/v1.0/verify")
uri.query = URI.encode_www_form({
    "verificationProfileId": "#{verificationProfileId}"
})