【问题标题】:Having <s> and </s> as an output from android pocketsphinx将 <s> 和 </s> 作为 android pocketsphinx 的输出
【发布时间】:2016-10-17 08:34:56
【问题描述】:

我们正在使用 pocketsphinx 来帮助我们将 .wav 文件转换为文本文件。我们不知道为什么它会给我们一个奇怪的输出,因为它在转换后只给我们&lt;s&gt; 和&lt;/s&gt;。我们使用 cmusphinx 社区提供的默认字典、语言模型和声学模型。

这是我们用于转换的代码:

package com.example.saling_wika.saling_wika;


import android.app.Activity;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.Toast;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import edu.cmu.pocketsphinx.Assets;
import edu.cmu.pocketsphinx.Config;
import edu.cmu.pocketsphinx.Decoder;
import edu.cmu.pocketsphinx.Segment;

import static android.support.v7.widget.StaggeredGridLayoutManager.TAG;
import static junit.framework.Assert.fail;





public class ConversionModule extends Activity {
    static {
        System.loadLibrary("pocketsphinx_jni");
    }
    Config c;
    Decoder ps;
    FileInputStream stream;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        setContentView(R.layout.main);

        c = Decoder.defaultConfig();

    /*Configuring decoder object*/
        c.setString("-hmm", new File(Environment.getExternalStorageDirectory() + "/Android/data/com.example.saling_wika.saling_wika/files/sync", "en-us-ptm").getPath());
        c.setString("-dict", new File(Environment.getExternalStorageDirectory() + "/Android/data/com.example.saling_wika.saling_wika/files/sync", "cmudict-en-us.dict").getPath());
        c.setString("-lm", new File(Environment.getExternalStorageDirectory() + "/Android/data/com.example.saling_wika.saling_wika/files/sync", "weather.dmp").getPath());
        c.setBoolean("-allphone_ci", true);


        ps = new Decoder(c);


        try {
            final File file = new File(AudioToConvert.pathko);
            Uri uri = Uri.fromFile(file);
            File auxFile = new File(uri.getPath());
            stream = new FileInputStream(auxFile);


        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




        ps.startUtt();
        byte[] b = new byte[4096];
        try {
            int nbytes;
            while ((nbytes = stream.read(b)) >= 0) {
                ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes);
                short[] s = new short[nbytes / 2];
                bb.asShortBuffer().get(s);
                ps.processRaw(s, nbytes / 2, false, false);
            }
        } catch (IOException e) {

        }
        ps.endUtt();
        //  System.out.println(ps.hyp().getHypstr());
        Toast.makeText(getApplicationContext(), ps.hyp().getHypstr(), Toast.LENGTH_LONG).show();
        for (Segment seg : ps.seg()) {
            //  System.out.println(seg.getWord());
            Toast.makeText(getApplicationContext(),seg.getWord(), Toast.LENGTH_LONG).show();
        }
        ;


    }
}

【问题讨论】:

    标签: android speech-recognition speech pocketsphinx pocketsphinx-android


    【解决方案1】:

    正如CMUSphinx forum 中所述,您有多个问题:

    1. 您需要按照Give a file as input to Pocketsphinx on Android中的说明添加bb.order(ByteOrder.LITTLE_ENDIAN);

    2. 您的输入文件应具有 PCM 格式 16khz 16 位单声道。如果您想提交一些编码文件,您需要先将其解码为原始数据。

    【讨论】:

    • 您好,我使用了这里给出的答案:stackoverflow.com/a/37640851/1693203,我也遇到了同样的问题。我有一个 11 秒的 wav 文件,母语为英语的人说了一个短句。该文件为 16 位、小端序、16 kHz,并且我已删除 wav 标头,因此该文件只有原始音频部分。我得到结果 [speech] [speech] [speech] 。你能给我一些关于如何解决这个问题的提示吗?
    • 顺便说一句,如果我使用保留 wav 标头的文件,我会得到相同的结果
    猜你喜欢
    • 2015-02-15
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 2019-08-22
    • 2013-02-23
    • 1970-01-01
    • 2011-02-17
    • 1970-01-01
    相关资源
    最近更新 更多