Microsoft发言人识别API:无法找到资源或路径

时间:2017-04-20 07:43:51

标签: java web-services

您好我正在尝试使用Microsoft发言人识别API并使用注册服务。但我在回复中得到了这个错误

  

{"错误":{"代码":" NotFound","消息":"资源或路径无法找到。" }

这是我的班级代码: package com.mscongnitive.speakeridentification;

import java.io.File;
import java.net.URI;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class JavaSample 
{
    public static void main(String[] args) 
    {
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://westus.api.cognitive.microsoft.com/spid/v1.0/identificationProfiles/1/enroll");
            builder.setParameter("shortAudio", "true");
            URI uri = builder.build();
            System.out.println(uri);
            HttpPost request = new HttpPost(uri);
            request.setHeader("Content-Type", "multipart/form-data");
            request.setHeader("Ocp-Apim-Subscription-Key", "b91fbd3dc22842d68e4ee1c81578d6be");
            //System.out.println(request.);


            // Request body
            File file = new File("C:\\Users\\dsghaier\\Desktop\\Records\\dhia1.wav");
            System.out.println(file.length());
            //StringEntity reqEntity = new StringEntity(file.toString());
            request.setEntity( new FileEntity(file, ContentType.APPLICATION_OCTET_STREAM) );

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null) 
            {
                System.out.println(EntityUtils.toString(entity));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}

0 个答案:

没有答案