`
leiwuluan
  • 浏览: 703576 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类

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/

11
1
分享到:
评论
20 楼 潇寒听竹 2015-12-25  
你好,请问您上传的那个APK为什么每次只能识别一次,不能连续识别呢?
19 楼 adminwuhen 2013-12-11  
adminwuhen 写道
您好,请问我在pocketsphinx-0.7目录下面./autogen.sh,make,sudo make install,之后也没有报错,但是编译了几次都是无法编译出libpocketsphinx_jni.so文件,请问下是什么原因啊?折腾了一阵了,请指点一二,非常感谢!

注:
sphinxbase-0.7编译过程中没有报什么错,
另,我在pocketsphinx-0.7版本中编译就会报下面等错误,pocketsphinx-0.7不报错
../../src/libpocketsphinx/.libs/libpocketsphinx.so: undefined reference to `feat_array_realloc'
collect2: ld returned 1 exit status


已经可以编译出libpocketsphinx_jni.so文件了,但是在jni目录下面ndk-build的时候,报错,那个头文件在哪里啊?谢谢了
/PocketSphinxAndroidDemo/jni/pocketsphinx_wrap.c:760:26: fatal error: pocketsphinx.h: No such file or directory
compilation terminated.
make: *** [/home/likewise-open/SPREADTRUM/changhua.wu/Pis/Yuyin/Yuyin/PocketSphinxAndroidDemo/obj/local/armeabi/objs-debug/pocketsphinx_jni/pocketsphinx_wrap.o] Error 1
18 楼 adminwuhen 2013-12-11  
您好,请问我在pocketsphinx-0.7目录下面./autogen.sh,make,sudo make install,之后也没有报错,但是编译了几次都是无法编译出libpocketsphinx_jni.so文件,请问下是什么原因啊?折腾了一阵了,请指点一二,非常感谢!

注:
sphinxbase-0.7编译过程中没有报什么错,
另,我在pocketsphinx-0.7版本中编译就会报下面等错误,pocketsphinx-0.7不报错
../../src/libpocketsphinx/.libs/libpocketsphinx.so: undefined reference to `feat_array_realloc'
collect2: ld returned 1 exit status
17 楼 pinggle 2013-06-05  
高手,你好,我把你的项目源码放在Eclipse里面编译之后,出现: R cannot be resolved to a variable, 那个gen文件为空,我仔细看了你的源码,里面是没有gen文件的,请问怎么解决啊?
16 楼 白不二 2013-05-21  
楼主你好,我先在手机上安装了附件中的apk,但是在手机上打开的时候总是闪退,好不容易打开一次,一按hold键就退出了,这是怎么回事?
15 楼 leiwuluan 2013-02-25  
好长时间没空! - 我过几天发个apk上来给大家共享。 太忙了最近1
14 楼 leeshuai006 2013-02-23  
我没有编译,直接将您的APK里面的libpocketsphinx_jni.so文件放在了我的工程libs目录下面,然后生产APK文件,但是在手机上运行,一点hold就自动退出了,不知道什么原因,请教!
13 楼 jhengko 2013-02-19  
請問可以在WIN7上安裝使用嗎?
12 楼 秦皇cht 2013-02-19  
您好,我在ubuntu环境下编译的时候,进入了sphinxbase目录下,敲进命令./autogen.sh  ./configure之后正常没有报错,然后敲命令make,电脑就开始死机了,一直停在一个文件上不动了,这是什么原因,望指教!
11 楼 xhban520 2012-10-10  
你好,我这里生成的 pocketsphinx/swig/pocketsphinx_wrap.c 与在PocketSphinxAndroidDemo/jni/pocketsphinx_wrap.c文件相差相大,并且生成的Config.java和decoder.java中的也没有对应的类构造函数,生成的apk安装后,在new RecognizerTask时会产生signal 11,你可以帮我分析分析吗,急用(fedora 17 ,swig:2.0.8 )
10 楼 TangShangWen 2012-09-27  
请问那个全路径加在哪里?
9 楼 aqinh 2012-08-20  
Demo运行后在pocketsphinx.log日志中出现如下错误, 识别也没有成功

ERROR: "dict.c", line 194: Line 1: Phone 'Q' is mising in the acoustic model; word '前进' ignored
ERROR: "dict.c", line 194: Line 2: Phone 'H' is mising in the acoustic model; word '后退' ignored
ERROR: "dict.c", line 194: Line 3: Phone 'Z' is mising in the acoustic model; word '左转' ignored
ERROR: "dict.c", line 194: Line 4: Phone 'Y' is mising in the acoustic model; word '右转' ignored
ERROR: "dict.c", line 194: Line 5: Phone 'T' is mising in the acoustic model; word '停止' ignored
8 楼 cxksmyt003 2012-08-10  
你好,我按照您这里指导的步骤在linux系统下生成libpocketsphinx_jni.so文件时会提示sphinx.h文件找不到,请问这是什么原因。
7 楼 leiwuluan 2012-05-04  
leiwuluan 写道
lcfeng1982 写道
请问在win7环境下使用cygwin如何编译工程?我编译了几次都没能产生libpocketsphinx_jni.so文件,而且在swig文件下make的时候报错:
mkdir -p edu/cmu/pocketsphinx
swig -I../include -I../../sphinxbase/include \
        -java -package edu.cmu.pocketsphinx \
        -outdir edu/cmu/pocketsphinx pocketsphinx.i
cc -g -Wall -DPIC -fPIC -I/usr/lib/jvm/default-java/include `pkg-config --cflags sphinxbase pocketsphinx`  -c -o pocketsphinx_wrap.o pocketsphinx_wrap.c
Package sphinxbase was not found in the pkg-config search path.
Perhaps you should add the directory containing `sphinxbase.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sphinxbase' found
Package pocketsphinx was not found in the pkg-config search path.
Perhaps you should add the directory containing `pocketsphinx.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pocketsphinx' found
pocketsphinx_wrap.c:1:0: warning: -fPIC ignored for target (all code is position independent)
pocketsphinx_wrap.c:760:26: fatal error: pocketsphinx.h: No such file or directory
compilation terminated.
<builtin>: recipe for target `pocketsphinx_wrap.o' failed
make: *** [pocketsphinx_wrap.o] Error 1



