I just played with Cognitive-SpeakerRecognition and tried to register a new user. To do this, I followed the examples from the Microsoft API Reference . Sorry, I get an error:
{
"error": {
"code": "BadRequest",
"message": "Invalid Audio Format: Not a WAVE file - no RIFF header"
}
}
I spent a lot of time to solve the problem and find something to do with github and qaru.site/questions/1657164 / ... . Unfortunately, I could not adapt the answer from github (they fixed the problem with a longer sound example, I tried, but still got an error response). So can someone figure out what I'm doing wrong? Thanks for reading :) Here is my code:
public static void main(String[] args) {
HttpClient httpclient = HttpClients.createDefault();
try {
URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/spid/v1.0/identificationProfiles/{PROFIL}/enroll");
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "multipart/form-data");
request.setHeader("Ocp-Apim-Subscription-Key", "API_KEY");
FileInputStream someStream = new FileInputStream(new File("test.wav"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int bytesRead;
byte[] bytes = new byte[1024];
while ((bytesRead = someStream.read(bytes)) > 0) {
byteArrayOutputStream.write(bytes, 0, bytesRead);
}
byte[] data = byteArrayOutputStream.toByteArray();
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.setStrictMode();
entityBuilder.addBinaryBody("enrollmentData", data, ContentType.MULTIPART_FORM_DATA, "test.wav");
request.setEntity(entityBuilder.build());
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());
}
}
EDIT: Here you can download the test.wav file