MicrosoftDocs / azure-docs-sdk-node

Azure for JavaScript and Node.js developers documentation on docs.microsoft.com.
https://docs.microsoft.com/en-us/javascript/azure/
Creative Commons Attribution 4.0 International
83 stars 180 forks source link

Cannot access 'vn' before initialization #698

Closed ManishTiwari-cloud closed 3 years ago

ManishTiwari-cloud commented 4 years ago

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.

Below is my code:

starAudioRecording() { const audioConstraints = { audio: true, video: false }; navigator.mediaDevices .getUserMedia(audioConstraints) .then(this.successCallback.bind(this), this.errorCallback.bind(this)); }

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;
        }
    );
}
ramya-rao-a commented 3 years ago

Apologies for the late reply here

This repo is for the various docs under https://docs.microsoft.com/javascript/api

Your problem seems to be with the microsoft-cognitiveservices-speech-sdk package. Issues for this package can be logged at https://github.com/Microsoft/cognitive-services-speech-sdk-js