How to resolve the "Unexpected server response: 200" error when using Microsoft Cognitive Services Speech SDK for voice profile enrollment and verification?

Ascend AI 0 Reputation points
2024-07-10T13:03:53.5333333+00:00

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.

Azure AI services
Azure AI services
A group of Azure services, SDKs, and APIs designed to make apps more intelligent, engaging, and discoverable.
2,897 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. VasaviLankipalle-MSFT 17,636 Reputation points
    2024-07-10T21:24:47.5733333+00:00

    Hello @Ascend AI , Thanks for using Microsoft Q&A Platform.

    Microsoft limits access to speaker recognition. You can apply for access through the Azure AI services speaker recognition limited access review. For more information, see Limited access for speaker recognition.

    Have you applied for speaker recognition access?

    0 comments No comments

  2. mikelydick 76 Reputation points
    2024-07-10T22:30:39.3666667+00:00

    The log entry you've provided indicates a ConnectionErrorEvent occurring in the Microsoft Cognitive Services Speech SDK. The key components of this error:

    1. Event Type: ConnectionErrorEvent
    2. Event Time: 2024-07-10T11:57:35.137Z
    3. Connection ID: 00BA767F1CF64F45A805A356AAC4DEB8
    4. Error Message: "Unexpected server response: 200"
    5. Error Type: error

    The most puzzling aspect of this error is that it's reporting an "Unexpected server response: 200". In HTTP status codes, 200 typically indicates a successful response. However, the SDK is treating this as an error. This unusual behavior could be due to several reasons:

    1. SDK Version Mismatch: The SDK version you're using might be different from the server version. Ensure you're using the latest version of the Speech SDK.
    2. Incorrect Response Format: The server might be returning a 200 status code, but the response body may not be in the format the SDK expects.
    3. Authentication Issues: Although the server is responding with a 200 status, there might be authentication-related information in the response that the SDK is interpreting as an error.
    4. SDK Bug: It's possible this is a bug in the Speech SDK itself, where it's incorrectly handling a valid 200 response.

    To resolve this issue, try the following steps:

    1. Update the Speech SDK: Ensure you're using the latest version of the Microsoft Cognitive Services Speech SDK.
    2. Check Authentication: Verify that your subscription key and region are correct and that you have the necessary permissions for speaker recognition.
    3. Enable Detailed Logging: If you haven't already, enable detailed logging in the SDK to get more information about the error:
         sdk.Diagnostics.SetLoggingLevel(sdk.LogLevel.Debug);
      

    sdk.Diagnostics.SetLogOutputPath("logfile.log");

    1. Check Network: Ensure there are no network issues or proxies interfering with the connection.
    2. Verify Service Status: Check if there are any known issues or outages with the Azure Cognitive Services in your region.
    3. Contact Support: If the issue persists, consider reaching out to Microsoft support or posting on their GitHub repository for the Speech SDK.

    Remember, speaker recognition features often require special access. Make sure you've applied for and been granted access to the speaker recognition features through the Azure AI services speaker recognition limited access review process

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.