samples/cpp/windows/console/samples/standalone_language_detection_samples.cpp
void StandaloneLanguageDetectionWithMicrophone()
{
    // <StandaloneLanguageDetectionWithMicrophone>
    // Creates an instance of a speech config with specified subscription key and service region.
    // Replace with your own subscription key and service region (e.g., "westus").
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");

    // Language Id feature requirement
    // Please refer to language id document for different modes
    config->SetProperty(PropertyId::SpeechServiceConnection_SingleLanguageIdPriority, "Latency");
    auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "de-DE" });

    // Creates a speech recognizer using microphone as audio input. The default language is "en-us".
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig);
    cout << "Say something...\n";

    // Starts Standalone language detection, and returns after a single utterance is recognized. The end of a
    // single utterance is determined by listening for silence at the end or until a maximum of 15
    // seconds of audio is processed.  The task returns the recognition text as result.
    // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
    // shot recognition like command or query.
    // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
    auto result = recognizer->RecognizeOnceAsync().get();

    // Checks result.
    if (result->Reason == ResultReason::RecognizedSpeech)
    {
        auto lidResult = AutoDetectSourceLanguageResult::FromResult(result);
        cout << "RECOGNIZED in "<< lidResult->Language << std::endl;
    }
    else if (result->Reason == ResultReason::NoMatch)
    {
        cout << "NOMATCH: Speech could not be recognized." << std::endl;
    }
    else if (result->Reason == ResultReason::Canceled)
    {
        auto cancellation = CancellationDetails::FromResult(result);
        cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;

        if (cancellation->Reason == CancellationReason::Error)
        {
            cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
            cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
            cout << "CANCELED: Did you update the subscription info?" << std::endl;
        }
    }
    // </StandaloneLanguageDetectionWithMicrophone>
}
// Standalone language detection using microphone.
Standalone language detection using microphone.
Standalone language detection using microphone .
void StandaloneLanguageDetectionWithMicrophone()
{
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
    config->SetProperty(PropertyId::SpeechServiceConnection_SingleLanguageIdPriority, "Latency");
    auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "de-DE" });
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig);
    cout << "Say something...\n";
    auto result = recognizer->RecognizeOnceAsync().get();
    if (result->Reason == ResultReason::RecognizedSpeech)
    {
        auto lidResult = AutoDetectSourceLanguageResult::FromResult(result);
        cout << "RECOGNIZED in "<< lidResult->Language << std::endl;
    }
    else if (result->Reason == ResultReason::NoMatch)
    {
        cout << "NOMATCH: Speech could not be recognized." << std::endl;
    }
    else if (result->Reason == ResultReason::Canceled)
    {
        auto cancellation = CancellationDetails::FromResult(result);
        cout << "CANCELED: Reason=" << (int)cancellation->Reason << std::endl;
        if (cancellation->Reason == CancellationReason::Error)
        {
            cout << "CANCELED: ErrorCode=" << (int)cancellation->ErrorCode << std::endl;
            cout << "CANCELED: ErrorDetails=" << cancellation->ErrorDetails << std::endl;
            cout << "CANCELED: Did you update the subscription info?" << std::endl;
        }
    }
}
void StandaloneLanguageDetectionWithMicrophone ( ) { auto config = SpeechConfig :: FromSubscription ( " " , " " ) ; config -> SetProperty ( PropertyId :: SpeechServiceConnection_SingleLanguageIdPriority , " " ) ; auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig :: FromLanguages ( { " " , " " } ) ; auto recognizer = SourceLanguageRecognizer :: FromConfig ( config , autoDetectSourceLanguageConfig ) ; cout << " \n " ; auto result = recognizer -> RecognizeOnceAsync ( ) . get ( ) ; if ( result -> Reason == ResultReason :: RecognizedSpeech ) { auto lidResult = AutoDetectSourceLanguageResult :: FromResult ( result ) ; cout << " " << lidResult -> Language << std :: endl ; } else if ( result -> Reason == ResultReason :: NoMatch ) { cout << " " << std :: endl ; } else if ( result -> Reason == ResultReason :: Canceled ) { auto cancellation = CancellationDetails :: FromResult ( result ) ; cout << " " << ( int ) cancellation -> Reason << std :: endl ; if ( cancellation -> Reason == CancellationReason :: Error ) { cout << " " << ( int ) cancellation -> ErrorCode << std :: endl ; cout << " " << cancellation -> ErrorDetails << std :: endl ; cout << " " << std :: endl ; } } }
Standalone language detection using microphone.
Standalone language detection using microphone .
// <StandaloneLanguageDetectionWithMicrophone> // Creates an instance of a speech config with specified subscription key and service region. // Replace with your own subscription key and service region (e.g., "westus"). // Language Id feature requirement // Please refer to language id document for different modes // Creates a speech recognizer using microphone as audio input. The default language is "en-us". // Starts Standalone language detection, and returns after a single utterance is recognized. The end of a // single utterance is determined by listening for silence at the end or until a maximum of 15 // seconds of audio is processed.  The task returns the recognition text as result. // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single // shot recognition like command or query. // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead. // Checks result. // </StandaloneLanguageDetectionWithMicrophone>