VisionImpaired Demo - TextToSpeach not working


I am trying to run the demo in your blog post - the Vision component is working. But the TextToSpeach is not. Same for your UMSBingSpeechDemo.

Looking at the logs (on Windows)
20161117T230751:HTTPS POST:
20161117T230752:HTTPS POST RES:401
20161117T230752:HTTPS POST RESULT:{ "statusCode": 401, "message": "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription." }

I am using Delphi Berlin 10.1 Update 2 and Android 6.0.1 for UMSBingSpeechDemo.


Did you obtain an API key for Bing Speech and if so, respected the limits of the free key


Yes, I have the API key. The Vision API is working and I can detect images and do the OCR to text etc... however it is just the Speech portion which is not working.

I also tried setting

 tmscloudbingspeech.key = key1
 tmscloudbingspeech.secret = key2

and other various combinations - all not working and getting the same 401 error.

I am sure I am under the quota as I just registered yesterday to test.

It's unclear why the Microsoft service refuses connection.

Did you try the MSBingSpeechDemo that is included in the TMS FMX Cloud Pack to see if this works?

Yes. I tested with the Demo that came with the TMS FMX CloudPack.

I see on the Bing forum some folks saying needing to send in your email and changing the headers ( Ocp-Apim-Subscription-Key) to add in a specific format. I am not sure in which property I should set them in the component.


Specifically :

curl -v -X POST ""; -H "Content-Type: application/x-www-form-urlencoded" -H "Ocp-Apim-Subscription-Key: <Your primary subscription key> --data-ascii "grant_type=client_credentials&client_id=<your client ID generated from Azure>&client_secret=<your primary subscription key>&";


We are not aware of any issues with authentication to the MS Bing Speech API.
Can you please make sure you are using a valid API Key?

Only the App.Key property needs to be assigned with the one of the "Bing Speech" API Keys displayed on Microsoft's web console.
As indicated here:
Please note that an API Key for "Computer Vision" is not valid for use with "Bing Speech" and vice versa.

Yes, I have used the correct API key.

Looking into your source code: the BING API URI has changed - if I make the following changes:

//  url := '';
  url := '';
  AddHeader(headers, 'Content-Type', 'application/x-www-form-urlencoded');
  AddHeader(headers, 'Content-Length', '0');
  AddHeader(headers, 'Ocp-Apim-Subscription-Key', UrlEncode(App.Key));
  FData := '';

  lf := '&';
//  FData :=
//    'client_id=' + UrlEncode(App.Key) + lf
//  + 'client_secret=' + UrlEncode(App.Key) + lf
//  + 'grant_type=client_credentials' + lf
//  + 'scope=' + ScopeParamText(',', true);

HttpsPost(ExtractServer(url), RemoveServer(url), headers, AnsiString(FData), resdat);
resdat := CleanUpJSON(resdat);
jv := TJSONObject.ParseJSONValue(string(resdat));

I can get an equivalent output if i use the bash console with CURL.. 

} [5 bytes data]
> POST /sts/v1.0/issueToken HTTP/1.1
> Host:
> User-Agent: curl/7.50.1
> Accept: */*
> Content-type: application/json
> Content-Length: 0
> Ocp-Apim-Subscription-Key: [my api key]
{ [5 bytes data]
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Length: 495
< Content-Type: application/jwt; charset=us-ascii
< Expires: -1
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< apim-request-id: 2e45fdd1-0bc5-44ff-a469-1189fbd954c5
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< Date: Mon, 21 Nov 2016 16:21:11 GMT
{ [495 bytes data]
100   495  100   495    0     0   1092      0 --:--:-- --:--:-- --:--:--  1581eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzY29wZSI6Imh0dHBzOi8vc3BlZWNoLnBsYXRmb3JtLmJpbmcuY29tIiwic3Vic2NyaXB0aW9uLWlkIjoiODE4OGM2Y2VlMTZjNDM2MGJlOTA5MGJlY2ExYzMxYzciLCJwcm9kdWN0LWlkIjoiQmluZy5TcGVlY2guUHJldmlldyIsImNvZ25pdGl2ZS1zZXJ2aWNlcy1lbmRwb2ludCI6Imh0dHBzOi8vYXBpLmNvZ25pdGl2ZS5taWNyb3NvZnQuY29tL2ludGVybmFsL3YxLjAvIiwiYXp1cmUtcmVzb3VyY2UtaWQiOiIiLCJpc3MiOiJ1cm46bXMuY29nbml0aXZlc2VydmljZXMiLCJhdWQiOiJ1cm46bXMuc3BlZWNoIiwiZXhwIjoxNDc5NzQ1ODcyfQ.pPtYmOqwjSi7m_aExtGJfyGhcQOm0_dRGr-QxtfszFw
* Connection #0 to host left intact

As you can see the output above is a token ( i think), but your code is expecting a JSON value, and hence the TJSONObject.ParseJSONValue fails.. and just returns 'e' in my case.

Hope this helps.

Your remarks are correct.
The authentication URL for the API has changed and the previous URL is not compatible with newly created API keys.

This issue has been fixed and the update will be available with the next release of the TMS FMX Cloud Pack.

Thanks.. if possible can I have the patch via email before the release of the update as I am working on a project at the moment.


You can request an incremental source update by sending an email to

Hi Bart

I would like to update that with the latest TMS FMX Cloud component update on 1st Dec - the VisionImpared demo is working perfectly on Android with Delphi 10.1 Update 2.


Good to hear it's OK now!
Thank you for notifying.