DeepSpeech
DeepSpeech copied to clipboard
Swift Client: Fix double deallocation
Hello,
This PR is an attempt to fix a double deallocation issue in the Swift client.
How to produce
- In the Swift demo project deepspeech_ios_test, locate the file SpeechRecognitionImpl.swift, and replace
let result = stream.finishStream()withlet result = stream.finishStreamWithMetadata(numResults: 1) - Run the app and click the button "Recognize files".
- The app will crash as soon as the associated
DeepSpeechStreamis deallocated. In my case, Xcode prompted something like "Thread XXX: Deallocation of freed memory".
References
- @zaptrem also mentioned a similar issue in https://github.com/mozilla/DeepSpeech/issues/3061#issuecomment-776199055: "I'm using intermediateDecodeWithMetadata as finishStreamWithMetadata also has an unknown crash".
Fix
Seems the fix can be as simple as adding one line of code. After the patch, the code pattern of finishStreamWithMetadata(numResults:) now aligns with finishStream().
Thank you
Would like to thank @reuben for the Swift wrapper-related work!
Could you please consider merging this, @reuben? Thanks!
I no longer have push access to this repository. If you can open the PR against our coqui-ai/STT fork I'm happy to merge it.
Few weeks ago I was planning to do that (opening a PR against coqui). But failed to build the iOS static framework -- bazel prompts:
"ERROR: file 'native_client/libkenlm.so' is generated by these conflicting actions:".
Will give it another try later.