问题
Trying to do Voice Recognition without internet using PocketSphinx referrring to the site,
http://swathiep.blogspot.com/2011/02/offline-speech-recognition-with.html
Followed the same as what it is.
Run the program in emulator,since it will not support audio, get crashed(not Force Close).but while trying to run this on phone,the application just opened and closed(not Force Close).Do need to add any more libraries to run this application????????? pls reply fast anyone........
回答1:
Latest documentation on pocketsphinx on android is provided on CMUSphinx wiki.
Basically you need to pull the demo from Github, import it into android studio and run, this way you can test basic functionality.
To start integration into your own application do the following:
Referencing the library in Android project
Library is distributed as architecture-independent pocketsphinx-android-5prealpha-nolib.jar and binary .so files for different hardware architectures.
In Android Studio you need to place jar file in app/libs folder and jni .so files into app/src/main/jniLibs folder.
Including resource files
The standard way to ship resource files with your application in Android is to put them in assets/ directory of your project. But in order to make them available for pocketsphinx files should have physical path, as long as they are within .apk they don't have one. Assets class from pocketsphinx-android provides a method to automatically copy asset files to external storage of the target device. edu.cmu.pocketsphinx.Assets#syncAssets
synchronizes resources reading items from assets.lst file located on the top assets/
. Before copying it matches MD5 checksums of an asset and a file on external storage with the same name if such exists. It only does actualy copying if there is incomplete information (no file on external storage, no any of two .md5 files) or there is hash mismatch. PocketSphinxAndroidDemo contains ant script that generates assets.lst as well as .md5 files, look for assets.xml.
Please note that if ant build script doesn't run properly in your build process, assets might be out of sync. Make sure that script runs or create md5 files and assets.lst yourself.
To integrate assets sync in your application do the following
Include app/asset.xml build file into your application Edit build.gradle build file to run assets.xml:
ant.importBuild 'assets.xml'
preBuild.dependsOn(list, checksum)
clean.dependsOn(clean_assets)
That should do the trick
Sample application
The classes and methods of pocketsphinx-android were designed to resemble the same workflow used in pocketsphinx, except that basic data structures organized into classes and functions working with them are turned into methods of the corresponding classes. So if you are familiar with pocketsphinx you should feel comfortable with pocketsphinx-android too.
SpeechRecognizer is the main class to access decoder functionality. It is created with the help of SpeechRecognizerSetup
builder. SpeechRecognizerBuilder allows to configure main properties as well as other parameters of teh decoder. The parameters keys and values are the same as those are passed in command-line to pocketsphinx binaries. Read more about tweaking pocketsphinx performance.
recognizer = defaultSetup()
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
.setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
.getRecognizer();
recognizer.addListener(this);
Decoder configuration is lengthy process that contains IO operation, so it's recommended to run in inside async task.
Decoder supports multiple named searches which you can switch in runtime
// Create keyword-activation search.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
// Create grammar-based searches.
File menuGrammar = new File(assetsDir, "menu.gram");
recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
// Next search for digits
File digitsGrammar = new File(assetsDir, "digits.gram");
recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
// Create language model search.
File languageModel = new File(assetsDir, "weather.dmp");
recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);
Once you setup the decoder and add all the searches you can start recognition with
recognizer.startListening(searchName);
You will get notified on speech end event in onEndOfSpeech callback of the recognizer listener. Then you could call recognizer.stop or recognizer.cancel(). Latter will cancel the recognition, former will cause the final result be passed you in onResult callback.
During the recognition you will get partial results in onPartialResult callback.
You can also access other Pocketsphinx method wrapped with Java classes in swig, check for details Decoder, Hypothesis, Segment and NBest classes.
来源:https://stackoverflow.com/questions/8999140/android-offline-voice-recognition-using-pocketsphinx