Speech rest API, 403 forbidden

Category: project oxford


piccolbo on Fri, 12 Jun 2015 19:36:31

Hi, I was wondering if somebody could sport the error in my request

-> POST /recognize?version=3.0&requestid=bdd2f91b-e1b7-477e-8836-606a8ae533ad&appID=D4D52672-91D7-4C74-8AD8-42B1D98141A5&format=JSON&locale=en-US&device.os=SomeOS&scenarios=websearch&instanceid=3b81cd96-8cca-4558-a210-02ac6223cf62&maxnbest=1&result.profanitymarkup=0&client_secret=XXXXXXXXXXXXXXXXXXXXXXX HTTP/1.1
-> User-Agent: curl/7.37.1 Rcurl/ httr/0.6.1
-> Host: speech.platform.bing.com
-> Accept-Encoding: gzip
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Type: audio/wav;codec=audio/wav;samplerate=16000;sourcerate=8000;trustsourcerate=false
-> Content-Length: 538014
-> Expect: 100-continue
<- HTTP/1.1 100 Continue
<- HTTP/1.1 403 Forbidden
<- Content-Length: 0
*  Server Microsoft-IIS/8.5 is not blacklisted
<- Server: Microsoft-IIS/8.5
<- X-MSEdge-Ref: Ref A: 174460258196421FB1F7903B37111B03 Ref B: 494BBE08058A7460655107763E9DAB86 Ref C: Fri Jun 12 12:34:07 2015 PST
<- Date: Fri, 12 Jun 2015 19:34:06 GMT
*  HTTP error before end of send, stop sending
*  Closing connection 1


Jia Gao on Sat, 13 Jun 2015 09:57:30

Hi Piccolbo,

It seems that you use your subscription key/secret to call speech service directly, which is not correct, you should use secret to get token first and then call speech reco service.

The process is like

(1). Use secret/key to call speech token API in proeject oxford to retrieve the oxford speech token, for instance in python,

clientId = "your client id"
clientSecret = "your subscription key"
ttsHost = "https://speech.platform.bing.com"

params = urllib.parse.urlencode({'grant_type': 'client_credentials', 'client_id': clientId, 'client_secret': clientSecret, 'scope': ttsHost})

print ("The body data: %s" %(params))

headers = {"Content-type": "application/x-www-form-urlencoded"}
AccessTokenHost = "oxford-speech.cloudapp.net"
path = "/token/issueToken"

# Connect to server to get the Oxford Access Token
conn = http.client.HTTPSConnection(AccessTokenHost)
conn.request("POST", path, params, headers)
response = conn.getresponse()
print(response.status, response.reason)

data = response.read()
accesstoken = data.decode("UTF-8")
print ("Oxford Access Token: " + accesstoken)

(2). Call speech service with the oxford speech token, you need to add header something like this

Authorization: Bearer <your token string from step (1)>

Here is some examples written in different languages on how to call speech token api and then how to call speech service (REST) api, please have a look, hope this would help you.

C#: https://social.msdn.microsoft.com/Forums/azure/en-US/577e2400-2010-45a9-98ec-fc1f7b3a6173/mvp-how-to-use-project-oxford-voice-recognition-api-rest-with-c?forum=mlapi

Python: https://social.msdn.microsoft.com/Forums/azure/en-US/138ad8a0-6e61-4929-84b4-0336290652d6/mvp-how-to-use-project-oxford-voice-recognition-api-rest-with-python?forum=mlapi


Java: https://social.msdn.microsoft.com/Forums/azure/en-US/b4ddb85c-4589-4935-866d-69734ac1826d/mvp-how-to-use-project-oxford-voice-recognition-api-rest-with-java?forum=mlapi

Node.js: https://social.msdn.microsoft.com/Forums/azure/en-US/5ac07310-ad3a-4fd9-a86f-38cf49e70a91/mvp-how-to-use-project-oxford-voice-recognition-api-rest-with-nodejs?forum=mlapi



piccolbo on Wed, 01 Jul 2015 23:20:24

Eureka! Thanks for your help. I was wondering if we should then outright ignore this reference API page:


It doesn't mention the token mechanism and seems off on a number of details (content type, format)

Examples are great, but don't answer the question: what is the complete list of all parameters? What are the allowed values? For instance, maxnbest is in the reference but not in the examples: can or should I use it? Thanks

Abdulrahman Sahmoud on Mon, 21 Dec 2015 19:08:31

so how often would I need to do that, when does the token expire?

alex_95 on Tue, 05 Apr 2016 15:19:24

Yeah, the documentation to get the token is really bad. Thanks for posting the question.

cthrash99 on Tue, 05 Apr 2016 15:25:50

The token lasts 10 minutes.  If you want to be rigorous about it, you can use the expires_in field in the response.  The units are seconds.

o365spo on Sun, 10 Apr 2016 20:11:21

I have my Azure Cognitive Service up and Keys.

Anybody got a working Javascript/jQuery REST example working with Azure Congitive Oxford.ai Speech API? 

Is it possible without server side code?