激动发音评估无法应对语音上下文错误

问题描述 投票:0回答:1
Seedoc
)来实现发音评估系统。 我在控制台中获得以下错误:

“无法进行语音上下文。Websocket错误代码:1007”

我的实施是:

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我检查了录制(fileurl),这是一个工作的WAV文件。

记录配置:

startRecording(event) { event.preventDefault(); if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) { navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => { this.recorder = new RecordRTC(stream, { type: 'audio', mimeType: 'audio/wav', recorderType: RecordRTC.StereoAudioRecorder, desiredSampRate: 16000, numberOfAudioChannels: 1, audioBitsPerSecond: 128000 }); this.startRecorder(event); }).catch((error) => { console.log("The following error occurred: " + error); alert("Please grant permission for microphone access"); }); } else { alert("Your browser does not support audio recording, please use a different browser or update your current browser"); } }

任何想法是什么问题?谢谢
    

尝试此代码块:

var sdk = require("microsoft-cognitiveservices-speech-sdk"); var fs = require("fs") // not supported in node // const audioConfig = sdk.AudioConfig.fromWavFileInput('myVoiceIsMyPassportVerifyMe01.wav'); // workaround var filename = "myVoiceIsMyPassportVerifyMe01.wav"; // 16000 Hz, Mono var pushStream = sdk.AudioInputStream.createPushStream(); fs.createReadStream(filename).on('data', function (arrayBuffer) { pushStream.write(arrayBuffer.slice()); }).on('end', function () { pushStream.close(); }); var audioConfig = sdk.AudioConfig.fromStreamInput(pushStream); const conf = sdk.SpeechConfig.fromSubscription( 'xxxx', 'eastus' ); conf.speechRecognitionLanguage = "en-GB"; var speechRecognizer = new sdk.SpeechRecognizer(conf, audioConfig); var pronunciationAssessmentConfig = new sdk.PronunciationAssessmentConfig( ReferenceText = "My voice is my passport, verify me.", GradingSystem = "HundredMark", Granularity = "Phoneme" ); pronunciationAssessmentConfig.applyTo(speechRecognizer); speechRecognizer.sessionStarted = (s, e) => { console.log('SESSION ID:'+ e.sessionId); }; speechRecognizer.recognizeOnceAsync( function (speechRecognitionResult) { // console.log("speechRecognitionResult:", speechRecognitionResult); if (speechRecognitionResult.reason === sdk.ResultReason.RecognizedSpeech) { // The pronunciation assessment result as a Speech SDK object var pronunciationAssessmentResult = sdk.PronunciationAssessmentResult.fromResult(speechRecognitionResult); console.log("pronunciationAssessmentResult", pronunciationAssessmentResult); // The pronunciation assessment result as a JSON string var pronunciationAssessmentResultJson = speechRecognitionResult.properties.getProperty(sdk.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 sdk.SpeechRecognitionCanceledEventArgs) { console.error("Recognition canceled. Reason:", error.reason); console.error("Error details:", error.errorDetails); } } );
几个捕获:

javascript azure speech-recognition speech-to-text azure-speech
1个回答
0
投票
audioconfig.fromwavfileInput可能不支持节点。我只是使用了链接中提到的解决方法,它起作用了。

https://github.com/azure-smamples/cognitive-services-speech-sdk/issues/813


需要作为单个参数值传递发音AssessmentConfig,而不是json
  1. 我从这里使用了样品WAV。您可以编辑到您的

    https://github.com/azure-samples/cognitive-services-speech-sdk/blob/master/sampledata/sampledata/audiofiles/myvoiceismypassportverifyme01.wav

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.