pocketsphinxAdroid離線語音辨識-入門

來源:互聯網
上載者:User
from : http://www.myexception.cn/mobile/450918.htmlpocketsphinxAdroid離線語音辨識---入門

       現在的語音辨識大部分都是基於服務端的開發,需要網路的支援才能很好的工作。
想開發一個基於用戶端的,不需要網路也可以識別的,識別服務。
可以在用戶端的各種應用中進行使用。如謀種遊戲進行語音控制,不會被網路所影響。
找到了一個開源的東西了。。。
可以識別英文,中文。

 

 

 

 

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**:

  • Sphinxbase 0.7
  • Pocket Sphinx 0.7
  • PocketSphinxAndroidDemo

 

 

下面的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/

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 12 樓 leiwuluan 2012-02-07  你配上全路徑就可以了 3 樓 leiwuluan 2012-02-07  你配上全路徑就可以了  
比如:c:/work_space/sphinxbase/include4 樓 lcfeng1982 2012-02-08  leiwuluan 寫道你配上全路徑就可以了  
比如:c:/work_space/sphinxbase/include

大牛,這個問題我已經解決了,運行了一下試了試,識別正確率很低,正如你所說的“[說 中國,美國,英國]識別得很好”,其他的就不行;為了提高識別率,我在網上搜尋了很久,也沒有發現什麼有價值的資料,我覺得應該可以建立自己的詞語庫來提高識別率,不知道你有沒有這方面的經驗?

5 樓 cs3230524 2012-04-20  樓主知道中文亂碼這個問題怎麼姐姐嗎?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

你的路徑有問題、、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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.