I have integrated Microsoft azure speech to text in my angular 8 application.
It is working on locally but when i deployed my code to test env it's giving me error 'Cannot access 'vn' before initialization' on this line const sdk = require('microsoft-cognitiveservices-speech-sdk');.
My test env is unsecured network.
successCallback(stream) {
const options = {
mimeType: 'audio/wav',
numberOfAudioChannels: 1
};
const StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
this.recorder = new StereoAudioRecorder(stream, options);
this.recorder.record();
}
stopRecording() {
setTimeout(() => {
this.recorder.stop(this.processRecording.bind(this));
}, 1000);
}
processRecording(blob) {
console.log(blob);
this.blob = URL.createObjectURL(blob);
setTimeout(() => {
const fileObject = new File([blob], 'audio.wav');
this.RecognizerStart(fileObject);
}, 1000);
}
errorCallback(error) {
console.log('Can not play audio in your browser');
this.resultText = 'media is not supported in your browser';
}
RecognizerStart(audioFile) {
const sdk = require('microsoft-cognitiveservices-speech-sdk');
console.log(sdk);
const audioConfig = sdk.AudioConfig.fromWavFileInput(audioFile);
console.log('audioConfig' + audioConfig);
const speechConfig = sdk.SpeechConfig.fromSubscription('29d1eb8c7bef4d7dadd0d5ea9d22ac20', 'centralindia');
console.log('speechConfig' + speechConfig);
speechConfig.speechRecognitionLanguage = 'en-US';
let recognizer = new sdk.SpeechRecognizer(speechConfig, audioConfig);
console.log('recognizer' + recognizer);
// Start the recognizer and wait for a result.
recognizer.recognizeOnceAsync(
result => {
console.log(result.text);
this.resultText = result.text;
recognizer.close();
recognizer = undefined;
},
err => {
console.log('err - ' + err);
recognizer.close();
recognizer = undefined;
}
);
}