EzDevInfo.com

pocketsphinx.js

Speech recognition in JavaScript

Setting up CMUSphinx/PocketSphinx on Windows 7

I have been trying this for hours now, but cannot seem to get this right. I am trying to download Pocketsphinx for use of command recognition in Python.

So first thing I did was attempt to install SphinxBase, which is required for Pocketsphinx to work. So here we go. I downloaded the files, the tar.gz zip. I followed the instructions in the README document in order to install on windows.

To compile sphinxbase in Visual Studio 2010 Express (or newer):
1, unzip the file.
2, rename the directory to sphinxbase
3, go into the sphinxbase folder and click sphinxbase.sln
4, in the menu, choose Build -> Rebuild All -> Batch Build -> Build

I have never used visual before, but it seemed pretty self explanatory. First thing I did was unzip and rename. Next up I opened the SLN project in visual, selected all 6 projects, the Files>Build Selection. It build with all 6 projects succeeding. Great, that's done. Now was that really all? I had to do?

Next up was PocketSphinx. I downloaded the tar.gz again, and basically did the same process.

 * load pocketsphinx.sln in pocketsphinx directory
 * compile all the projects in PocketSphinx

All builds succeeded in being built. So... done, right? After this, I am lost. Most tutorials stop here and do not actually go into using Pocketsphinx in other languages. I need to be able to use it in Python.

So I did some digging around and found a setup_win32.py file under pocketsphinx/python. I tried to run this in the command prompt but go multiple errors. Now I am running windows 64 bit, but could this cause this issue? http://hastebin.com/japobecusi.tex

So all in all, I just need help getting this to work with Python. I am very inexperienced in these things currently. Thanks

One more thing, I am considering switching to my Ubuntu Linux partition in order to almost make it easier on myself. Most programs, including this one, seem to only use windows 32, like 64 is unacceptable apparently. So would it benefit me to move over to a Linux platform to work in Python? Would it be easier?

Thanks for any help in advance.


Source: (StackOverflow)

Error while Loading CMU sphinx in visual studio 2013

I am trying to load CMU sphinx in visual studio 2013 but getting some error. The steps which i followed was

I downloaded sphinxbase-5prealpha and pocketsphinx-5prealpha and extracted to same folder.

Then i complied all the projects from both pocketsphinx and sphinxbase in visual studio(it asked me to upgrade the compliers so i did the upgrade)

now after cleaning the project, when i am trying to build all the project it is throwing a error that 'cannot open sphinxbase.lib' which it is showing in pocketsphinx project.

when i checked the 'sphinxbase.lib' file was already there in the linker of the project.

enter image description here

According to this document the 'sphinxbase.dll' file should be added to the bin files, but it is already added in the directory bot release and debug.

enter image description here

Similarly it is present in debug directory also.

Please help me, can anybody tell me what wrong i am doing here??

I am just a beginner only in this area.

Thanks !


Source: (StackOverflow)

Advertisements

Call a "void" method that have values from another activity

Hi I'm quite new to Java, I wonder how to call a void method from another activity, when I already moved to new activity. For example, I want to call

onCreate(Bundle state)

from PocketSphinxActivty.java in my new activity SMSReaderMain.java

I already tried

PocketSphinxActivity ps = new PocketSphinxActivity();
ps.onCreate(null);

It gives no error, but when SMSReaderMain.java activity start it suddenly force close and not responding in the actual device.

I also try to change into ps.onCreate(this) or ps.onCreate(SMSReaderMain.this) but it gives

The method setupRecognizer(File) in the type PocketSphinxActivity is not applicable for the arguments (SMSReaderMain)

Here's the complete code, and I want to call almost all of method there in my new activity SMSReaderMain.java

PocketSphinxActivity.java

package edu.cmu.pocketsphinx.demo;

public class PocketSphinxActivity extends Activity implements
    RecognitionListener {

//keyword yang digunakan dalem program untuk set ke even2 tertentu
private static final String KWS_SEARCH = "wakeup";
private static final String FORECAST_SEARCH = "forecast";
private static final String DIGITS_SEARCH = "drive mode";
private static final String MENU_SEARCH = "menu";
private static final String KEYPHRASE = "ok";

private SpeechRecognizer recognizer;
private HashMap<String, Integer> captions;



@Override
public void onCreate(Bundle state) {
    super.onCreate(state);

    // Buat nyiapin User Interface
    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(FORECAST_SEARCH, R.string.forecast_caption);
    setContentView(R.layout.main);
    ((TextView) findViewById(R.id.caption_text))
            .setText("Preparing the recognizer");

    // 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();
}

//nyocokin keyword dan pindah2 menu
@Override
public void onPartialResult(Hypothesis hypothesis) {
    String text = hypothesis.getHypstr();
    try {
    Intent i= null;
    if (text.equals(KEYPHRASE)) {
        switchSearch(MENU_SEARCH);
    }
    if (text.equals(DIGITS_SEARCH)) {
        //panggil class SMSReaderMain
        recognizer.stop();
        i = new Intent(getApplicationContext(),SMSReaderMain.class);
        startActivity(i);
    }
    if (text.equals(FORECAST_SEARCH)) {
        switchSearch(FORECAST_SEARCH);
    }
   //else
        //((TextView) findViewById(R.id.result_text)).setText(text);
} catch (Exception e) {
    e.printStackTrace();
}
}

//nge pop up keyword yang sesuai kita ucapin sama library yg udah ada 
@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() {
}

//kembali ke menu utama
/*@Override
public void onEndOfSpeech() {
    if (DIGITS_SEARCH.equals(recognizer.getSearchName())
            || FORECAST_SEARCH.equals(recognizer.getSearchName()))
        switchSearch(KWS_SEARCH);
}**/

//nampilin caption yg di mau sesuai dengan keyword
public void switchSearch(String searchName) {
    recognizer.stop();
    recognizer.startListening(searchName);
    String caption = getResources().getString(captions.get(searchName));
    ((TextView) findViewById(R.id.caption_text)).setText(caption);
}

//inisiasi recognizer di awal
public void setupRecognizer(File assetsDir) {
    File modelsDir = new File(assetsDir, "models");
    recognizer = defaultSetup()
            .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
            .setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
            .setRawLogDir(assetsDir).setKeywordThreshold(1e-20f)
            .getRecognizer();
    recognizer.addListener(this);

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

    // Create grammar-based searches.
    File menuGrammar = new File(modelsDir, "grammar/mulai.gram");
    recognizer.addGrammarSearch(MENU_SEARCH, menuGrammar);
    //File digitsGrammar = new File(modelsDir, "grammar/digits.gram");
    //recognizer.addGrammarSearch(DIGITS_SEARCH, digitsGrammar);

    // Create language model search.
    File languageModel = new File(modelsDir, "lm/weather.dmp");
    recognizer.addNgramSearch(FORECAST_SEARCH, languageModel);
}

@Override
public void onEndOfSpeech() {
    // TODO Auto-generated method stub

}
}

