samples/cpp/windows/console/samples/standalone_language_detection_samples.cpp
void StandaloneLanguageDetectionInSingleshotModeWithFileInput()
{
    // 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");

    // Request detailed output format.
    config->SetOutputFormat(OutputFormat::Detailed);

    // 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" });

    auto audioInput = AudioConfig::FromWavFileInput("whatstheweatherlike.wav");

    // Creates a speech recognizer
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig, audioInput);

    // 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
             << "  Speech Service JSON: " << result->Properties.GetProperty(PropertyId::SpeechServiceResponse_JsonResult)
             << 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;
        }
    }
}
// Standalone language detection in the specified language, using microphone, and requesting detailed output format.
Standalone language detection in the specified language, using microphone, and requesting detailed output format.
Standalone language detection in the specified language using microphone and requesting detailed output format .
void StandaloneLanguageDetectionInSingleshotModeWithFileInput()
{
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
    config->SetOutputFormat(OutputFormat::Detailed);
    config->SetProperty(PropertyId::SpeechServiceConnection_SingleLanguageIdPriority, "Latency");
    auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "de-DE" });
    auto audioInput = AudioConfig::FromWavFileInput("whatstheweatherlike.wav");
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig, audioInput);
    auto result = recognizer->RecognizeOnceAsync().get();
    if (result->Reason == ResultReason::RecognizedSpeech)
    {
        auto lidResult = AutoDetectSourceLanguageResult::FromResult(result);
        cout << "RECOGNIZED in " << lidResult->Language << std::endl
             << "  Speech Service JSON: " << result->Properties.GetProperty(PropertyId::SpeechServiceResponse_JsonResult)
             << 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 StandaloneLanguageDetectionInSingleshotModeWithFileInput ( ) { auto config = SpeechConfig :: FromSubscription ( " " , " " ) ; config -> SetOutputFormat ( OutputFormat :: Detailed ) ; config -> SetProperty ( PropertyId :: SpeechServiceConnection_SingleLanguageIdPriority , " " ) ; auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig :: FromLanguages ( { " " , " " } ) ; auto audioInput = AudioConfig :: FromWavFileInput ( " " ) ; auto recognizer = SourceLanguageRecognizer :: FromConfig ( config , autoDetectSourceLanguageConfig , audioInput ) ; auto result = recognizer -> RecognizeOnceAsync ( ) . get ( ) ; if ( result -> Reason == ResultReason :: RecognizedSpeech ) { auto lidResult = AutoDetectSourceLanguageResult :: FromResult ( result ) ; cout << " " << lidResult -> Language << std :: endl << " " << result -> Properties . GetProperty ( PropertyId :: SpeechServiceResponse_JsonResult ) << 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 in the specified language, using microphone, and requesting detailed output format.
Standalone language detection in the specified language using microphone and requesting detailed output format .
// 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"). // Request detailed output format. // Language Id feature requirement // Please refer to language id document for different modes // Creates a speech recognizer // 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.