Skip to content

Commit

Permalink
Decoder
Browse files Browse the repository at this point in the history
- Fix crash when stopDecodingSpeech() is called
- Remove the ps_free() from the assert. It was causing memory leak in
reals builds
  • Loading branch information
BrunoBerisso committed Jul 14, 2015
1 parent 6e7aea5 commit 14ccf21
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions TLSphinx/Decoder.swift
Expand Up @@ -55,10 +55,10 @@ public class Decoder {
}

deinit {
assert(ps_free(psDecoder) == 0, "Can't free decoder, it's shared among instances")
let refCount = ps_free(psDecoder)
assert(refCount == 0, "Can't free decoder, it's shared among instances")
}


private func process_raw(data: NSData) -> CInt {
//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.
let dataLenght = data.length / 2
Expand Down Expand Up @@ -204,8 +204,6 @@ public class Decoder {

public func stopDecodingSpeech () {
recorder.stop()
end_utt()

recorder.deleteRecording()
recorder = nil
}
Expand Down
2 changes: 2 additions & 0 deletions TLSphinxTests/LiveDecode.swift
Expand Up @@ -26,7 +26,9 @@ class LiveDecode: XCTestCase {
let dict = modelPath.stringByAppendingPathComponent("cmudict-en-us.dict")

if let config = Config(args: ("-hmm", hmm), ("-lm", lm), ("-dict", dict)) {

config.showDebugInfo = false

if let decoder = Decoder(config:config) {
decoder.startDecodingSpeech { (hyp) -> () in
println("Utterance: \(hyp)")
Expand Down

0 comments on commit 14ccf21

Please sign in to comment.