Skip to content

Commit 14ccf21

Browse files
author
BrunoBerisso
committed
Decoder
- Fix crash when stopDecodingSpeech() is called - Remove the ps_free() from the assert. It was causing memory leak in reals builds
1 parent 6e7aea5 commit 14ccf21

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

TLSphinx/Decoder.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ public class Decoder {
5555
}
5656

5757
deinit {
58-
assert(ps_free(psDecoder) == 0, "Can't free decoder, it's shared among instances")
58+
let refCount = ps_free(psDecoder)
59+
assert(refCount == 0, "Can't free decoder, it's shared among instances")
5960
}
6061

61-
6262
private func process_raw(data: NSData) -> CInt {
6363
//Sphinx expect words of 2 bytes but the NSFileHandle read one byte at time so the lenght of the data for sphinx is the half of the real one.
6464
let dataLenght = data.length / 2
@@ -204,8 +204,6 @@ public class Decoder {
204204

205205
public func stopDecodingSpeech () {
206206
recorder.stop()
207-
end_utt()
208-
209207
recorder.deleteRecording()
210208
recorder = nil
211209
}

TLSphinxTests/LiveDecode.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class LiveDecode: XCTestCase {
2626
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")
2727

2828
if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) {
29+
2930
config.showDebugInfo = false
31+
3032
if let decoder = Decoder(config:config) {
3133
decoder.startDecodingSpeech { (hyp) -> () in
3234
println("Utterance: \(hyp)")

0 commit comments

Comments
 (0)