使用PocketSphinx的Android离线语音识别 [英] Android offline voice recognition using PocketSphinx

查看:662
本文介绍了使用PocketSphinx的Android离线语音识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用引用该站点的PocketSphinx尝试在没有互联网的情况下进行语音识别,

Trying to do Voice Recognition without internet using PocketSphinx referrring to the site,

http://swathiep.blogspot.com/2011/02/offline-speech-recognition-with.html

跟上一样.

在模拟器中运行该程序,因为它不支持音频,导致崩溃(不是强制关闭).但是,当尝试在手机上运行该程序时,该应用程序只是打开和关闭(不是强制关闭).需要添加任何内容更多库来运行此应用程序????????? 请快速回复任何人........

Run the program in emulator,since it will not support audio, get crashed(not Force Close).but while trying to run this on phone,the application just opened and closed(not Force Close).Do need to add any more libraries to run this application????????? pls reply fast anyone........

推荐答案

CMUSphinx提供了有关Android上Pocketsphinx的最新文档

Latest documentation on pocketsphinx on android is provided on CMUSphinx wiki.

基本上,您需要从 Github 中提取演示,将其导入android studio并运行,这样您就可以测试基本功能.

Basically you need to pull the demo from Github, import it into android studio and run, this way you can test basic functionality.

要开始集成到您自己的应用程序中,请执行以下操作:

To start integration into your own application do the following:

在Android项目中引用库

库以与体系结构无关的pocketsphinx-android-5prealpha-nolib.jar和二进制.so文件的形式分发,用于不同的硬件体系结构.

Library is distributed as architecture-independent pocketsphinx-android-5prealpha-nolib.jar and binary .so files for different hardware architectures.

在Android Studio中,您需要将jar文件放在app/libs文件夹中,并将jni .so文件放入app/src/main/jniLibs文件夹中.

In Android Studio you need to place jar file in app/libs folder and jni .so files into app/src/main/jniLibs folder.

包括资源文件

在Android中随应用程序一起发送资源文件的标准方法是将它们放在项目的资产/目录中.但是,为了使它们可用于Pocketsphinx文件,它们应该具有物理路径,只要它们位于.apk之内,就没有该路径.来自Pocketsphinx-android的Assets类提供了一种自动将资产文件复制到目标设备的外部存储的方法. edu.cmu.pocketsphinx.Assets#syncAssets同步资源,以读取位于顶部assets/上的asset.lst文件中的项目.复制之前,它与资产和外部存储中具有相同名称的文件的MD5校验和(如果存在)匹配.仅当信息不完整(外部存储中没有文件,两个.md5文件中没有任何文件)或哈希不匹配时,它才进行实际复制. PocketSphinxAndroidDemo包含可生成asset.lst以及.md5文件的ant脚本,请查找assets.xml.

The standard way to ship resource files with your application in Android is to put them in assets/ directory of your project. But in order to make them available for pocketsphinx files should have physical path, as long as they are within .apk they don't have one. Assets class from pocketsphinx-android provides a method to automatically copy asset files to external storage of the target device. edu.cmu.pocketsphinx.Assets#syncAssets synchronizes resources reading items from assets.lst file located on the top assets/. Before copying it matches MD5 checksums of an asset and a file on external storage with the same name if such exists. It only does actualy copying if there is incomplete information (no file on external storage, no any of two .md5 files) or there is hash mismatch. PocketSphinxAndroidDemo contains ant script that generates assets.lst as well as .md5 files, look for assets.xml.

请注意,如果蚂蚁构建脚本在构建过程中无法正常运行,则资产可能不同步.确保脚本可以运行或自行创建md5文件和资产.

Please note that if ant build script doesn't run properly in your build process, assets might be out of sync. Make sure that script runs or create md5 files and assets.lst yourself.

要在您的应用程序中集成资产同步,请执行以下操作

To integrate assets sync in your application do the following

将app/asset.xml构建文件包含到您的应用程序中 编辑build.gradle构建文件以运行asset.xml:

Include app/asset.xml build file into your application Edit build.gradle build file to run assets.xml:

  ant.importBuild 'assets.xml'
  preBuild.dependsOn(list, checksum)
  clean.dependsOn(clean_assets)

应该可以解决问题

示例应用

pocketsphinx-android的类和方法的设计类似于在Pocketsphinx中使用的相同工作流程,不同之处在于将组织为类的基本数据结构和与之配合使用的功能转换为相应类的方法.因此,如果您熟悉Pocketsphinx,也应该对Pocketsphinx-android感到满意.

The classes and methods of pocketsphinx-android were designed to resemble the same workflow used in pocketsphinx, except that basic data structures organized into classes and functions working with them are turned into methods of the corresponding classes. So if you are familiar with pocketsphinx you should feel comfortable with pocketsphinx-android too.

SpeechRecognizer是访问解码器功能的主要类别.它是在SpeechRecognizerSetup构建器的帮助下创建的. SpeechRecognizerBuilder允许配置解码器的主要属性以及其他参数.参数键和值与在命令行中传递给Pocketsphinx二进制文件的参数相同.了解有关调整Pocketsphinx性能的更多信息.

SpeechRecognizer is the main class to access decoder functionality. It is created with the help of SpeechRecognizerSetup builder. SpeechRecognizerBuilder allows to configure main properties as well as other parameters of teh decoder. The parameters keys and values are the same as those are passed in command-line to pocketsphinx binaries. Read more about tweaking pocketsphinx performance.

recognizer = defaultSetup()
        .setAcousticModel(new File(assetsDir, "en-us-ptm"))
        .setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
        .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
        .getRecognizer();
recognizer.addListener(this);

解码器配置是一个冗长的过程,其中包含IO操作,因此建议在异步任务内部运行.

Decoder configuration is lengthy process that contains IO operation, so it's recommended to run in inside async task.

解码器支持多个命名搜索,您可以在运行时进行切换

Decoder supports multiple named searches which you can switch in runtime

// Create keyword-activation search.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
// Create grammar-based searches.
File menuGrammar = new File(assetsDir, "menu.gram");
recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
// Next search for digits
File digitsGrammar = new File(assetsDir, "digits.gram");
recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);
// Create language model search.
File languageModel = new File(assetsDir, "weather.dmp");
recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);

设置解码器并添加所有搜索后,您就可以开始识别

Once you setup the decoder and add all the searches you can start recognition with

 recognizer.startListening(searchName);

您将在识别器侦听器的onEndOfSpeech回调中收到有关语音结束事件的通知.然后,您可以调用identifier.stop或identifier.cancel().后一个会取消识别,前一个会导致最终结果在onResult回调中传递给您.

You will get notified on speech end event in onEndOfSpeech callback of the recognizer listener. Then you could call recognizer.stop or recognizer.cancel(). Latter will cancel the recognition, former will cause the final result be passed you in onResult callback.

在识别期间,您将在onPartialResult回调中获得部分结果.

During the recognition you will get partial results in onPartialResult callback.

您还可以访问swig中用Java类包装的其他Pocketsphinx方法,检查详细信息:解码器,假设,分段和NBest类.

You can also access other Pocketsphinx method wrapped with Java classes in swig, check for details Decoder, Hypothesis, Segment and NBest classes.

这篇关于使用PocketSphinx的Android离线语音识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