pocketsphinxAdroid离线语音识别---入门

       现在的语音识别大部分都是基于服务端的开发,需要网络的支持才能很好的工作。
想开发一个基于客户端的,不需要网络也可以识别的,识别服务。
可以在客户端的各种应用中进行使用。如谋种游戏进行语音控制,不会被网络所影响。
找到了一个开源的东西了。。。
可以识别英文,中文。

 

 

 

 

pocketsphinx --- 是什么?
      这是微软公司研究人员开发的最新的适用于嵌入式设备上的语言识别系统的源代码,继承了优秀语音识别软件sphinx的优点,用于开发嵌入式系统上的应用。

怎么做?
将这些c的源程序打包成.so,用java去调c接口 进行语音识别。


首先下载一个 PocketSphinxAndroidDemo
https://nodeload.github.com/cjac/cmusphinx/zipball/trunk

说明
http://ucla.jamesyxu.com/?p=118

 

下载一个swig  ---将c 接口转java 并生成java类.

 

下载一个NDK 将c打包成.so文件.

 

 

 

This is done with CMUSphinx 0.7 (so sphinxbase 0.7 and pocketsphinx 0.7). The files are archived at the end of the article. The process also require access to a linux machine and the Eclipse IDE.

  1. Download Sphinx base and pocket sphinx (http://cmusphinx.sourceforge.net/wiki/download/ )
  2. Create a directory somewhere, untar both to ./sphinxbase and ./pocketsphinx (lose the -0.x version suffix)
  3. For each of the two, do the usual ./autogen.sh ./configure, make, make install (make install require root)
  4. Check ./pocketsphinx/swig has libpocketsphinx_jni.so in it. If not, do a make in that directory
  5. Download the PocketSpinxAndroiDemo
  6. untar it to the same directory created in 2
  7. cp -r ./pocketsphinx/swig/edu ./PocketSphinxAndroidDemo/jni/
  8. cd ./PocketSphinxAndroidDemo/jni/
  9. Update SPHINX_PATH to the directory created in 2
  10. Open Android.mk, edit LOCAL_STATIC_LIBRARIES from whatever it was before to “pocketsphinx sphinxlm sphinxfeat sphinxfe sphinxutil” (without qoutes)
  11. Install Android NDK (http://developer.android.com/sdk/ndk/index.html )
  12. stay in the jni directory, do a ndk-build (see the ndk link about for instructions on building if it is not clear)

Now we are ready to open this in Eclipse

  1. Open eclipse and import the project, ignore any build warnings/errors
  2. Untick Project -> Build Automatically (This is personal choice, since the JNI build process is heavy I dont like it building all the time)
  3. Project -> Properties -> Builders
  4. Select SWIG -> Edit -> for Working Directory, select Browse Workspace and pick the jni directory, In the Refresh tab, select The folder containing the selected resource, in Build Options, untick Specify working set of relevant resources (This option may be hidden in the dialog, if you dont see it, maximize the Configuration window).
  5. Select NDK build -> Edit -> Set the correct location for ndk-build, select the correct Working directory (Browse workspace and then select the jni directory). In the Refresh tab, select The project containing the selected resource, in Build Options, untick Specify working set of relevant resources (This option may be hidden in the dialog, if you dont see it, maximize the Configuration window).
  6. Project -> Build Project. If you see any errors, check that step 4 and 5 are carried out correctly. The project should build without error. A console may appear with red texts, just confirm that they are warning messages from building the c code and you should be ok

We should now have a built Android application ready for testing

  1. In the emulator (or phone), create under primary storage (whatever is returned by the getExternalStorageDirectory). For example if you have a sdcard this would be /mnt/sdcard
  2. If using the emulator, call adb shell from a console window, and use mkdir command for the step below (to create directories on the emulator)
  3. Create directory structure: Android/edu.cmu.pocketsphinx/hmm/en_US/hub4wsj_sc_8k, Android/edu/edu.cmu.pocketsphinx/lm/en_US/
  4. Copy pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k/* into the emulator/phone
  5. Copy pocketsphinx/model/lm/en_US/* into emulator/phone
  6. In eclipse, open the RecognizerTask.java file, look for c.setString(“-lm”
  7. Make sure the files loaded in the code around step 6 exists (especially the .dict file may have a different name)
  8. Now we can run the application!

If the app crashes for any reason, go to sdcard/Android/edu.cmu.pocketsphinx and there should be a log file (pocketsphinx.log) from the native library.

Misc thought

  • On my machine (OpenSuSE 11.3) the swig directory was empty after make. Go into swig directory and call make, the errors will be displayed (for me it was because I didn’t have swig installed)
  • By default make install installs to /usr/local/lib which can cause problems on some systems. If you get errors with any of the sphinx stuff saying some library is not found, use the ldd and strace commands to see where they are looking for the libs, and symlink them. Alternatively supply another install location to make install
  • While working in eclipse, if you see any errors along the lines of “Refresh scope invalid”, check step 4 and 5 are carried out from the Eclipse section above.

Files required **Before downloading these archives, try using the latest build from the official website first**:

 

 

下面的apk .demo  是中文的。[说 中国,美国,英国]识别得很好,但是说别的。呵呵、、、

 

 

 

有兴趣的,一起研究、、、   

 

 

相关资料:

http://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/

 

工程共享:https://github.com/cjac/cmusphinx

语音模型:http://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/

转载于:https://my.oschina.net/VenusV/blog/703399

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值