亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用PocketSphinx識別多個關鍵字

使用PocketSphinx識別多個關鍵字

慕碼人8056858 2019-11-03 13:04:01
我已經安裝了PocketSphinx演示程序,并且在Ubuntu和Eclipse下運行良好,但是盡管嘗試了一下,但仍無法弄清楚如何添加多個單詞的識別。我只想讓代碼識別單個單詞,然后我就可以在代碼中識別它們switch(),例如“上”,“下”,“左”,“右”。我不想識別句子,只能識別單個單詞。任何幫助,將不勝感激。我發現其他用戶也有類似的問題,但到目前為止,沒人知道答案。讓我感到困惑的一件事是,為什么我們根本需要使用“喚醒”常量?private static final String KWS_SEARCH = "wakeup";private static final String KEYPHRASE = "oh mighty computer";...recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);有wakeup什么關系嗎?我已經取得了一些進步(?):使用,addGrammarSearch我可以使用.gram文件列出我的單詞,例如up,down,left,right,forwards,backwards,如果我只說那些特定的單詞,這似乎很好用。但是,任何其他字詞都將導致系統將所陳述的內容與“最近”字詞進行匹配。理想情況下,如果.gram文件中沒有說出的單詞,我不希望被識別...
查看完整描述

3 回答

?
慕妹3146593

TA貢獻1820條經驗 獲得超9個贊

您可以使用addKeywordSearch哪個用于歸檔密鑰短語。每行一個短語,例如//中的每個短語都有閾值


up /1.0/

down /1.0/

left /1.0/

right /1.0/

forwards /1e-1/

必須選擇閾值以避免錯誤警報。



查看完整回答
反對 回復 2019-11-04
?
牛魔王的故事

TA貢獻1830條經驗 獲得超3個贊

正在為PocketSphinx演示更新Antinous修訂,以使其能夠在Android Studio上運行。這就是我到目前為止


//Note: change MainActivity to PocketSphinxActivity for demo use...

public class MainActivity extends Activity implements RecognitionListener {

private static final String DIGITS_SEARCH = "digits";

private SpeechRecognizer recognizer;


/* Used to handle permission request */

private static final int PERMISSIONS_REQUEST_RECORD_AUDIO = 1;


@Override

public void onCreate(Bundle state) {

    super.onCreate(state);


    setContentView(R.layout.main);

    ((TextView) findViewById(R.id.caption_text))

            .setText("Preparing the recognizer");


    // Check if user has given permission to record audio

    int permissionCheck = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECORD_AUDIO);

    if (permissionCheck != PackageManager.PERMISSION_GRANTED) {

        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, PERMISSIONS_REQUEST_RECORD_AUDIO);

        return;

    }


    new AsyncTask<Void, Void, Exception>() {

        @Override

        protected Exception doInBackground(Void... params) {

            try {

                Assets assets = new Assets(MainActivity.this);

                File assetDir = assets.syncAssets();

                setupRecognizer(assetDir);

            } catch (IOException e) {

                return e;

            }

            return null;

        }

        @Override

        protected void onPostExecute(Exception result) {

            if (result != null) {

                ((TextView) findViewById(R.id.caption_text))

                        .setText("Failed to init recognizer " + result);

            } else {

                reset();

            }

        }

    }.execute();

    ((TextView) findViewById(R.id.caption_text)).setText("Say one, two, three, four, five, six...");

}


/**

 * In partial result we get quick updates about current hypothesis. In

 * keyword spotting mode we can react here, in other modes we need to wait

 * for final result in onResult.

 */


@Override

public void onPartialResult(Hypothesis hypothesis) {

    if (hypothesis == null) {

        return;

    } else if (hypothesis != null) {

        if (recognizer != null) {

            //recognizer.rapidSphinxPartialResult(hypothesis.getHypstr());

            String text = hypothesis.getHypstr();

            if (text.equals(DIGITS_SEARCH)) {

                recognizer.cancel();

                performAction();

                recognizer.startListening(DIGITS_SEARCH);

            }else{

                //Toast.makeText(getApplicationContext(),"Partial result = " +text,Toast.LENGTH_SHORT).show();

            }

        }

    }

}

@Override

public void onResult(Hypothesis hypothesis) {

    ((TextView) findViewById(R.id.result_text)).setText("");

    if (hypothesis != null) {

        String text = hypothesis.getHypstr();

        makeText(getApplicationContext(), "Hypothesis" +text, Toast.LENGTH_SHORT).show();

    }else if(hypothesis == null){

        makeText(getApplicationContext(), "hypothesis = null", Toast.LENGTH_SHORT).show();

    }

}

@Override

public void onDestroy() {

    super.onDestroy();

    recognizer.cancel();

    recognizer.shutdown();

}

@Override

public void onBeginningOfSpeech() {

}

@Override

public void onEndOfSpeech() {

   reset();

}

@Override

public void onTimeout() {

}

private void setupRecognizer(File assetsDir) throws IOException {

    // The recognizer can be configured to perform multiple searches

    // of different kind and switch between them

    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);


    File digitsGrammar = new File(assetsDir, "digits.gram");

    recognizer.addKeywordSearch(DIGITS_SEARCH, digitsGrammar);

}

private void reset(){

    recognizer.stop();

    recognizer.startListening(DIGITS_SEARCH);

}

@Override

public void onError(Exception error) {

    ((TextView) findViewById(R.id.caption_text)).setText(error.getMessage());

}


public void performAction() {

    // do here whatever you want

    makeText(getApplicationContext(), "performAction done... ", Toast.LENGTH_SHORT).show();

}

}

請注意:此工作正在進行中。過一會再來檢查。建議將不勝感激。



查看完整回答
反對 回復 2019-11-04
  • 3 回答
  • 0 關注
  • 400 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號