none
Crash in SpeechRecognizer::StartContinuousRecognitionAsync when called a second time RRS feed

  • Question

  • Hi

    I am using SpeechRecognizer for continuous recognition. I am using C++ as development language with VS 2017, Below is the full sample:

        auto config = SpeechConfig::FromSubscription(_subscriptionKey.toStdString(),
                                                     _serviceRegion.toStdString());

        // Creates a speech recognizer
        auto recognizer = SpeechRecognizer::FromConfig(config);

        // Subscribes to events.
        recognizer->Recognizing.Connect([] (const SpeechRecognitionEventArgs& e) {
            const QString msg = "Recognizing:" + QString::fromStdString(e.Result->Text);
            qInfo() << msg;
        });

        recognizer->Recognized.Connect([this] (const SpeechRecognitionEventArgs& e) {
            if (e.Result->Reason == ResultReason::RecognizedSpeech) {
                const QString res = QString::fromStdString(e.Result->Text);
                if (!res.isEmpty()) {
                    setResult(res);//send only non empty string to EPU
                }
                qInfo() << "RECOGNIZED: Text=" << _result
                        << "Offset=" << e.Result->Offset()
                        << "Duration=" << e.Result->Duration();
            }
            else if (e.Result->Reason == ResultReason::NoMatch) {
                qWarning() << "NOMATCH: Speech could not be recognized.";
            }
        });

        recognizer->Canceled.Connect([this](const SpeechRecognitionCanceledEventArgs& e) {
            qInfo() << "CANCELED: Reason=" << (int)e.Reason;

            if (e.Reason == CancellationReason::Error) {
                const QString msg = "CANCELED: ErrorCode=" + QString::number((int)e.ErrorCode)
                        + "CANCELED: ErrorDetails=" + QString::fromStdString(e.ErrorDetails)
                        + "CANCELED: Did you update the subscription info?";
                qCritical() << msg;
                emit error(msg);
                _recognitionEnd.set_value(); // Notify to stop recognition.
                setStart(false);
            }
        });

        recognizer->SessionStopped.Connect([this](const SessionEventArgs& e) {
            qInfo() << "Session stopped.";
            Q_UNUSED(e)
            _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();

    Can you tell me why running the second time the same code (without stopping the application) crashes the application ? The crash happens in StartContinuousRecognitionAsync


    bogdan

    Wednesday, December 4, 2019 6:44 PM