Android下通过pocketsphinx实现离线语音识别的环境搭建和demo运行(续)--实现Windows下的语音识别

本文介绍了如何在Windows下搭建Android离线语音识别环境,使用pocketsphinx和Cygwin模拟Linux环境。通过jni编程调用sphinx和pocketsphinx库,实现语音到文字的识别。作者分享了遇到的问题和解决方案,包括Cygwin的安装、NDK环境配置、Eclipse NDK Builder的调整,并提供了源代码下载链接。
摘要由CSDN通过智能技术生成

前言:大家好,这是我的第二篇博文。上一篇介绍了一下在Linux环境下实现android的离线语音识别,本文主要说一下如何将这个工程成功地在Windows下运行起来。还是那句话,我所涉及的范围只是“应用”,由于时间的关系,对于一些原理性的东西我确实没有弄明白,我只是要求能够跑通,能够实现成功地的识别的目的。我会将一些我不懂的问题在下边一一列出来,有时间我一定尽力把它的原理弄明白。另外,上一篇中我引用了许多链接,虽然方便了,但我感觉不如自己写出来对自己以后发展更有帮助,很容易就忘掉了,所以,在这一次我争取把我所从事的试验、尝试和所遇到的问题都写出来,希望帮到别人同时也提醒自己不要忘掉。

我对这一个工程的理解:在我看来,这一工程实际上就是一个通过jni编程调用微软写的sphinx和pocketsphinx函数库(这两个库都是C语言写的),然后通过声学模型分析录入的语音,根据分析出的特性在数据字典中寻找匹配的文字。主要用到的知识应该就是jni交叉语言编程,其实质也就是通过NDK,借助这两个函数库编译出最终的.so文件。(当然,这其中也包括用到swig将c 接口转java 并生成java类,这个我不太懂就不说了)最终的android程序也就是要通过这个.so文件去实现识别功能,android终究是linux的程序,它还是要依托linux下的共享函数库即.so文件而不是windows下的.dll文件。

可以实现录音,有效率超过百分之九十九 package edu.cmu.pocketsphinx.demo; import java.util.Date; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class PocketSphinxIntent extends Activity implements OnTouchListener, RecognitionListener { static { System.loadLibrary("pocketsphinx_jni"); } public static final String EXTRA_RESULTS = "PockectSphinxExtraResults"; /** * Recognizer task, which runs in a worker thread. */ RecognizerTask rec; /** * Thread in which the recognizer task runs. */ Thread rec_thread; /** * Time at which current recognition started. */ Date start_date; /** * Number of seconds of speech. */ float speech_dur; /** * Are we listening? */ boolean listening; /** * Progress dialog for final recognition. */ ProgressDialog rec_dialog; /** * Performance counter view. */ TextView performance_text; /** * Editable text view. */ EditText edit_text; Intent intent; /** * Respond to touch events on the Speak button. * * This allows the Speak button to function as a "push and hold" button, by * triggering the start of recognition when it is first pushed, and the end * of recognition when it is released. * * @param v * View on which this event is called * @param event * Event that was triggered. */ public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: start_date = new Date(); this.listening = true; this.rec.start(); break; case MotionEvent.ACTION_UP: Date end_date = new Date();
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值