Menu

WSJ_8gau_13dCep_16k_40mel_130Hz_6800Hz -Not found when adding it to library in netbeans

Kavya
2016-02-25
2016-03-07
  • Kavya

    Kavya - 2016-02-25

    Hi,
    Since I wanted to add some more words to dictionary I unzipped the above file and added to accoustic model and again coverted it to zip file. But now when I ried adding this zip folder to my netbeans project the above file was missing although it is present. Why is this? And how to make it work.
    Thanks

     
    • Nickolay V. Shmyrev

      Make sure you are using sphinx4 version and do not use WSJ model, there are much more accurate models available.

       
      • Kavya

        Kavya - 2016-02-25

        I'm using sphinx4 version only. Which model should I use?

         
  • Mangesh Mukund Panchwagh

    Have done with the sample demo example of pocketsphinx.
    I want to add button click event instead of specking 'oh mighty computer' in the example given in the pocketsphinx.I am trying it from last week but not able to get it. can you tell me how can i achieve it. Not gtting the exact pinch where I should add button click event.?
    Thank you.

     
  • Mangesh Mukund Panchwagh

    hey I am getting this exception while adding the button click event to pocketsphinx-android-demo.
    Thanks

     
    • Nickolay V. Shmyrev

      You modified something incorrectly, you need to provide your modifications in order to get help on this issue.

       
  • Mangesh Mukund Panchwagh

    The modified Code is:
    Have just given some comments:
    package edu.cmu.pocketsphinx.demo;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.TextView;
    import android.widget.Toast;

    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;

    import edu.cmu.pocketsphinx.Assets;
    import edu.cmu.pocketsphinx.Hypothesis;
    import edu.cmu.pocketsphinx.RecognitionListener;
    import edu.cmu.pocketsphinx.SpeechRecognizer;

    import static android.widget.Toast.makeText;
    import static edu.cmu.pocketsphinx.SpeechRecognizerSetup.defaultSetup;

    public class PocketSphinxActivity extends Activity implements
    RecognitionListener {

    /* Named searches allow to quickly reconfigure the decoder */
    private static final String KWS_SEARCH = "wakeup";
    private static final String FORECAST_SEARCH = "forecast";
    private static final String DIGITS_SEARCH = "digits";
    private static final String PHONE_SEARCH = "phones";
    private static final String MENU_SEARCH = "menu";
    
    /* Keyword we are looking for to activate menu */
    **private static final String KEYPHRASE = "up down left right";**
    
    private SpeechRecognizer recognizer;
    private HashMap<String, Integer> captions;
    
    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
    
        // Prepare the data for UI
        captions = new HashMap<String, Integer>();
        captions.put(KWS_SEARCH, R.string.kws_caption);
        captions.put(MENU_SEARCH, R.string.menu_caption);
        captions.put(DIGITS_SEARCH, R.string.digits_caption);
        captions.put(PHONE_SEARCH, R.string.phone_caption);
        captions.put(FORECAST_SEARCH, R.string.forecast_caption);
        setContentView(R.layout.main);
        //((TextView) findViewById(R.id.caption_text)).setText("START SPEAKING ");
    
        // Recognizer initialization is a time-consuming and it involves IO,
        // so we execute it in async task
    
        new AsyncTask<Void, Void, Exception>() {
            @Override
            protected Exception doInBackground(Void... params) {
                try {
                    Assets assets = new Assets(PocketSphinxActivity.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 {
                    switchSearch(KWS_SEARCH);
                }
            }
        }.execute();
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        recognizer.cancel();
        recognizer.shutdown();
    }
    
    /**
    
     * 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) {
        ((TextView) findViewById(R.id.result_text)).setText("");
        if (hypothesis != null) {
            String text = hypothesis.getHypstr();
            makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
        }
    }
    
    /**
    
     * This callback is called when we stop the recognizer.
     */
    @Override
    public void onResult(Hypothesis hypothesis) {
        ((TextView) findViewById(R.id.result_text)).setText("");
        if (hypothesis != null) {
            String text = hypothesis.getHypstr();
            makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
        }
    }
    
    
    @Override
    public void onBeginningOfSpeech() {
    
    }
    
    /**
    
     * We stop recognizer here to get a final result
     */
    @Override
    public void onEndOfSpeech() {
        if (!recognizer.getSearchName().equals(KWS_SEARCH))
            switchSearch(KWS_SEARCH);
    }
    
    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, 1000);
    
        String caption = getResources().getString(captions.get(searchName));
        ((TextView) findViewById(R.id.caption_text)).setText(caption);
    }
    
    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"))
    
                // To disable logging of raw audio comment out this call (takes a lot of space on the device)
                .setRawLogDir(assetsDir)
    
                // Threshold to tune for keyphrase to balance between false alarms and misses
                .setKeywordThreshold(1e-45f)
    
                // Use context-independent phonetic search, context-dependent is too slow for mobile
                .setBoolean("-allphone_ci", true)
    
                .getRecognizer();
        recognizer.addListener(this);
    
        /** In your application you might not need to add all those searches.
    
         * They are added here for demonstration. You can leave just one.
         */
    
        // Create keyword-activation search.
        recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
    
        // Create grammar-based search for selection between demos
    
    
        // Create language model search
        File languageModel = new File(assetsDir, "weather.dmp");
        recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);
    
        // Phonetic search
        File phoneticModel = new File(assetsDir, "en-phone.dmp");
        recognizer.addAllphoneSearch(PHONE_SEARCH, phoneticModel);
    }
    
    @Override
    public void onError(Exception error) {
        ((TextView) findViewById(R.id.caption_text)).setText(error.getMessage());
    }
    
    @Override
    public void onTimeout() {
        switchSearch(KWS_SEARCH);
    }
    

    public void playAudio(View view) {
    Intent objIntent = new Intent(this, PlayAudio.class);
    startService(objIntent);
    }

    public void stopAudio(View view) {
        Intent objIntent = new Intent(this, PlayAudio.class);
        stopService(objIntent);
    }
    

    }

    1) If I use the Bold line as:
    private static final String KEYPHRASE = "up down left right";
    it keep on showing the text up down left right, multiple times..
    or didnt recognise any other sentenses or words.
    but
    If I use the Bold line as:
    private static final String KEYPHRASE = " ";
    it keeps on its keeps on poping up empty text bar:

    2) What I want is just it should recognise whatever I speak.can you give suggesions so I can continue. with

    what should I do
    please give any solution.
    Thank you.

     

    Last edit: Mangesh Mukund Panchwagh 2016-03-04
    • Nickolay V. Shmyrev

      First format your question properly.

       
  • Mangesh Mukund Panchwagh

    package edu.cmu.pocketsphinx.demo;

    import android.app.Activity;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.widget.TextView;
    import android.widget.Toast;

    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;

    import edu.cmu.pocketsphinx.Assets;
    import edu.cmu.pocketsphinx.Hypothesis;
    import edu.cmu.pocketsphinx.RecognitionListener;
    import edu.cmu.pocketsphinx.SpeechRecognizer;

    import static android.widget.Toast.makeText;
    import static edu.cmu.pocketsphinx.SpeechRecognizerSetup.defaultSetup;

    public class PocketSphinxActivity extends Activity implements
    RecognitionListener {

    /* Named searches allow to quickly reconfigure the decoder */
    private static final String KWS_SEARCH = "wakeup";
    private static final String FORECAST_SEARCH = "forecast";
    private static final String DIGITS_SEARCH = "digits";
    private static final String PHONE_SEARCH = "phones";
    private static final String MENU_SEARCH = "menu";
    
    /* Keyword we are looking for to activate menu */
    private static final String KEYPHRASE = " ";
    
    private SpeechRecognizer recognizer;
    private HashMap<String, Integer> captions;
    
    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
    
        // Prepare the data for UI
        captions = new HashMap<String, Integer>();
        captions.put(KWS_SEARCH, R.string.kws_caption);
        captions.put(MENU_SEARCH, R.string.menu_caption);
        captions.put(DIGITS_SEARCH, R.string.digits_caption);
        captions.put(PHONE_SEARCH, R.string.phone_caption);
        captions.put(FORECAST_SEARCH, R.string.forecast_caption);
        setContentView(R.layout.main);
        //((TextView) findViewById(R.id.caption_text)).setText("START SPEAKING ");
    
        // Recognizer initialization is a time-consuming and it involves IO,
        // so we execute it in async task
    
        new AsyncTask<Void, Void, Exception>() {
            @Override
            protected Exception doInBackground(Void... params) {
                try {
                    Assets assets = new Assets(PocketSphinxActivity.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 {
                    switchSearch(KWS_SEARCH);
                }
            }
        }.execute();
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        recognizer.cancel();
        recognizer.shutdown();
    }
    
    /**
    
     * 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) {
        ((TextView) findViewById(R.id.result_text)).setText("");
        if (hypothesis != null) {
            String text = hypothesis.getHypstr();
            makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
        }
    }
    
    /**
    
     * This callback is called when we stop the recognizer.
     */
    @Override
    public void onResult(Hypothesis hypothesis) {
        ((TextView) findViewById(R.id.result_text)).setText("");
        if (hypothesis != null) {
            String text = hypothesis.getHypstr();
            makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
        }
    }
    
    
    @Override
    public void onBeginningOfSpeech() {
    
    }
    
    /**
    
     * We stop recognizer here to get a final result
     */
    @Override
    public void onEndOfSpeech() {
        if (!recognizer.getSearchName().equals(KWS_SEARCH))
            switchSearch(KWS_SEARCH);
    }
    
    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, 1000);
    
        String caption = getResources().getString(captions.get(searchName));
        ((TextView) findViewById(R.id.caption_text)).setText(caption);
    }
    
    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"))
    
                // To disable logging of raw audio comment out this call (takes a lot of space on the device)
                .setRawLogDir(assetsDir)
    
                // Threshold to tune for keyphrase to balance between false alarms and misses
                .setKeywordThreshold(1e-45f)
    
                // Use context-independent phonetic search, context-dependent is too slow for mobile
                .setBoolean("-allphone_ci", true)
    
                .getRecognizer();
        recognizer.addListener(this);
    
        /** In your application you might not need to add all those searches.
    
         * They are added here for demonstration. You can leave just one.
         */
    
        // Create keyword-activation search.
        recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
    
        // Create grammar-based search for selection between demos
       File menuGrammar = new File(assetsDir, "menu.gram");
        recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
    
        // Create grammar-based search for digit recognition
        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);
    
        // Phonetic search
        File phoneticModel = new File(assetsDir, "en-phone.dmp");
        recognizer.addAllphoneSearch(PHONE_SEARCH, phoneticModel);
    }
    
    @Override
    public void onError(Exception error) {
        ((TextView) findViewById(R.id.caption_text)).setText(error.getMessage());
    }
    
    @Override
    public void onTimeout() {
        switchSearch(KWS_SEARCH);
    }
    

    }

    1) This is how I modified the code as above.
    for the following line in the code as
    private static final String KEYPHRASE = " ";
    the output is:
    whatever I speak giving nothing in the KEYPHRASE ,It just giving the tab having no any text on it.And keep on poping that tab with blank texts.

    2)And when I write the line in the code as
    private static final String KEYPHRASE = " up down left right";
    the output is:
    It keep on displaying up down left right with infinite loop.

    3)And if change the sentense(up down left right to how are you) it crashes the app.
    I want that whatever I speak It should identify and displays its text on the screen.
    Thank you

     

Log in to post a comment.

MongoDB Logo MongoDB