I am encountering an error while trying to use the Microsoft Cognitive Services Speech SDK for voice profile enrollment and verification in a Node.js application. The error message indicates an "Unexpected server response: 200" when attempting to contact the server.
Here is the code I am using:
import * as sdk from "microsoft-cognitiveservices-speech-sdk";
import * as fs from "fs";
// Replace with your own subscription key and service region
const subscriptionKey = "adsasdasdasdasdasd";
const serviceRegion = "eastus"; // e.g., "westus"
const enrollFiles = [
"myVoiceIsMyPassportVerifyMe01.wav",
"myVoiceIsMyPassportVerifyMe02.wav",
"myVoiceIsMyPassportVerifyMe03.wav",
]; // 16000 Hz, Mono
const verificationFile = "myVoiceIsMyPassportVerifyMe04.wav"; // 16000 Hz, Mono
// Create the speech config with the credentials for the subscription
const speechConfig = sdk.SpeechConfig.fromSubscription(subscriptionKey, serviceRegion);
const client = new sdk.VoiceProfileClient(speechConfig);
const locale = "en-us";
const getAudioConfigFromFile = function (file) {
return sdk.AudioConfig.fromWavFileInput(fs.readFileSync(file));
};
sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug);
sdk.Diagnostics.SetLogOutputPath("logfile.log");
async function main() {
try {
// Create a verification specific profile
const profile = await client.createProfileAsync(sdk.VoiceProfileType.TextDependentVerification, locale);
console.log("Profile id:", profile.profileId);
// Enroll the profile using the provided audio files
for (const enrollFile of enrollFiles) {
const enrollConfig = getAudioConfigFromFile(enrollFile);
const enrollResult = await client.enrollProfileAsync(profile, enrollConfig);
console.log("Enrollment result:", sdk.ResultReason[enrollResult.reason]);
if (enrollResult.reason !== sdk.ResultReason.EnrolledVoiceProfile) {
throw new Error("Enrollment failed for file: " + enrollFile);
}
}
// Perform verification
const verificationConfig = getAudioConfigFromFile(verificationFile);
const recognizer = new sdk.SpeakerRecognizer(speechConfig, verificationConfig);
const model = sdk.SpeakerVerificationModel.fromProfile(profile);
const verificationResult = await recognizer.recognizeOnceAsync(model);
console.log("Verification result:", sdk.ResultReason[verificationResult.reason]);
if (verificationResult.reason === sdk.ResultReason.Canceled) {
const cancellationDetails = sdk.SpeakerRecognitionCancellationDetails.fromResult(verificationResult);
console.log("Verification canceled. Error Details:", cancellationDetails.errorDetails);
console.log("Verification canceled. Error Code:", cancellationDetails.errorCode);
} else {
console.log("Profile Id:", verificationResult.profileId);
console.log("Score:", verificationResult.score);
}
// Delete the voice profile
const deleteResult = await client.deleteProfileAsync(profile);
console.log("Delete profile result:", sdk.ResultReason[deleteResult.reason]);
} catch (err) {
console.error("ERROR:", err);
}
}
main();
After enabling SDK logging, I received the following logs:
2024-07-10T11:57:34.167Z | ConnectionErrorEvent | privName: ConnectionErrorEvent | privEventId: 5F94ADC0A175403899E3C155C54EDAF3 | privEventTime: 2024-07-10T11:57:34.167Z | privEventType: 0 | privMetadata: {} | privConnectionId: 00BA767F1CF64F45A805A356AAC4DEB8 | privMessage: Unexpected server response: 200 | privType: error
2024-07-10T11:57:34.171Z | ConnectionStartEvent | privName: ConnectionStartEvent | privEventId: AD7F957367EC4FFEAD5E12EB8BC48FCB | privEventTime: 2024-07-10T11:57:34.171Z | privEventType: 1 | privMetadata: {} | privConnectionId: 00BA767F1CF64F45A805A356AAC4DEB8 | privUri: wss://eastus.spr-frontend.speech.microsoft.com/speaker/ws/verification/text-dependent/profile?format=simple&language=en-US&Ocp-Apim-Subscription-Key=69129cae5c18486faa1151dc82690417&X-ConnectionId=00BA767F1CF64F45A805A356AAC4DEB8&Apim-Subscription-Id=69129cae5c18486faa1151dc82690417 | privHeaders: <NULL>
2024-07-10T11:57:35.137Z | ConnectionErrorEvent | privName: ConnectionErrorEvent | privEventId: A965681C0FBD49D5880B7CD30EBE259C | privEventTime: 2024-07-10T11:57:35.137Z | privEventType: 0 | privMetadata: {} | privConnectionId: 00BA767F1CF64F45A805A356AAC4DEB8 | privMessage: Unexpected server response: 200 | privType: error
2024-07-10T11:57:35.141Z | ConnectionStartEvent | privName: ConnectionStartEvent | privEventId: 75BCDBCCF0144568A25050672ACC00F9 | privEventTime: 2024-07-10T11:57:35.141Z | privEventType: 1 | privMetadata: {} | privConnectionId: 00BA767F1CF64F45A805A356AAC4DEB8 | privUri: wss://eastus.spr-frontend.speech.microsoft.com/speaker/ws/verification/text-dependent/profile?format=simple&language=en-US&Ocp-Apim-Subscription-Key=69129cae5c18486faa1151dc82690417&X-ConnectionId=00BA767F1CF64F45A805A356AAC4DEB8&Apim-Subscription-Id=69129cae5c18486faa1151dc82690417 | privHeaders: <NULL>
2024-07-10T11:57:36.161Z | ConnectionErrorEvent | privName: ConnectionErrorEvent | privEventId: 5C9D94A9D421493CA13E44A64293B779 | privEventTime: 2024-07-10T11:57:36.161Z | privEventType: 0 | privMetadata: {} | privConnectionId: 00BA767F1CF64F45A805A356AAC4DEB8 | privMessage: Unexpected server response: 200 | privType: error
ERROR: Unable to contact server. StatusCode: 1006, undefined Reason: Unexpected server response: 200
I have verified that my subscription key and service region are correct and that my audio files are in the correct format (16 kHz, mono). I am also running the latest version of the Speech SDK. Any help resolving this issue would be greatly appreciated.