SMSReaderMAin.java

public class SMSReaderMain extends Activity {   

private final int CHECK_CODE = 0x1; 
private final int LONG_DURATION = 5000;
private final int SHORT_DURATION = 1200;

private Speaker speaker;    

private ToggleButton toggle;
private OnCheckedChangeListener toggleListener;

private TextView smsText;
private TextView smsSender; 
private BroadcastReceiver smsReceiver;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //PocketSphinxActivity ps = new PocketSphinxActivity();
    //ps.setupRecognizer(null);
    //ps.onPartialResult(null);
    //ps.onResult(null);
    //ps.switchSearch(null);

    setContentView(R.layout.main_sms);          

    //recognizer.startListening(searchName);

    toggle = (ToggleButton)findViewById(R.id.speechToggle);
    smsText = (TextView)findViewById(R.id.sms_text);
    smsSender = (TextView)findViewById(R.id.sms_sender);

    toggleListener = new OnCheckedChangeListener() {            
        @Override
        public void onCheckedChanged(CompoundButton view, boolean isChecked) {
            if(isChecked){
                speaker.allow(true);
                speaker.speak(getString(R.string.start_speaking));
            }else{
                speaker.speak(getString(R.string.stop_speaking));
                speaker.allow(false);                   
            }
        }
    };      
    toggle.setOnCheckedChangeListener(toggleListener);

    checkTTS();
    initializeSMSReceiver();
    registerSMSReceiver();
}   

private void checkTTS(){
    Intent check = new Intent();
    check.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
    startActivityForResult(check, CHECK_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode == CHECK_CODE){
        if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
            speaker = new Speaker(this);
        }else {
            Intent install = new Intent();
            install.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(install);
        }
    }
}

private void initializeSMSReceiver(){
    smsReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context context, Intent intent) {

            Bundle bundle = intent.getExtras();
            if(bundle!=null){
                Object[] pdus = (Object[])bundle.get("pdus");
                for(int i=0;i<pdus.length;i++){
                    byte[] pdu = (byte[])pdus[i];
                    SmsMessage message = SmsMessage.createFromPdu(pdu);
                    String text = message.getDisplayMessageBody();
                    String sender = getContactName(message.getOriginatingAddress());
                    speaker.pause(LONG_DURATION);
                    speaker.speak("You have a new message from" + sender + "!");
                    speaker.pause(SHORT_DURATION);
                    speaker.speak(text);
                    smsSender.setText("Message from " + sender);
                    smsText.setText(text);
                }
            }

        }           
    };      
}

private void registerSMSReceiver() {    
    IntentFilter intentFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(smsReceiver, intentFilter);
}

private String getContactName(String phone){
    Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phone));
    String projection[] = new String[]{ContactsContract.Data.DISPLAY_NAME};
    Cursor cursor = getContentResolver().query(uri, projection, null, null, null);              
    if(cursor.moveToFirst()){
        return cursor.getString(0);
    }else {
        return "unknown number";
    }
}

@Override
protected void onDestroy() {    
    super.onDestroy();
    unregisterReceiver(smsReceiver);
    speaker.destroy();
 }

}

Source: (StackOverflow)

Installing Pocketsphinx/Sphinxbase in OSX for use in XCode 6

I'm trying to use Pocketsphinx/Sphinxbase in an OSX OpenframeWorks application. I have cloned both

https://github.com/cmusphinx/pocketsphinx and https://github.com/cmusphinx/sphinxbase

And configured/installed them as per the instructions on the readme's. However I'm struggling on how to include them in XCode.

Has anyone attempted this?


Source: (StackOverflow)

Handling Errors in PocketSphinx Android app

I am using the default dictionary that comes with the pocketsphinx demo which is good for my purposes. When a user enters a phrase, the app starts a keyphrase listening but if the word is not found in the dictionary the app crashes. The app crashes onError() within a service. How is the error handling done? is there any way I can catch the error? Overall I would just like the service to call stopSelf() when an error happens so the main activity won't crash as well.

Errors:

ERROR: "kws_search.c", line 165: The word 'phonez' is missing in the dictionary

Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 5389 (1994.wherephone)

Here is my service class:

 public class WherePhoneService extends Service implements RecognitionListener {

private static String SettingStorage = "SavedData";
SharedPreferences settingData;

private SpeechRecognizer recognizer;

private String sInput;
private String sOutput;

private int seekVal;
private TextToSpeech reply;

private AsyncTask t;


public WherePhoneService() {
}

@Override
public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    throw new UnsupportedOperationException("Not yet implemented");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    makeText(getApplicationContext(), "onHandle start", Toast.LENGTH_SHORT).show();

    getValues();

    startTTS();

    t = new AsyncTask<Void, Void, Exception>() {
        @Override
        protected Exception doInBackground(Void... params) {
            try {
                Assets assets = new Assets(WherePhoneService.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(sInput);
            }
        }
    }.execute();
    return Service.START_STICKY;
}

private void setupRecognizer(File assetsDir) throws IOException {
        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);

        // Create keyword-activation search.
        recognizer.addKeyphraseSearch(sInput, sInput);
}

