samples/cpp/windows/console/samples/standalone_language_detection_samples.cpp
void StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput()
{
    // <StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput>
    // 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_ContinuousLanguageIdPriority, "Latency");
    auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "zh-CN" });

    // Creates a speech recognizer using microphone as audio input.
    auto audioInput = AudioConfig::FromWavFileInput("en-us_zh-cn.wav");
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig, audioInput);

    // promise for synchronization of recognition end.
    promise<void> recognitionEnd;

    // Subscribes to events.
    recognizer->Recognized.Connect([](const SpeechRecognitionEventArgs& e)
        {
            if (e.Result->Reason == ResultReason::RecognizedSpeech)
            {
                auto lidResult = AutoDetectSourceLanguageResult::FromResult(e.Result);
                cout << "RECOGNIZED in " << lidResult->Language << "\n"
                    << "  Offset=" << e.Result->Offset() << "\n"
                    << "  Duration=" << e.Result->Duration() << std::endl;
            }
            else if (e.Result->Reason == ResultReason::NoMatch)
            {
                cout << "NOMATCH: Speech could not be recognized." << std::endl;
            }
        });

    recognizer->Canceled.Connect([&recognitionEnd](const SpeechRecognitionCanceledEventArgs& e)
        {
            cout << "CANCELED: Reason=" << (int)e.Reason << std::endl;

            if (e.Reason == CancellationReason::Error)
            {
                cout << "CANCELED: ErrorCode=" << (int)e.ErrorCode << "\n"
                    << "CANCELED: ErrorDetails=" << e.ErrorDetails << "\n"
                    << "CANCELED: Did you update the subscription info?" << std::endl;

                recognitionEnd.set_value(); // Notify to stop recognition.
            }
        });

    recognizer->SessionStopped.Connect([&recognitionEnd](const SessionEventArgs& e)
        {
            cout << "Session stopped.";
            recognitionEnd.set_value(); // Notify to stop recognition.
        });

    // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
    recognizer->StartContinuousRecognitionAsync().get();

    // Waits for recognition end.
    recognitionEnd.get_future().get();

    // Stops recognition.
    recognizer->StopContinuousRecognitionAsync().get();
    // </StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput>
}
// Standalone language detection using a customized model.
Standalone language detection using a customized model.
Standalone language detection using a customized model .
void StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput()
{
    auto config = SpeechConfig::FromSubscription("YourSubscriptionKey", "YourServiceRegion");
    config->SetProperty(PropertyId::SpeechServiceConnection_ContinuousLanguageIdPriority, "Latency");
    auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig::FromLanguages({ "en-US", "zh-CN" });
    auto audioInput = AudioConfig::FromWavFileInput("en-us_zh-cn.wav");
    auto recognizer = SourceLanguageRecognizer::FromConfig(config, autoDetectSourceLanguageConfig, audioInput);
    promise<void> recognitionEnd;
    recognizer->Recognized.Connect([](const SpeechRecognitionEventArgs& e)
        {
            if (e.Result->Reason == ResultReason::RecognizedSpeech)
            {
                auto lidResult = AutoDetectSourceLanguageResult::FromResult(e.Result);
                cout << "RECOGNIZED in " << lidResult->Language << "\n"
                    << "  Offset=" << e.Result->Offset() << "\n"
                    << "  Duration=" << e.Result->Duration() << std::endl;
            }
            else if (e.Result->Reason == ResultReason::NoMatch)
            {
                cout << "NOMATCH: Speech could not be recognized." << std::endl;
            }
        });
    recognizer->Canceled.Connect([&recognitionEnd](const SpeechRecognitionCanceledEventArgs& e)
        {
            cout << "CANCELED: Reason=" << (int)e.Reason << std::endl;
            if (e.Reason == CancellationReason::Error)
            {
                cout << "CANCELED: ErrorCode=" << (int)e.ErrorCode << "\n"
                    << "CANCELED: ErrorDetails=" << e.ErrorDetails << "\n"
                    << "CANCELED: Did you update the subscription info?" << std::endl;
                recognitionEnd.set_value(); 
            }
        });
    recognizer->SessionStopped.Connect([&recognitionEnd](const SessionEventArgs& e)
        {
            cout << "Session stopped.";
            recognitionEnd.set_value(); 
        });
    recognizer->StartContinuousRecognitionAsync().get();
    recognitionEnd.get_future().get();
    recognizer->StopContinuousRecognitionAsync().get();
}
void StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput ( ) { auto config = SpeechConfig :: FromSubscription ( " " , " " ) ; config -> SetProperty ( PropertyId :: SpeechServiceConnection_ContinuousLanguageIdPriority , " " ) ; auto autoDetectSourceLanguageConfig = AutoDetectSourceLanguageConfig :: FromLanguages ( { " " , " " } ) ; auto audioInput = AudioConfig :: FromWavFileInput ( " " ) ; auto recognizer = SourceLanguageRecognizer :: FromConfig ( config , autoDetectSourceLanguageConfig , audioInput ) ; promise < void > recognitionEnd ; recognizer -> Recognized . Connect ( [ ] ( const SpeechRecognitionEventArgs & e ) { if ( e . Result -> Reason == ResultReason :: RecognizedSpeech ) { auto lidResult = AutoDetectSourceLanguageResult :: FromResult ( e . Result ) ; cout << " " << lidResult -> Language << " \n " << " " << e . Result -> Offset ( ) << " \n " << " " << e . Result -> Duration ( ) << std :: endl ; } else if ( e . Result -> Reason == ResultReason :: NoMatch ) { cout << " " << std :: endl ; } } ) ; recognizer -> Canceled . Connect ( [ & recognitionEnd ] ( const SpeechRecognitionCanceledEventArgs & e ) { cout << " " << ( int ) e . Reason << std :: endl ; if ( e . Reason == CancellationReason :: Error ) { cout << " " << ( int ) e . ErrorCode << " \n " << " " << e . ErrorDetails << " \n " << " " << std :: endl ; recognitionEnd . set_value ( ) ; } } ) ; recognizer -> SessionStopped . Connect ( [ & recognitionEnd ] ( const SessionEventArgs & e ) { cout << " " ; recognitionEnd . set_value ( ) ; } ) ; recognizer -> StartContinuousRecognitionAsync ( ) . get ( ) ; recognitionEnd . get_future ( ) . get ( ) ; recognizer -> StopContinuousRecognitionAsync ( ) . get ( ) ; }
Standalone language detection using a customized model.
Standalone language detection using a customized model .
// <StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput> // 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. // promise for synchronization of recognition end. // Subscribes to events. // Notify to stop recognition. // Notify to stop recognition. // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition. // Waits for recognition end. // Stops recognition. // </StandaloneLanguageDetectionInContinuousModeWithMultiLingualFileInput>