I am trying to implement a pronunciation assessment system using Azure’s JS SDK (see doc).
I get the following error in console:
“Could not deserialize speech context. websocket error code: 1007”
Here is my implementation:
assessPronunciation(fileUrl) {
const speechConfig = window.SpeechSDK.SpeechConfig.fromSubscription("xxx", "westeurope");
speechConfig.speechRecognitionLanguage = "en-GB";
// Fetch the WAV file and create an AudioConfig
fetch(fileUrl)
.then(response => response.blob())
.then(blob => {
// Convert the blob to a File object
const file = new File([blob], "audio.wav", { type: "audio/wav" });
// Create an AudioConfig using the File object
const audioConfig = window.SpeechSDK.AudioConfig.fromWavFileInput(file);
var pronunciationAssessmentConfig = new window.SpeechSDK.PronunciationAssessmentConfig({
referenceText: "Hello this is a test",
gradingSystem: "HundredMark",
granularity: "Phoneme"
});
var speechRecognizer = new window.SpeechSDK.SpeechRecognizer(speechConfig, audioConfig);
pronunciationAssessmentConfig.applyTo(speechRecognizer);
speechRecognizer.sessionStarted = (s, e) => {
console.log(`SESSION ID: ${e.sessionId}`);
};
pronunciationAssessmentConfig.applyTo(speechRecognizer);
speechRecognizer.recognizeOnceAsync(
function(speechRecognitionResult) {
if (speechRecognitionResult.reason === window.SpeechSDK.ResultReason.RecognizedSpeech) {
// The pronunciation assessment result as a Speech SDK object
var pronunciationAssessmentResult = SpeechSDK.PronunciationAssessmentResult.fromResult(speechRecognitionResult);
console.log("pronunciationAssessmentResult", pronunciationAssessmentResult);
// The pronunciation assessment result as a JSON string
var pronunciationAssessmentResultJson = speechRecognitionResult.properties.getProperty(SpeechSDK.PropertyId.SpeechServiceResponse_JsonResult);
console.log("pronunciationAssessmentResultJson", pronunciationAssessmentResultJson);
} else {
console.error("Speech not recognized. Reason:", speechRecognitionResult);
}
},
function(error) {
console.error("Error during recognition:", error);
if (error instanceof window.SpeechSDK.SpeechRecognitionCanceledEventArgs) {
console.error("Recognition canceled. Reason:", error.reason);
console.error("Error details:", error.errorDetails);
}
}
);
})
.catch(error => {
console.error("Error fetching WAV file:", error);
});
}
I checked the recording (fileUrl) and it’s a working Wav file as expected.
Any idea what’s the issue? Thanks.