private void switchSearch(String searchName) {
    recognizer.stop();

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

@Override
public void onBeginningOfSpeech() {

}

@Override
public void onEndOfSpeech() {
    if (!recognizer.getSearchName().equals(sInput))
        switchSearch(sInput);
}

@Override
public void onPartialResult(Hypothesis hypothesis) {
    if (hypothesis == null)
        return;

    String text = hypothesis.getHypstr();
    makeText(getApplicationContext(), "Partial", Toast.LENGTH_SHORT).show();

    if (text.equals(sInput)) {

        setVolume();

        // Text to speech
        reply.speak(sOutput, TextToSpeech.QUEUE_ADD, null);

        switchSearch(sInput);
    }
    else {
        makeText(getApplicationContext(), "Try again", Toast.LENGTH_SHORT).show();
        switchSearch(sInput);
    }
}

@Override
public void onResult(Hypothesis hypothesis) {
    if (hypothesis != null) {
        // restart listener and affirm that partial has past
        makeText(getApplicationContext(), "end", Toast.LENGTH_SHORT).show();
        //recognizer.startListening(sInput);
        switchSearch(sInput);
    }
}


public void onError(Exception e) {
    e.printStackTrace(); // not all Android versions will print the stack trace automatically

    Intent intent = new Intent ();
    intent.setAction ("com.mydomain.SEND_LOG"); // see step 5.
    intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application
    startActivity (intent);

    stopSelf();
}

@Override
public void onTimeout() {
    switchSearch(sInput);
}

public void startTTS() {
    reply = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if(status != TextToSpeech.ERROR){
                reply.setLanguage(Locale.UK);
            }
        }
    });
}

public void getValues() {
    settingData = getBaseContext().getSharedPreferences(SettingStorage, 0);
    sInput = settingData.getString("inputstring", "Where is my phone").toString().toLowerCase().replaceAll("[^\\w\\s]", "");
    sOutput = settingData.getString("outputstring", "").toString().toLowerCase();
    seekVal = settingData.getInt("seekval", 0);
}

public void setVolume() {
    int seekValConvert = 0;
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    int getMaxPhoneVol = audioManager.getStreamMaxVolume(audioManager.STREAM_MUSIC);
    seekValConvert = ((seekVal * getMaxPhoneVol)/100);
    audioManager.setStreamVolume(audioManager.STREAM_MUSIC, seekValConvert, 0);
}

@Override
public void onDestroy() {
    super.onDestroy();
    makeText(getApplicationContext(), "destroy", Toast.LENGTH_SHORT).show();
    recognizer.cancel();
    recognizer.shutdown();
    t.cancel(true);
}

}


Source: (StackOverflow)

Pocketsphinx-python installation error on Windows

I have been trying to install pocketsphinx on my laptop. I have installed all the dependencies, still keep giving the below error. GCC.exe exits in a folder and is added to the environment variables. Appreciate all the help

Source in c:\users\archana\appdata\local\temp\pip_build_archana\pocketsphinx has version 0.0.4, which satisfies requirement pocketsphinx
Installing collected packages: pocketsphinx
  Running setup.py install for pocketsphinx
    Running command C:\Users\ARCHANA\Anaconda\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\archana\\appdata\\local\\temp\\pip_build_ARCHANA\\pocketsphinx\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\archana\appdata\local\temp\pip-f_ai9e-record\install-record.txt --single-version-externally-managed --compile
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-2.7
    creating build\lib.win-amd64-2.7\sphinxbase
    copying sphinxbase\swig\python\sphinxbase.py -> build\lib.win-amd64-2.7\sphinxbase
    copying sphinxbase\swig\python\__init__.py -> build\lib.win-amd64-2.7\sphinxbase
    creating build\lib.win-amd64-2.7\pocketsphinx
    copying pocketsphinx\swig\python\pocketsphinx.py -> build\lib.win-amd64-2.7\pocketsphinx
    copying pocketsphinx\swig\python\__init__.py -> build\lib.win-amd64-2.7\pocketsphinx
    running build_ext
    building 'sphinxbase._sphinxbase' extension
    swigging sphinxbase/swig/sphinxbase.i to sphinxbase/swig/sphinxbase_wrap.c
    C:\Users\ARCHANA\Anaconda\swigwin-3.0.5\swig.exe -python -modern -Isphinxbase/include -Isphinxbase/include/sphinxbase -Isphinxbase/include/win32 -outdir sphinxbase/swig/python -o sphinxbase/swig/sphinxbase_wrap.c sphinxbase/swig/sphinxbase.i
    creating build\temp.win-amd64-2.7
    creating build\temp.win-amd64-2.7\Release
    creating build\temp.win-amd64-2.7\Release\sphinxbase
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\lm
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\feat
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\util
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\fe
    creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxad
    creating build\temp.win-amd64-2.7\Release\sphinxbase\swig
    C:\Users\ARCHANA\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -DSPHINXBASE_EXPORTS -DPOCKETSPHINX_EXPORTS -DHAVE_CONFIG_H -D_CRT_SECURE_NO_DEPRECATE -D_USRDLL -DSPHINXDLL -DWIN32 -D_WINDOWS -DYY_NO_UNISTD_H -Isphinxbase/include -Isphinxbase/include/sphinxbase -Isphinxbase/include/win32 -IC:\Users\ARCHANA\Anaconda\include -IC:\Users\ARCHANA\Anaconda\PC -c sphinxbase/src/libsphinxbase/lm\fsg_model.c -o build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\lm\fsg_model.o /wd4244 /wd4090 /wd4018
    gcc.exe: error: /wd4244: No such file or directory
    gcc.exe: error: /wd4090: No such file or directory
    gcc.exe: error: /wd4018: No such file or directory
    error: command 'gcc' failed with exit status 1
    Complete output from command C:\Users\ARCHANA\Anaconda\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\archana\\appdata\\local\\temp\\pip_build_ARCHANA\\pocketsphinx\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\archana\appdata\local\temp\pip-f_ai9e-record\install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build\lib.win-amd64-2.7

