Safely stop SpeechPipeline on iOS?

I’m getting occasional crashes after calling the stop() method on SpeechPipeline – it seems I’m prematurely interrupting some ongoing SpeechPipeline process. Is there a safer way to stop the pipeline than just calling .stop()?

The crash occurs in AppleWakewordRecognizer.swift, line 97:

// Automatically restart wakeword task if it goes over Apple’s 1 minute listening limit
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + .milliseconds(self.configuration.wakewordRequestTimeout), execute: self.dispatchWorker!)

Error: AURemoteIO::IOThread (28): Fatal error: Unexpectedly found nil while unwrapping an Optional value

Thanks for any help you can provide!

To clarify, self.dispatchWorker is nil

Hi Nathaniel, thanks for the report!

stop() is expected to be safe, so what you’re reporting is a bug. I’ll triage it and let you know when we release a fix.

Hi Nathaniel, Spokestack-iOS 14.0.2 is now available from CocoaPods with a fix for the bug you reported. Thanks for the heads-up! Let us know how it works for you.

:tada: Congrats
:rocket: Spokestack-iOS (14.0.2) successfully published
:date: October 29th, 17:18
:earth_americas: https://github.com/spokestack/spokestack-ios/releases/tag/14.0.2

Wow!! Thank you so much for the fast response! I’ll test and report back.

That bug seems to be resolved, thank you!

I don’t know if I should make a separate thread, but I have encountered another bug with the same setup (using the appleWakewordAppleSpeech profile on iOS 14.1). After running the SpeechPipeline for a few minutes after calling .start(), I will occasionally get a crash with this message:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘SFSpeechAudioBufferRecognitionRequest cannot be re-used’

terminating with uncaught exception of type NSException

This usually follows a lot of these warnings:

[Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=209 "(null)"

Thanks for all your help!

Hi,
I do follow you advice from you guys and works well now
best regards