当前位置:  编程技术>移动开发
本页文章导读:
    ▪pocketsphinxAdroid离线语音识别-入门        pocketsphinxAdroid离线语音识别---入门        现在的语音识别大部分都是基于服务端的开发,需要网络的支持才能很好的工作。 想开发一个基于客户端的,不需要网络也可以识别的,识别服.........
    ▪ OO的五大准则        OO的五大原则 1. SRP(Single Responsibility Principle 单一职责原则): 单一职责很容易理解,也很容易实现。所谓单一职责,就是一个设计元素只做一件事。什么是“只做一件事”?简单说就是少.........
    ▪ 八种结构型模式 之2 ADAPTER 适配器模式       8种结构型模式 之2 ADAPTER 适配器模式 适配器模式 是一种“补偿”模式,通常用来解决接口不相容的问题。分成 类适配器模式 和 对象适配器模式 2种 。1:类适配器模式2:对象适配器模式.........

[1]pocketsphinxAdroid离线语音识别-入门
    来源: 互联网  发布时间: 2014-02-18
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.

  • Download Sphinx base and pocket sphinx (http://cmusphinx.sourceforge.net/wiki/download/ )
  • Create a directory somewhere, untar both to ./sphinxbase and ./pocketsphinx (lose the -0.x version suffix)
  • For each of the two, do the usual ./autogen.sh ./configure, make, make install (make install require root)
  • Check ./pocketsphinx/swig has libpocketsphinx_jni.so in it. If not, do a make in that directory
  • Download the PocketSpinxAndroiDemo
  • untar it to the same directory created in 2
  • cp -r ./pocketsphinx/swig/edu ./PocketSphinxAndroidDemo/jni/
  • cd ./PocketSphinxAndroidDemo/jni/
  • Update SPHINX_PATH to the directory created in 2
  • Open Android.mk, edit LOCAL_STATIC_LIBRARIES from whatever it was before to “pocketsphinx sphinxlm sphinxfeat sphinxfe sphinxutil” (without qoutes)
  • Install Android NDK (http://developer.android.com/sdk/ndk/index.html )
  • 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

  • Open eclipse and import the project, ignore any build warnings/errors
  • Untick Project -> Build Automatically (This is personal choice, since the JNI build process is heavy I dont like it building all the time)
  • Project -> Properties -> Builders
  • 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).
  • 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).
  • 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

  • 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
  • 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)
  • Create directory structure: Android/edu.cmu.pocketsphinx/hmm/en_US/hub4wsj_sc_8k, Android/edu/edu.cmu.pocketsphinx/lm/en_US/
  • Copy pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k/* into the emulator/phone
  • Copy pocketsphinx/model/lm/en_US/* into emulator/phone
  • In eclipse, open the RecognizerTask.java file, look for c.setString(“-lm”
  • Make sure the files loaded in the code around step 6 exists (especially the .dict file may have a different name)
  • 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 1
    2 楼 leiwuluan 2012-02-07  
    你配上全路径就可以了 
    3 楼 leiwuluan 2012-02-07  
    你配上全路径就可以了 
    比如:c:/work_space/sphinxbase/include
    4 楼 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

        
    [2] OO的五大准则
        来源: 互联网  发布时间: 2014-02-18
    OO的五大原则
    1. SRP(Single Responsibility Principle 单一职责原则):

    单一职责很容易理解,也很容易实现。所谓单一职责,就是一个设计元素只做一件事。什么是“只做一件事”?简单说就是少管闲事。现实中就是如此,如果要你专心做一件事情,任何人都有信心可以做得很出色。

    2. OCP :开闭原则:

    很简单,一句话:“Closed for Modification; Open for Extension”——“对变更关闭;对扩展开放”。

    3.LSP——里氏替换原则:

    Liskov于1987年提出了一个关于继承的原则“继承必须确保超类所拥有的性质在子类中仍然成立。”也就是说,当一个子类的实例应该能够替换任何其超类的实例时,它们之间才具有is-A关系。 举一个例子:生物学的分类体系中把企鹅归属为鸟类。类“鸟”中有个方法fly,企鹅自然也继承了这个方法,可是企鹅不能飞.

    4.DIP 依赖倒置原则:

    依赖倒置(Dependence Inversion Principle)原则讲的是:要依赖于抽象,不要依赖于具体。 简单的说,依赖倒置原则要求客户端依赖于抽象耦合。原则表述: 抽象不应当依赖于细节;细节应当依赖于抽象; 要针对接口编程,不针对实现编程。

    5.ISP 接口隔离原则:

    使用多个专门的接口比使用单一的总接口要好。

        
    [3] 八种结构型模式 之2 ADAPTER 适配器模式
        来源: 互联网  发布时间: 2014-02-18
    8种结构型模式 之2 ADAPTER 适配器模式
    适配器模式 是一种“补偿”模式,通常用来解决接口不相容的问题。分成 类适配器模式 和 对象适配器模式 2种 。



    1:类适配器模式



    2:对象适配器模式



        
    最新技术文章:
    ▪Android开发之登录验证实例教程
    nosql iis7站长之家
    ▪Android获取手机SIM卡运营商信息的方法
    ▪Android实现将已发送的短信写入短信数据库的...
    ▪Android发送短信功能代码
    ▪Android根据电话号码获得联系人头像实例代码
    ▪Android中GPS定位的用法实例
    ▪Android实现退出时关闭所有Activity的方法
    ▪Android实现文件的分割和组装
    ▪Android录音应用实例教程
    ▪Android双击返回键退出程序的实现方法
    ▪Android实现侦听电池状态显示、电量及充电动...
    ▪Android获取当前已连接的wifi信号强度的方法
    ▪Android实现动态显示或隐藏密码输入框的内容
    ▪根据USER-AGENT判断手机类型并跳转到相应的app...
    ▪Android Touch事件分发过程详解
    ▪Android中实现为TextView添加多个可点击的文本
    ▪Android程序设计之AIDL实例详解
    ▪Android显式启动与隐式启动Activity的区别介绍
    ▪Android按钮单击事件的四种常用写法总结
    ▪Android消息处理机制Looper和Handler详解
    ▪Android实现Back功能代码片段总结
    ▪Android实用的代码片段 常用代码总结
    ▪Android实现弹出键盘的方法
    ▪Android中通过view方式获取当前Activity的屏幕截...
    ▪Android提高之自定义Menu(TabMenu)实现方法
    ▪Android提高之多方向抽屉实现方法
    ▪Android提高之MediaPlayer播放网络音频的实现方法...
    ▪Android提高之MediaPlayer播放网络视频的实现方法...
    ▪Android提高之手游转电视游戏的模拟操控
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3