creating build\lib.win-amd64-2.7\sphinxbase

copying sphinxbase\swig\python\sphinxbase.py -> build\lib.win-amd64-2.7\sphinxbase

copying sphinxbase\swig\python\__init__.py -> build\lib.win-amd64-2.7\sphinxbase

creating build\lib.win-amd64-2.7\pocketsphinx

copying pocketsphinx\swig\python\pocketsphinx.py -> build\lib.win-amd64-2.7\pocketsphinx

copying pocketsphinx\swig\python\__init__.py -> build\lib.win-amd64-2.7\pocketsphinx

running build_ext

building 'sphinxbase._sphinxbase' extension

swigging sphinxbase/swig/sphinxbase.i to sphinxbase/swig/sphinxbase_wrap.c

C:\Users\ARCHANA\Anaconda\swigwin-3.0.5\swig.exe -python -modern -Isphinxbase/include -Isphinxbase/include/sphinxbase -Isphinxbase/include/win32 -outdir sphinxbase/swig/python -o sphinxbase/swig/sphinxbase_wrap.c sphinxbase/swig/sphinxbase.i

creating build\temp.win-amd64-2.7

creating build\temp.win-amd64-2.7\Release

creating build\temp.win-amd64-2.7\Release\sphinxbase

creating build\temp.win-amd64-2.7\Release\sphinxbase\src

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\lm

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\feat

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\util

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\fe

creating build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxad

creating build\temp.win-amd64-2.7\Release\sphinxbase\swig

C:\Users\ARCHANA\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -DSPHINXBASE_EXPORTS -DPOCKETSPHINX_EXPORTS -DHAVE_CONFIG_H -D_CRT_SECURE_NO_DEPRECATE -D_USRDLL -DSPHINXDLL -DWIN32 -D_WINDOWS -DYY_NO_UNISTD_H -Isphinxbase/include -Isphinxbase/include/sphinxbase -Isphinxbase/include/win32 -IC:\Users\ARCHANA\Anaconda\include -IC:\Users\ARCHANA\Anaconda\PC -c sphinxbase/src/libsphinxbase/lm\fsg_model.c -o build\temp.win-amd64-2.7\Release\sphinxbase\src\libsphinxbase\lm\fsg_model.o /wd4244 /wd4090 /wd4018

gcc.exe: error: /wd4244: No such file or directory

gcc.exe: error: /wd4090: No such file or directory

gcc.exe: error: /wd4018: No such file or directory

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
  Removing temporary dir c:\users\archana\appdata\local\temp\pip_build_ARCHANA...
Command C:\Users\ARCHANA\Anaconda\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\archana\\appdata\\local\\temp\\pip_build_ARCHANA\\pocketsphinx\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\archana\appdata\local\temp\pip-f_ai9e-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\archana\appdata\local\temp\pip_build_ARCHANA\pocketsphinx
Exception information:
Traceback (most recent call last):
  File "C:\Users\ARCHANA\Anaconda\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Users\ARCHANA\Anaconda\lib\site-packages\pip\commands\install.py", line 279, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "C:\Users\ARCHANA\Anaconda\lib\site-packages\pip\req.py", line 1380, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "C:\Users\ARCHANA\Anaconda\lib\site-packages\pip\req.py", line 699, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "C:\Users\ARCHANA\Anaconda\lib\site-packages\pip\util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
InstallationError: Command C:\Users\ARCHANA\Anaconda\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\archana\\appdata\\local\\temp\\pip_build_ARCHANA\\pocketsphinx\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\archana\appdata\local\temp\pip-f_ai9e-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\archana\appdata\local\temp\pip_build_ARCHANA\pocketsphinx

Source: (StackOverflow)

PocketSphinx crash

I'm trying to code a simple speech recognizer using cmu pocketsphinx , but It always crash when encounter decode_raw() function. I'm using Python 2.7 32-bit on Windows 7 64-bit with PyPocketSphinx(installed with pip)

Here is my code:

from pocketsphinx import Decoder
import sphinxbase

HMM="pocketsphinx-5prealpha-win32/model/en-us/en-us/"
LM="pocketsphinx-5prealpha-win32/model/en-us/en-us.lm.dmp"
DICT="pocketsphinx-5prealpha-win32/model/en-us/cmudict-en-us.dict"

config=Decoder.default_config()
config.set_string("-hmm",HMM)
config.set_string("-lm",LM)
config.set_string('-dict',DICT)
decoder=Decoder(config)

fh=open("output.wav",'rb')
fh.seek(44)

decoder.decode_raw(fh) #Crash
print decoder.get_hyp()

I tried to solve this problem for more than a week , and still haven't found an answer.

EDIT: Log generated before crash:

INFO: cmd_ln.c(696): Parsing command line:


