Hello @Andris Kokins , I'm glad that you were able to partially resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that " The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.
Issue: Azure speech to text giving WebSocket error in docker
Solution:
Adding this to token_util.jsx made it work but it still works on chrome but firefox still gives the websocket error, might be related to this bug:- https://github.com/microsoft/cognitive-services-speech-sdk-js/issues/814#issuecomment-2056775876
import { unstable_noStore } from 'next/cache';
unstable_noStore();
const res = await fetch('/api/token', {next: {revalidate: 0}});
Here is the full code of token_util.js for reference:
// token_util.js
// https://github.com/Azure-Samples/AzureSpeechReactSample
import Cookie from 'universal-cookie';
export async function getTokenOrRefresh() {
const cookie = new Cookie();
const speechToken = cookie.get('speech-token');
if (speechToken === undefined) {
try {
const res = await fetch('/api/token', {next: {revalidate: 0}});
if (!res.ok) {
throw new Error(`Failed to fetch speech token: ${res.status} ${res.statusText}`);
}
const data = await res.json();
const token = data.token;
const region = data.region;
cookie.set('speech-token', region + ':' + token, { maxAge: 540, path: '/' });
console.log('Token fetched from back-end: ' + token);
return { authToken: token, region: region };
} catch (err) {
console.log(err);
return { authToken: null, error: err.message };
}
} else {
console.log('Token fetched from cookie: ' + speechToken);
const idx = speechToken.indexOf(':');
return { authToken: speechToken.slice(idx + 1), region: speechToken.slice(0, idx) };
}
}
Thank you again for your time and patience throughout this issue.
Regards,
Vasavi
Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.