文件未发现异常? (语音识别测试) [英] File not found exception? (Voice recog)

查看:277
本文介绍了文件未发现异常? (语音识别测试)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉的长期问题,我一直停留在这一个月,我想提供尽可能多的细节可能的...它只是一个文件,没有找到一个简单的库例外...:)

我得到一个文件中未发现异常我方差文件:

在这里输入的形象描述

我这样做,但是,有差异的文件:

在这里输入的形象描述

我想简单地实现语音识别在我的后台服务,这样当用户打招呼(使用pocketsphinx)字我能察觉。

问题发生在此方法: createSphinxDir();

这是我的服务:

  @覆盖
    公共无效的onCreate(){
        super.onCreate();
       SETU precog();        }
     私人无效SETU precog(){
    串sphinxDir = createSphinxDir();
    Log.v(TAG,要创建SETUP);
    如果(sphinxDir!= NULL){
        尝试{            Log.v(TAG,设置:)!);
            mSpeechRecognizer = defaultSetup()
                    .setAcousticModel(新文件(sphinxDir,EN-US-PTM))
                    .setDictionary(新文件(sphinxDirhello.dict))
                    .setBoolean( - allphone_ci,真)//这是什么
                    .getRecognizer();
            mSpeechRecognizer.addListener(本);            Log.v(TAG,补充说:LISTENER);            如果((新文件(sphinxDir +文件分割符+command.gram))。ISFILE()){
                mSpeechRecognizer.addKeywordSearch(你好,
                        新的文件(sphinxDir +文件分割符+command.gram));                Log.v(TAG,补充说:关键字搜索:)!);
            }            //或酌情
            mSpeechRecognizer.startListening(唤醒); //它是否正确?
            Log.v(TAG,开始听);        }赶上(IOException异常五){            Log.v(ERROR,TAG);        }
    }
}
串createSphinxDir(){
    共享preferences preFS = preferenceManager.getDefaultShared preferences(本);
    字符串sphinxDir = prefs.getString(狮身人面像,NULL);
    如果(sphinxDir == NULL){
        资产资产;
        Log.v(TAG的资产不同步,现在应该同步:);
        尝试{
            Log.v(TAG,在try块!);
            资产=新资产(本);
            文件sphinxDirFile = assets.syncAssets();
            Log.v(TAG,同步资产......应该建立监听器);
            如果(sphinxDirFile!= NULL){
                sphinxDir = sphinxDirFile.getAbsolutePath();
                共享preferences.Editor编辑器= prefs.edit();
                editor.putString(狮身人面像,sphinxDir);
                editor.commit();
                Log.v(TAG,设置监听器);            }其他{
                Log.v(TAGsphinxDirFile为空!);
            }
        }赶上(IOException异常五){//这是我正在错误的地方!
            e.printStackTrace();
            Log.d(TAG,e.toString());
        }
    }
    返回sphinxDir;
}

我也有所有的回调方法(onPartialResult,onResult等),但他们从来没有被调用。

早些时候,我得到一个异常说.md5文件不存在的方差,所以我把一个空间,在方差和<$ C之间$ C> .md5 ,但现在我得到这个错误,我不知道为什么...

请让我知道,

Ruchir


解决方案

  

早些时候我得到一个异常说.md5文件不存在的方差,所以我把一个空间的差异和.md5之间,但现在我得到这个错误,我不知道为什么。 ..


您不应该做这样的事情,它会导致的问题,而是你需要遵循文档

出货与Android的应用程序资源文件的标准方法是把它们放在你的项目资产/ 目录。但是,为了使它们可用于pocketsphinx文件应该有物理路径,只要他们是在 .apk文件他们没有之一。从pocketsphinx-android的资产类提供了一个方法来自动资产文件复制到目标设备的外部存储。 edu.cmu.pocketsphinx.Assets#syncAssets 可以同步资源从 assets.lst 文件位于顶部<$读项目C $ C>资产/ 。复制之前,它相匹配的资产的MD5校验和与如果这种存在相同名称的外部存储的文件。它只做actualy复制,如果有不完整的信息(外部存储上没有文件,没有任何两个 .md5 文件)或有哈希不匹配。 PocketSphinxAndroidDemo包含ant脚本生成 assets.lst 以及 .md5 文件,寻找 assets.xml