Current configuration:
[NAME]          [DEFLT]         [VALUE]
-agc            none            none
-agcthresh      2.0             2.000000e+000
-allphone
-allphone_ci    no              no
-alpha          0.97            9.700000e-001
-ascale         20.0            2.000000e+001
-aw             1               1
-backtrace      no              no
-beam           1e-48           1.000000e-048
-bestpath       yes             yes
-bestpathlw     9.5             9.500000e+000
-bghist         no              no
-ceplen         13              13
-cmn            current         current
-cmninit        8.0             8.0
-compallsen     no              no
-debug                          0
-dict
-dictcase       no              no
-dither         no              no
-doublebw       no              no
-ds             1               1
-fdict
-feat           1s_c_d_dd       1s_c_d_dd
-featparams
-fillprob       1e-8            1.000000e-008
-frate          100             100
-fsg
-fsgusealtpron  yes             yes
-fsgusefiller   yes             yes
-fwdflat        yes             yes
-fwdflatbeam    1e-64           1.000000e-064
-fwdflatefwid   4               4
-fwdflatlw      8.5             8.500000e+000
-fwdflatsfwin   25              25
-fwdflatwbeam   7e-29           7.000000e-029
-fwdtree        yes             yes
-hmm
-input_endian   little          little
-jsgf
-kdmaxbbi       -1              -1
-kdmaxdepth     0               0
-kdtree
-keyphrase
-kws
-kws_plp        1e-1            1.000000e-001
-kws_threshold  1               1.000000e+000
-latsize        5000            5000
-lda
-ldadim         0               0
-lextreedump    0               0
-lifter         0               0
-lm
-lmctl
-lmname         default         default
-logbase        1.0001          1.000100e+000
-logfn
-logspec        no              no
-lowerf         133.33334       1.333333e+002
-lpbeam         1e-40           1.000000e-040
-lponlybeam     7e-29           7.000000e-029
-lw             6.5             6.500000e+000
-maxhmmpf       10000           10000
-maxnewoov      20              20
-maxwpf         -1              -1
-mdef
-mean
-mfclogdir
-min_endfr      0               0
-mixw
-mixwfloor      0.0000001       1.000000e-007
-mllr
-mmap           yes             yes
-ncep           13              13
-nfft           512             512
-nfilt          40              40
-nwpen          1.0             1.000000e+000
-pbeam          1e-48           1.000000e-048
-pip            1.0             1.000000e+000
-pl_beam        1e-10           1.000000e-010
-pl_pbeam       1e-5            1.000000e-005
-pl_window      0               0
-rawlogdir
-remove_dc      no              no
-remove_noise   yes             yes
-remove_silence yes             yes
-round_filters  yes             yes
-samprate       16000           1.600000e+004
-seed           -1              -1
-sendump
-senlogdir
-senmgau
-silprob        0.005           5.000000e-003
-smoothspec     no              no
-svspec
-tmat
-tmatfloor      0.0001          1.000000e-004
-topn           4               4
-topn_beam      0               0
-toprule
-transform      legacy          legacy
-unit_area      yes             yes
-upperf         6855.4976       6.855498e+003
-usewdphones    no              no
-uw             1.0             1.000000e+000
-vad_postspeech 50              50
-vad_prespeech  10              10
-vad_threshold  2.0             2.000000e+000
-var
-varfloor       0.0001          1.000000e-004
-varnorm        no              no
-verbose        no              no
-warp_params
-warp_type      inverse_linear  inverse_linear
-wbeam          7e-29           7.000000e-029
-wip            0.65            6.500000e-001
-wlen           0.025625        2.562500e-002

INFO: cmd_ln.c(696): Parsing command line:
\
        -lowerf 130 \
        -upperf 6800 \
        -nfilt 25 \
        -transform dct \
        -lifter 22 \
        -feat 1s_c_d_dd \
        -svspec 0-12/13-25/26-38 \
        -agc none \
        -cmn current \
        -varnorm no \
        -model ptm \
        -cmninit 40,3,-1

Current configuration:
[NAME]          [DEFLT]         [VALUE]
-agc            none            none
-agcthresh      2.0             2.000000e+000
-alpha          0.97            9.700000e-001
-ceplen         13              13
-cmn            current         current
-cmninit        8.0             40,3,-1
-dither         no              no
-doublebw       no              no
-feat           1s_c_d_dd       1s_c_d_dd
-frate          100             100
-input_endian   little          little
-lda
-ldadim         0               0
-lifter         0               22
-logspec        no              no
-lowerf         133.33334       1.300000e+002
-ncep           13              13
-nfft           512             512
-nfilt          40              25
-remove_dc      no              no
-remove_noise   yes             yes
-remove_silence yes             yes
-round_filters  yes             yes
-samprate       16000           1.600000e+004
-seed           -1              -1
-smoothspec     no              no
-svspec                         0-12/13-25/26-38
-transform      legacy          dct
-unit_area      yes             yes
-upperf         6855.4976       6.800000e+003
-vad_postspeech 50              50
-vad_prespeech  10              10
-vad_threshold  2.0             2.000000e+000
-varnorm        no              no
-verbose        no              no
-warp_params
-warp_type      inverse_linear  inverse_linear
-wlen           0.025625        2.562500e-002

