Mrinal Ahlawat
Mrinal Ahlawat

Reputation: 115

Project Oxford Speaker Recognition- Invalid Audio Format

I have been trying a lot to use the Project Oxford Speaker Recognition API (https://dev.projectoxford.ai/docs/services/563309b6778daf02acc0a508/operations/5645c3271984551c84ec6797).

I have been successfully able to record the sound on my microphone convert it to the required WAV(PCM,16bit,16K,Mono).

The problem is when I try to post this file as a binary stream to the API it returns an Invalid audio format error message.

The same file is accepted by the demo on the website(https://www.projectoxford.ai/demo/SPID).

I am using python 2.7 with this code.

import httplib
import urllib
import base64
import json
import codecs

headers = {
    # Request headers
    'Content-Type': 'application/octet-stream',
    'Ocp-Apim-Subscription-Key': '{KEY}',
}

params = urllib.urlencode({
})


def enroll(audioId):
    conn = httplib.HTTPSConnection('api.projectoxford.ai')
    file = open('test.wav','rb')
    body = file.read()
    conn.request("POST", "/spid/v1.0/verificationProfiles/" + audioId +"/enroll?%s" % params, str(body), headers)
    response = conn.getresponse()
    data = response.read()
    print data
    conn.close()
    return data

And this is the response that i am getting.

{
    "error": {
        "code": "BadRequest",
        "message": "Invalid Audio Format"
    }
}

Please if anyone can guide me as to what I am missing. I have verified all the properties of the audio file and the requirements needed by the API but with no luck.

All answers and comments are appreciated.

Upvotes: 0

Views: 828

Answers (1)

kberryman
kberryman

Reputation: 101

I sent this file to Project oxford with my test program that is in ruby and it works properly. I think the issue might be in the other params you are sending. Try changing your 'Content Type' header to 'audio/wav; samplerate=1600' this is the header that I used. I also send a 'Content Length' header with the size of the file. I'm not sure if 'Content Length' is required but it is good standard to include it.

Upvotes: 2

Related Questions