请注意,如果Ant构建脚本不会在构建过程中正常运行,资产可能是不同步的。确保脚本生成过程中运行。

要整合资产同步在应用程序中执行以下操作

包含应用程序/ asset.xml 建立从演示应用程序文件到您的应用程序。编辑的build.gradle 构建文件运行 assets.xml

  ant.importBuild'assets.xml
  preBuild.dependsOn(列表,校验和)
  clean.dependsOn(clean_assets)

Sorry for the long question, I have been stuck on this for a month, and I want to provide as much detail as possible...its just a file not found exception in a simple library... :)

I am getting a file not found exception on my variances file:

I do, however, have the variances file:

I am trying to simply implement voice recognition in my background service, so that I can detect when the user says the word hello (using pocketsphinx).

The problem happens in this method: createSphinxDir();

Here is my service:

 @Override
    public void onCreate() {
        super.onCreate();
       setupRecog();

        }
     private void setupRecog() {
    String sphinxDir = createSphinxDir();
    Log.v(TAG, "ABOUT TO CREATE SETUP");
    if (sphinxDir != null) {
        try {

            Log.v(TAG, "SETTING UP! :)");
            mSpeechRecognizer = defaultSetup()
                    .setAcousticModel(new File(sphinxDir, "en-us-ptm"))
                    .setDictionary(new File(sphinxDir, "hello.dict"))
                    .setBoolean("-allphone_ci", true) //WHAT IS THIS
                    .getRecognizer();
            mSpeechRecognizer.addListener(this);

            Log.v(TAG, "ADDED LISTENER");

            if ((new File(sphinxDir + File.separator + "command.gram")).isFile()) {
                mSpeechRecognizer.addKeywordSearch("hello",
                        new File(sphinxDir + File.separator + "command.gram"));

                Log.v(TAG, "ADDED KEYWORD SEARCH! :)");
            }

            // Or wherever appropriate
            mSpeechRecognizer.startListening("wakeup"); //Is this correct?
            Log.v(TAG, "STARTED LISTENING");

        } catch (IOException e) {

            Log.v("ERROR", TAG);

        }
    }
}


String createSphinxDir() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String sphinxDir = prefs.getString("sphinx", null);
    if (sphinxDir == null) {
        Assets assets;
        Log.v(TAG, "Assets are not synced, should sync now:");
        try {
            Log.v(TAG, "In try block!");
            assets = new Assets(this);
            File sphinxDirFile = assets.syncAssets();
            Log.v(TAG, "Syncing assets...should set up listener");
            if (sphinxDirFile != null) {
                sphinxDir = sphinxDirFile.getAbsolutePath();
                SharedPreferences.Editor editor = prefs.edit();
                editor.putString("sphinx", sphinxDir);
                editor.commit();
                Log.v(TAG, "Set up listener");

            }else{
                Log.v(TAG, "sphinxDirFile is null!");
            }
        } catch (IOException e) { //THIS IS THE PLACE WHERE I AM GETTING THE ERROR!
            e.printStackTrace();
            Log.d(TAG, e.toString());
        }
    }
    return sphinxDir;
}

I also have all the call back methods (onPartialResult, onResult, etc.) but they never get called.

Earlier I was getting an exception saying the variances .md5 file didn't exist, so I put a space in between the variances and the .md5, but now I am getting this error, and I don't know why...

Please let me know,

Ruchir

解决方案

Earlier I was getting an exception saying the variances .md5 file didn't exist, so I put a space in between the variances and the .md5, but now I am getting this error, and I don't know why...

You should not do such things, it causes problems, instead you need to follow the documentation:

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.

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 during the build.

To integrate assets sync in your application do the following

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

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

这篇关于文件未发现异常? (语音识别测试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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