INFO: acmod.c(252): Parsed model-specific feature parameters from pocketsphinx-5
prealpha-win32/model/en-us/en-us//feat.params
INFO: feat.c(715): Initializing feature stream to type: '1s_c_d_dd', ceplen=13,
CMN='current', VARNORM='no', AGC='none'
INFO: cmn.c(143): mean[0]= 12.00, mean[1..12]= 0.0
INFO: acmod.c(171): Using subvector specification 0-12/13-25/26-38
INFO: mdef.c(517): Reading model definition: pocketsphinx-5prealpha-win32/model/
en-us/en-us//mdef
INFO: mdef.c(530): Found byte-order mark BMDF, assuming this is a binary mdef fi
le
INFO: bin_mdef.c(336): Reading binary model definition: pocketsphinx-5prealpha-w
in32/model/en-us/en-us//mdef
INFO: bin_mdef.c(516): 42 CI-phone, 137053 CD-phone, 3 emitstate/phone, 126 CI-s
en, 5126 Sen, 29324 Sen-Seq
INFO: tmat.c(206): Reading HMM transition probability matrices: pocketsphinx-5pr
ealpha-win32/model/en-us/en-us//transition_matrices
INFO: acmod.c(124): Attempting to use SCHMM computation module
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: pocketsphinx-5prealp
ha-win32/model/en-us/en-us//means
INFO: ms_gauden.c(292): 42 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: pocketsphinx-5prealp
ha-win32/model/en-us/en-us//variances
INFO: ms_gauden.c(292): 42 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(354): 222 variance values floored
INFO: acmod.c(126): Attempting to use PTHMM computation module
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: pocketsphinx-5prealp
ha-win32/model/en-us/en-us//means
INFO: ms_gauden.c(292): 42 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(198): Reading mixture gaussian parameter: pocketsphinx-5prealp
ha-win32/model/en-us/en-us//variances
INFO: ms_gauden.c(292): 42 codebook, 3 feature, size:
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(294):  128x13
INFO: ms_gauden.c(354): 222 variance values floored
INFO: ptm_mgau.c(467): Loading senones from dump file pocketsphinx-5prealpha-win
32/model/en-us/en-us//sendump
INFO: ptm_mgau.c(491): BEGIN FILE FORMAT DESCRIPTION
INFO: ptm_mgau.c(554): Rows: 128, Columns: 5126
INFO: ptm_mgau.c(586): Using memory-mapped I/O for senones
INFO: ptm_mgau.c(826): Maximum top-N: 4
INFO: dict.c(320): Allocating 137526 * 20 bytes (2686 KiB) for word entries
INFO: dict.c(333): Reading main dictionary: pocketsphinx-5prealpha-win32/model/e
n-us/cmudict-en-us.dict
INFO: dict.c(213): Allocated 1007 KiB for strings, 1662 KiB for phones
INFO: dict.c(336): 133425 words read
INFO: dict.c(342): Reading filler dictionary: pocketsphinx-5prealpha-win32/model
/en-us/en-us//noisedict
INFO: dict.c(213): Allocated 0 KiB for strings, 0 KiB for phones
INFO: dict.c(345): 5 words read
INFO: dict2pid.c(396): Building PID tables for dictionary
INFO: dict2pid.c(406): Allocating 42^3 * 2 bytes (144 KiB) for word-initial trip
hones
INFO: dict2pid.c(132): Allocated 21336 bytes (20 KiB) for word-final triphones
INFO: dict2pid.c(196): Allocated 21336 bytes (20 KiB) for single-phone word trip
hones
INFO: ngram_model_arpa.c(77): No \data\ mark in LM file
INFO: ngram_model_dmp.c(142): Will use memory-mapped I/O for LM file
INFO: ngram_model_dmp.c(196): ngrams 1=19794, 2=1377200, 3=3178194
INFO: ngram_model_dmp.c(242):    19794 = LM.unigrams(+trailer) read
INFO: ngram_model_dmp.c(288):  1377200 = LM.bigrams(+trailer) read
INFO: ngram_model_dmp.c(314):  3178194 = LM.trigrams read
INFO: ngram_model_dmp.c(339):    57155 = LM.prob2 entries read
INFO: ngram_model_dmp.c(359):    10935 = LM.bo_wt2 entries read
INFO: ngram_model_dmp.c(379):    34843 = LM.prob3 entries read
INFO: ngram_model_dmp.c(407):     2690 = LM.tseg_base entries read
INFO: ngram_model_dmp.c(463):    19794 = ascii word strings read
INFO: ngram_search_fwdtree.c(99): 788 unique initial diphones
INFO: ngram_search_fwdtree.c(148): 0 root, 0 non-root channels, 56 single-phone
words
INFO: ngram_search_fwdtree.c(186): Creating search tree
INFO: ngram_search_fwdtree.c(192): before: 0 root, 0 non-root channels, 56 singl
e-phone words
INFO: ngram_search_fwdtree.c(326): after: max nonroot chan increased to 44782
INFO: ngram_search_fwdtree.c(339): after: 573 root, 44654 non-root channels, 47
single-phone words
INFO: ngram_search_fwdflat.c(157): fwdflat: min_ef_width = 4, max_sf_win = 25

EDIT 2: This is generated in log file when I try to compile PyPocketsphinx:

setup.py build:

running build
running build_ext
running build_py
copying sphinxbase\swig\python\sphinxbase.py -> build\lib.win32-2.7\sphinxbase
copying pocketsphinx\swig\python\pocketsphinx.py -> build\lib.win32-2.7\pocketsp
hinx

setup.py install:

running install
running build_ext
running build
running build_py
copying sphinxbase\swig\python\sphinxbase.py -> build\lib.win32-2.7\sphinxbase
copying pocketsphinx\swig\python\pocketsphinx.py -> build\lib.win32-2.7\pocketsp
hinx
running install_lib
copying build\lib.win32-2.7\pocketsphinx\_pocketsphinx.pyd -> C:\Python27\Lib\si
te-packages\pocketsphinx
copying build\lib.win32-2.7\sphinxbase\_sphinxbase.pyd -> C:\Python27\Lib\site-p
ackages\sphinxbase
running install_egg_info
running egg_info
writing PyPocketSphinx.egg-info\PKG-INFO
writing top-level names to PyPocketSphinx.egg-info\top_level.txt
writing dependency_links to PyPocketSphinx.egg-info\dependency_links.txt
reading manifest file 'PyPocketSphinx.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'build'
no previously-included directories found matching 'dist'
warning: no previously-included files found matching 'sphinxbase\swig\sphinxbase
_wrap.c'
warning: no previously-included files found matching 'pocketsphinx\swig\pocketsp
hinx_wrap.c'
writing manifest file 'PyPocketSphinx.egg-info\SOURCES.txt'
removing 'C:\Python27\Lib\site-packages\PyPocketSphinx-12608.5-py2.7.egg-info' (
and everything under it)
Copying PyPocketSphinx.egg-info to C:\Python27\Lib\site-packages\PyPocketSphinx-
12608.5-py2.7.egg-info
running install_scripts

I think there is a problem at these lines:

warning: no previously-included files found matching 'sphinxbase\swig\sphinxbase_wrap.c'
warning: no previously-included files found matching 'pocketsphinx\swig\pocketsphinx_wrap.c'

Source: (StackOverflow)

