question

DirkDelbaere-9662 avatar image
0 Votes"
DirkDelbaere-9662 asked DirkDelbaere-9662 commented

TTS timeout connection to server: how to keep alive the connection with javascript?

In Azure cognitive services TTS there is a timeout after +- 2 minutes when not using the speech. There is a WebSocket connection problem: "Unable to contact server. StatusCode: 1006, undefined Reason: undefined"
Is there a way to keep alive the connection with javascript (browser)?

azure-cognitive-services
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YutongTie-MSFT avatar image
0 Votes"
YutongTie-MSFT answered DirkDelbaere-9662 commented

Hello,

Thanks for reaching out to us. How long you want keep the connection alive? How you are dong the authentication?

For access token, the access token should be sent to the service as the Authorization: Bearer <TOKEN> header. Each access token is valid for 10 minutes. You can get a new token at any time, however, to minimize network traffic and latency, we recommend using the same token for nine minutes.

This is an example for HTTP short-audio scenario:

 POST /cognitiveservices/v1 HTTP/1.1
 Authorization: Bearer YOUR_ACCESS_TOKEN
 Host: westus.stt.speech.microsoft.com
 Content-type: application/ssml+xml
 Content-Length: 199
 Connection: Keep-Alive
    
 // Message body here...


Regards,
Yutong

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for help.
If possible I would use nine minutes.
For access token I use code from the TTS example in Javascript (browser):
var authorizationEndpoint = "token.php";
function RequestAuthorizationToken() {
if (authorizationEndpoint) {
var a = new XMLHttpRequest();
a.open("GET", authorizationEndpoint);
a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
a.send("");
.....
Can I put "Content-Length: 199 / Connection: Keep-Alive" in this script?

0 Votes 0 ·

In token.php I have:
'''curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Ocp-Apim-Subscription-Key: ' . $subscriptionKey));'''
Is this the place to be for "Content-Length: 199 / Connection: Keep-Alive..." ?

0 Votes 0 ·

Hello,

I have found a C#code sample not sure if this helps you a little bit:

Continuous recognition code snippet – https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/get-started-speech-to-text?tabs=windowsinstall&pivots=programming-language-csharp#continuous-recognition.

You may have to tweak one of the samples to process continuous recognition, as pointed out in L41 of C# sample.

I am sorry we do not have any published .js code.


Regards,
Yutong


0 Votes 0 ·

This is for Speech Recognition not Speech Synthesis?
Now I also see that above you gave me the "sample HTTP request to the Speech-to-text REST API for short audio".
I am looking for a solution for TTS Speech Synthesis.
As mentioned, I have a WebSocket connection problem when working with Speech synthesis TTS.
When the webpage with Azure Cognitive Services TTS is not used for a few minutes, the error - timeout occurs.
I made this page based on the javascript example for browser...
So should I put "Content-Length: 199 and Connection: Keep-Alive." in the token.php?

0 Votes 0 ·