コード例 #1
0
  public void onDestroy() {
    super.onDestroy();

    Utilities.setDirectionImage("STOP", ivDirection, bt);
    bt.stop();

    recognizer.cancel();
    recognizer.shutdown();
  }
コード例 #2
0
ファイル: MainActivity.java プロジェクト: phreakradio/iSwear
  /**
   * Function stops recognizer and switches textview UI
   *
   * @param searchName
   */
  private void switchSearch(String searchName) {
    recognizer.stop();

    // If we are not spotting, start listening with timeout (10000 ms or 10 seconds).
    if (searchName.equals(KWS_SEARCH)) recognizer.startListening(searchName);
    else recognizer.startListening(searchName, 10000);

    String caption = getResources().getString(captions.get(searchName));
    ((TextView) findViewById(R.id.caption_text)).setText(caption);
  }
コード例 #3
0
  private void startListeningSphinx(String searchName) {
    recognizer.stop();

    // If we are not spotting, start listening with timeout (10000 ms or 10 seconds).
    if (searchName.equals(KWS_SEARCH)) recognizer.startListening(searchName);
    /*   else
    // recognizer.startListening(searchName);
    recognizer.startListening(searchName, 10000);*/

    // String caption = getResources().getString(searchName);
    ((TextView) findViewById(R.id.user_help)).setText(R.string.robot_move);
  }
コード例 #4
0
  @Override
  public void onEndOfSpeech() {

    showSnackbar("End of speech Sphinx", Snackbar.LENGTH_LONG);

    try {
      if (!recognizer.getSearchName().equals(KWS_SEARCH)) startListeningSphinx(KWS_SEARCH);
    } catch (Exception r) {
      r.printStackTrace();
    }
    progressBar.setIndeterminate(true);
  }
コード例 #5
0
  private void setupRecognizer(File assetsDir) {
    try {
      recognizer =
          defaultSetup()
              .setAcousticModel(new File(assetsDir, "en-us-ptm"))
              .setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
              // .setRawLogDir(assetsDir) // To disable logging of raw audio comment out this call
              // (takes a lot of space on the device)
              .setKeywordThreshold(
                  1e-45f) // Threshold to tune for keyphrase to balance between false alarms and
              // misses
              .setBoolean("-allphone_ci", true)
              .getRecognizer();
      recognizer.addListener(this);

      // Create keyword-activation search.
      recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #6
0
  @Override
  public void onPartialResult(Hypothesis hypothesis) { // / change recogniser Sphinx -> Android

    if (hypothesis == null) return;

    String text = hypothesis.getHypstr();
    if (text.equals(KEYPHRASE)) {
      progressBar.setVisibility(View.VISIBLE);
      progressBar.setIndeterminate(true);
      recognizer.cancel(); // cancel Sphinx speech recognizer
      speech.startListening(recognizerIntent); // start android speech recognizer
      ((TextView) findViewById(R.id.user_help)).setText(R.string.speech_prompt);
    }
  }
コード例 #7
0
ファイル: MainActivity.java プロジェクト: phreakradio/iSwear
  /**
   * The recognizer can be configured to perform multiple searches of different kind and switch
   * between them.
   *
   * <p>THE HEART OF THE APP!
   *
   * @param assetsDir
   * @throws IOException
   */
  private void setupRecognizer(File assetsDir) throws IOException {
    recognizer =
        defaultSetup()
            .setAcousticModel(new File(assetsDir, "en-us-ptm")) // Acoustic model
            .setDictionary(
                new File(
                    assetsDir, "cmudict-en-us.dict")) // English dictionary of most common words
            .setRawLogDir(
                assetsDir) // To disable logging of raw audio comment out this call (takes a lot of
                           // space on the device)
            .setKeywordThreshold(
                1e-15f) // Threshold to tune for keyphrase to balance between false alarms and
                        // misses
            //                .setBoolean("-allphone_ci", true)                           // Use
            // context-independent phonetic search, context-dependent is too slow for mobile
            .getRecognizer();
    recognizer.addListener(this);

    // Create keyword-activation search.
    recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);

    File animalGrammar = new File(assetsDir, "animals.gram");
    recognizer.addKeywordSearch("animals", animalGrammar);
  }
コード例 #8
0
  @Override
  protected void onPause() {
    super.onPause();
    if (textToSpeech != null) {
      textToSpeech.stop();
      textToSpeech.shutdown();
    }
    Utilities.setDirectionImage("STOP", ivDirection, bt);
    bt.stop();
    recognizer.cancel();
    // finish();

    if (speech != null) {
      speech.destroy();
    }
  }
コード例 #9
0
ファイル: MainActivity.java プロジェクト: phreakradio/iSwear
  /** We stop recognizer here to get a final result */
  @Override
  public void onEndOfSpeech() {
    Log.i(LOG_TAG, "Updating count");
    ((TextView) findViewById(R.id.result_text))
        .setText(
            "cat: "
                + wordCount.get("cat")
                + "\n"
                + "dog: "
                + wordCount.get("dog")
                + "\n"
                + "rat: "
                + wordCount.get("rat"));

    //        String temp_text = recognizer.getSearchName();
    //
    if (!recognizer.getSearchName().equals(KWS_SEARCH)) switchSearch(ANIMAL_SEARCH);
  }
コード例 #10
0
ファイル: MainActivity.java プロジェクト: phreakradio/iSwear
 @Override
 public void onDestroy() {
   super.onDestroy();
   recognizer.cancel();
   recognizer.shutdown();
 }