Pocketsphinx android demo is working great on Android 4.3 and below. But it crashes in Android 4.4 and above

The code runs great on all Android devices running 4.0 - 4.3. However on devices running Android 4.4 and above, KWS_Search starts successfully but the application crashes the moment I say "activate speech" giving the following error.

02-06 20:13:40.228: I/cmusphinx(29758): INFO: fsg_search.c(843): 74 frames, 477 HMMs (6/fr), 2534 senones (34/fr), 23 history entries (0/fr)
02-06 20:13:40.235: I/SpeechRecognizer(29758): Stop recognition
02-06 20:13:40.235: I/SpeechRecognizer(29758): Start recognition "wakeup"
02-06 20:13:40.244: D/bt(29758): subclass 
02-06 20:13:40.256: I/cmusphinx(29758): INFO: pocketsphinx.c(863): Writing raw audio log file: /storage/emulated/0/Android/data/com.BuildingBlocks.codigo/files/sync/000000007.raw
02-06 20:13:40.459: A/libc(29758): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x89280000 in tid 30022 (Thread-1944)

I get Fatal signal 11 when a device runs out of memory usually if I use very high resolution graphics

I searched the internet and found that Google introduced HotKeywords in Android 4.4 where the phone is constantly listening to sounds. Sometimes it works if I wait for 60 seconds before saying the KEYPHRASE. Sometimes it doesnot work and the my app crashes. Below is my complete code

@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(FORECAST_SEARCH, R.string.forecast_caption);
setContentView(R.layout.sphinx_voice);
((TextView) findViewById(R.id.speech))
        .setText("Preparing the recognizer");
((TextView) findViewById(R.id.speech)).setTextSize(23);
((TextView) findViewById(R.id.deactivate)).setVisibility(View.INVISIBLE);
((TextView) findViewById(R.id.result_text)).setVisibility(View.INVISIBLE);
((TextView) findViewById(R.id.listening)).setVisibility(View.INVISIBLE);

// 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(SphinxVoice.this);
            File assetDir = assets.syncAssets();
            setupRecognizer(assetDir);
            load=2;
        } catch (IOException e) {
            return e;
        }
        return null;
    }

    @Override
    protected void onPostExecute(Exception result) {
        if (load==2)
        {
        if (result != null) {
            ((TextView) findViewById(R.id.speech))
                    .setText("Failed to init recognizer " + result);
            ((TextView) findViewById(R.id.speech)).setTextSize(23);
            ((TextView) findViewById(R.id.deactivate)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.result_text)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.listening)).setVisibility(View.INVISIBLE);
        } else {
            switchSearch(KWS_SEARCH);
            ((TextView) findViewById(R.id.deactivate)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.result_text)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.listening)).setVisibility(View.INVISIBLE);
            }   
        }
    }
}.execute();
}

@Override
public void onPartialResult(Hypothesis hypothesis) {
String text = hypothesis.getHypstr();
if (text.contains("left"))
{
    ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DLXXXXXXXXXXXXXXX");
     switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.result_text)).setText("Executing Left");
        ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

}else if (text.contains("right"))
{
    ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DRXXXXXXXXXXXXXXX");
     switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.result_text)).setText("Executing Right");
        ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

}else if (text.contains("forward"))
{
    ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DFXXXXXXXXXXXXXXX");
     switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.result_text)).setText("Executing Forward");
        ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

}else if (text.contains("back"))
{
    ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DBXXXXXXXXXXXXXXX");
    switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.result_text)).setText("Executing Back");
        ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

}else if (text.contains("stop"))
{
    ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DYXXXXXXXXXXXXXXX");
     switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.result_text)).setText("Stop");
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);

}else if (text.contains("deactivate"))
{
     ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DYXXXXXXXXXXXXXXX");
     switchSearch(KWS_SEARCH);
     ((TextView) findViewById(R.id.result_text)).setVisibility(View.INVISIBLE);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.INVISIBLE);
        ((TextView) findViewById(R.id.listening)).setVisibility(View.INVISIBLE);

}else if (text.equals(KEYPHRASE))
{
      switchSearch(DIGITS_SEARCH);
     ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);
     ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
}
else{
    ((TextView) findViewById(R.id.result_text)).setText(text);
    }
}
@Override
public void onResult(Hypothesis hypothesis) {
((TextView) findViewById(R.id.result_text)).setText("");

if (hypothesis != null) {
    String text = hypothesis.getHypstr();
    if (text.contains("left"))
    {
        ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DLXXXXXXXXXXXXXXX");
         switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.result_text)).setText("Executing Left");
            ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

    }else if (text.contains("right"))
    {
        ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DRXXXXXXXXXXXXXXX");
         switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.result_text)).setText("Executing Right");
            ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

    }else if (text.contains("forward"))
    {
        ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DFXXXXXXXXXXXXXXX");
         switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.result_text)).setText("Executing Forward");
            ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

    }else if (text.contains("back"))
    {
        ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DBXXXXXXXXXXXXXXX");
        switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.result_text)).setText("Executing Back");
            ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);

    }else if (text.contains("stop"))
    {
        ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DYXXXXXXXXXXXXXXX");
         switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.result_text)).setText("Stop");
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);

    }else if (text.contains("deactivate"))
    {
         ((CodigoApplication)SphinxVoice.this.getApplicationContext()).sendMessage("DYXXXXXXXXXXXXXXX");
         switchSearch(KWS_SEARCH);
         ((TextView) findViewById(R.id.result_text)).setVisibility(View.INVISIBLE);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.INVISIBLE);
            ((TextView) findViewById(R.id.listening)).setVisibility(View.INVISIBLE);

    }else if (text.equals(KEYPHRASE))
    {
        switchSearch(DIGITS_SEARCH);
         ((TextView) findViewById(R.id.deactivate)).setVisibility(View.VISIBLE);
         ((TextView) findViewById(R.id.listening)).setVisibility(View.VISIBLE);
    }
    else{
        ((TextView) findViewById(R.id.result_text)).setText(text);
        }
    }
}

