Hi guys, I need help!
I try to replicate the Pocketsphinx-android library in swift language on iOS, everything works well except about adding the language model.
For example, I have about 10 new words already added with "ngram_model_add_word" and then I tried to set the language model with "ps_set_lm", but its take a long time and take 99% CPU usage. But in Android, its only take less than a second. My question is, how to set language model faster and reduce the CPU usage?
fileprivate func generateNGramModel(words: [String]) {
let arpaFile = Utilities.getAssetPath()!.appending("\(SEARCH_ID).arpa")
nGramModel = NGramModel(config: config, logMath: recognizer.getDecoder().getLogMath(), lmFile: arpaFile)
for word in words {
nGramModel?.addWord(word: word.lowercased(), weight: 1.7)
}
recognizer.getDecoder().setLanguageModel(name: SEARCH_ID, nGramModel: nGramModel!)
}
And the method to set the language model:
open func setLanguageModel(name: String, nGramModel: NGramModel) {
if ps_set_lm(pointer, name, nGramModel.getPointer()) < 0 {
print("Set language model failed!")
}
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can use debugger to figure out where the process spends the time by stopping the run several times and looking on backtrace. Based on this information you can find the solution for the problem. Usually the resources are spent in your code, not in pocketsphinx.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Shmyrev, Thanks for your response.
Finally, I found the problem. The problem is in the dictionary, I use a full dictionary when I build the language model with 15 words only. It's why the pocketsphinx take a long time to build the language model on the fly.
And actually I already use minimize dictionary before but pocketsphinx cannot find the dictionary file on iOS because file:// on the path of the dictionary. This is standard path when I use FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) in iOS:
Hi guys, I need help!
I try to replicate the Pocketsphinx-android library in swift language on iOS, everything works well except about adding the language model.
For example, I have about 10 new words already added with "ngram_model_add_word" and then I tried to set the language model with "ps_set_lm", but its take a long time and take 99% CPU usage. But in Android, its only take less than a second. My question is, how to set language model faster and reduce the CPU usage?
And the method to set the language model:
You can use debugger to figure out where the process spends the time by stopping the run several times and looking on backtrace. Based on this information you can find the solution for the problem. Usually the resources are spent in your code, not in pocketsphinx.
Hi Shmyrev, Thanks for your response.
Finally, I found the problem. The problem is in the dictionary, I use a full dictionary when I build the language model with 15 words only. It's why the pocketsphinx take a long time to build the language model on the fly.
And actually I already use minimize dictionary before but pocketsphinx cannot find the dictionary file on iOS because
file://
on the path of the dictionary. This is standard path when I useFileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
in iOS:file:///var/mobile/Containers/Data/Application/.../icaksama-dict.txt
And I need to change the dictionary path to:
/var/mobile/Containers/Data/Application/.../icaksama-dict.txt