你的路径有问题、、



写个全路径。。比如  D:/workspace/project/android_deom
6 楼 leiwuluan 2012-05-04  
lcfeng1982 写道
请问在win7环境下使用cygwin如何编译工程?我编译了几次都没能产生libpocketsphinx_jni.so文件,而且在swig文件下make的时候报错:
mkdir -p edu/cmu/pocketsphinx
swig -I../include -I../../sphinxbase/include \
        -java -package edu.cmu.pocketsphinx \
        -outdir edu/cmu/pocketsphinx pocketsphinx.i
cc -g -Wall -DPIC -fPIC -I/usr/lib/jvm/default-java/include `pkg-config --cflags sphinxbase pocketsphinx`  -c -o pocketsphinx_wrap.o pocketsphinx_wrap.c
Package sphinxbase was not found in the pkg-config search path.
Perhaps you should add the directory containing `sphinxbase.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sphinxbase' found
Package pocketsphinx was not found in the pkg-config search path.
Perhaps you should add the directory containing `pocketsphinx.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pocketsphinx' found
pocketsphinx_wrap.c:1:0: warning: -fPIC ignored for target (all code is position independent)
pocketsphinx_wrap.c:760:26: fatal error: pocketsphinx.h: No such file or directory
compilation terminated.
<builtin>: recipe for target `pocketsphinx_wrap.o' failed
make: *** [pocketsphinx_wrap.o] Error 1



你的路径有问题、、
5 楼 cs3230524 2012-04-20  
楼主知道中文乱码这个问题怎么姐姐吗?
4 楼 lcfeng1982 2012-02-08  
leiwuluan 写道
你配上全路径就可以了 
比如:c:/work_space/sphinxbase/include


大牛,这个问题我已经解决了,运行了一下试了试,识别正确率很低,正如你所说的“[说 中国,美国,英国]识别得很好”,其他的就不行;为了提高识别率,我在网上搜索了很久,也没有发现什么有价值的资料,我觉得应该可以建立自己的词语库来提高识别率,不知道你有没有这方面的经验?
3 楼 leiwuluan 2012-02-07  
你配上全路径就可以了 
比如:c:/work_space/sphinxbase/include
2 楼 leiwuluan 2012-02-07  
你配上全路径就可以了 
1 楼 lcfeng1982 2012-02-02  
请问在win7环境下使用cygwin如何编译工程?我编译了几次都没能产生libpocketsphinx_jni.so文件,而且在swig文件下make的时候报错:
mkdir -p edu/cmu/pocketsphinx
swig -I../include -I../../sphinxbase/include \
        -java -package edu.cmu.pocketsphinx \
        -outdir edu/cmu/pocketsphinx pocketsphinx.i
cc -g -Wall -DPIC -fPIC -I/usr/lib/jvm/default-java/include `pkg-config --cflags sphinxbase pocketsphinx`  -c -o pocketsphinx_wrap.o pocketsphinx_wrap.c
Package sphinxbase was not found in the pkg-config search path.
Perhaps you should add the directory containing `sphinxbase.pc'
to the PKG_CONFIG_PATH environment variable
No package 'sphinxbase' found
Package pocketsphinx was not found in the pkg-config search path.
Perhaps you should add the directory containing `pocketsphinx.pc'
to the PKG_CONFIG_PATH environment variable
No package 'pocketsphinx' found
pocketsphinx_wrap.c:1:0: warning: -fPIC ignored for target (all code is position independent)
pocketsphinx_wrap.c:760:26: fatal error: pocketsphinx.h: No such file or directory
compilation terminated.
<builtin>: recipe for target `pocketsphinx_wrap.o' failed
make: *** [pocketsphinx_wrap.o] Error 1

相关推荐

Global site tag (gtag.js) - Google Analytics