@Override
public void onBeginningOfSpeech() {

    ((TextView) findViewById(R.id.listening)).setText("Listening...");
}

@Override
public void onEndOfSpeech() {

}

private void switchSearch(String searchName) {
recognizer.stop();
recognizer.startListening(searchName);
String caption = getResources().getString(captions.get(searchName));
((TextView) findViewById(R.id.speech)).setText(caption);
((TextView) findViewById(R.id.speech)).setTextSize(23);
}

private void setupRecognizer(File assetsDir) {
File modelsDir = new File(assetsDir, "models");
recognizer = defaultSetup()
        .setAcousticModel(new File(modelsDir, "hmm/en-us-semi"))
        .setDictionary(new File(modelsDir, "dict/cmu07a.dic"))
        .setRawLogDir(assetsDir).setKeywordThreshold(1f-80f)
        .getRecognizer();
recognizer.addListener(this);

// Create keyword-activation search.
recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
// Create grammar-based searches.
Log.d("voicelog",modelsDir.getAbsolutePath());
File robbyGrammar = new File(modelsDir, "grammar/robby.gram");
Log.d("voicelog",robbyGrammar.getAbsolutePath());
recognizer.addGrammarSearch(DIGITS_SEARCH, robbyGrammar);
}

@Override 
public void onBackPressed() { 
        recognizer.cancel();
        SphinxVoice.this.finish();
    } 
}

Below is the robby.gram file

#JSGF V1.0;

grammar robby;

= deactivate speech| left | right | forward | back | stop ;


Source: (StackOverflow)

How to get LanguageModel JS File?

I have been using PocketSphinx.js for speech recognition on my website. I have Downloaded language model file (.dmp). But their code uses JS file for Language model. I dont know where to get JS file. Help me out. Thanks.


Source: (StackOverflow)

The range of variation for each parameter for pocketsphinx_continuous app

I found that there are so many parameters to tune up speech recognition( for example input parameters in pocketsphinx_continuous app). Many parameters are enumerations, other are floating values. Where can I find the range of variation for each parameter for pocketsphinx_continuous app?


Source: (StackOverflow)

Pocketsphinx: Capturing real-time output of -inmic yes to .txt

I'm using pocketsphinx_continuous on Windows. Redirecting output to a text file works with the "-infile" argument, but fails with "-inmic yes".

As noted in the question Does Pocketsphinx ignore stdout? pocketsphinx ignores stdout (at least when using -inmic).

Is there any way I can save the words recognized by pocketsphinx_continuous with "-inmic yes" to a text file?

Specifically, I want my Java program to run pocketsphinx_continuous.exe and get the words recognized from microphone input.

Solution

Using -backtrace with -logfn as suggested by Alexander Solovets indeed saves the results along with the log in the specified file. However, the log is not saved as frequently as the results are sent to the terminal. I wanted the results output to a file as fast as possible, so I built pocketsphinx_continuous.exe from source with the following changes to continous.c.

In continuous.c:

hyp = ps_get_hyp(ps, NULL );
if (hyp != NULL)
{
    printf("%s\n", hyp);
    FILE * fp;
    fp = fopen("file.txt", "a+");
    fprintf(fp, hyp);
    fprintf(fp, "\r\n");
    fclose(fp);
}

Source: (StackOverflow)

Where is Gradle Project so I can import it? (Android Studio)

I'm 99% positive this is a total nub question but I downloaded the pocketsphinx demo project: https://github.com/cmusphinx/pocketsphinx-android-demo and was told in the tutorial to just import the project into Android Studio and then all the dependencies would be pulled automatically. I don't doubt this is the case but when I tried importing the project I got a dialog asking me to "Import Gradle Project". I'm confused because it sounds like it's looking for a component of the project but there's nothing I could find in there that AS was looking for. Is this included in the project or do I have to download Gradle?

Edit:

I try to import the project

enter image description here

I hit okay and this pops up:

enter image description here


Source: (StackOverflow)

Identify start/stop times of spoken words within a phrase using Sphinx

I'm trying to identify the start/end time of individual words within a phrase. I have a WAV file of the phrase AND the text of the utterance.

Is there an intelligent way of combining these two data (audio, text) to improve Sphinx's recognition abilities? What I'd like as output are accurate start/stop times for each word within the phrase.

(I know you can pass -time yes to pocketsphinx to get the time data I'm looking for -- however, the speech recognition itself is not very accurate.)

The solution cannot be for a specific speaker, as the corpus I'm working with contains a lot of different speakers, although they are all using US English.


Source: (StackOverflow)

pocketsphinx.js - prevent accepting wrong words

i am trying to use pocketsphinx.js for speechrecognition in my Webapp. My Problem is, that the software tries to recognize everything it hears as a right word.

And i am wondering because all Demos i found behaves the same.

So for example take this demonstration: https://touchless-timer.appspot.com/timer/en.html# It's made for setting an alarm in english.

But when i'm saying something in german, it always prints me out that it has understood something correct like "setting the alarm to...."

So how should i use it, when it recognizes always correct input even if i'm speaking a different language?

Hope my Question is understandable. Thanks a lot.


Source: (StackOverflow)

Can't find methods in pocketsphinx module (Python3.4 on windows)

I'm trying to use the PocketSphinx python module, I downloaded PyPocketSphinx via pypi.python.org using the win32-py3.4 link. But when I can't make this simple code working using the interpreter:

import pocketsphinx as ps
dec = ps.Decoder()

"AttributeError: 'module' object has no attribute 'Decoder'

When checking the module via: dir(ps), I have:

['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

And print(ps.__file__) gave me the right path (C:\Python34\lib\site-packages\pocketsphinx__init__.py)

I'm a bit lost why python find the correct module but can't figure out the methods within.

Would you have an idea ? Thanks in advance,


Source: (StackOverflow)