Menu

sphinx crash fourth time round

Help
RobR
2003-07-14
2012-09-22
  • RobR

    RobR - 2003-07-14

    Hi,
    Its a long story as to why I need this, but whenever I try to initialise and stop sphinx a number of times, Sphinx crashes out on me.

    Specificly Sphinx can only start and stop three times within the same process. The fourth time you try to initialise, she crashes.

    I have attached sample code in the hope that someone with a dubegger set up might be able to track the fault.

    I have not included the lm or dict files though... so if anyone wants to play with the example they will have to use their own Lm and dict.  Also just say quit/goodbye to move it onto the next iteration.

    Please please please can someone help

    robert

    #include <stdio.h>
    #include <signal.h>
    #include <setjmp.h>
    #include <string.h>

    #include "s2types.h"
    #include "err.h"
    #include "ad.h"
    #include "cont_ad.h"
    #include "fbs.h"

    #ifdef WIN32
    #include <time.h>
    #else
    #include <sys/types.h>
    #include <sys/time.h>
    #endif

    #define SAMPLE_RATE   16000

    static ad_rec_t *ad;

    /* Sleep for specified msec */
    static void sleep_msec (int32 ms)
    {
    #ifdef WIN32
        Sleep(ms);
    #else
        /* ------------------- Unix ------------------ */
        struct timeval tmo;
       
        tmo.tv_sec = 0;
        tmo.tv_usec = ms*1000;
       
        select(0, NULL, NULL, NULL, &tmo);
    #endif
    }

    /*
    * Main utterance processing loop:
    *     for (;;) {
    *       wait for start of next utterance;
    *       decode utterance until silence of at least 1 sec observed;
    *       print utterance result;
    *     }
    */
    static void utterance_loop()
    {
        int16 adbuf[4096];
        int32 k, fr, ts, rem;
        char *hyp;
        cont_ad_t *cont;
        char word[256];
       
        /* Initialize continuous listening module */
        if ((cont = cont_ad_init (ad, ad_read)) == NULL)
       E_FATAL("cont_ad_init failed\n");
        if (ad_start_rec (ad) < 0)
       E_FATAL("ad_start_rec failed\n");
        if (cont_ad_calib (cont) < 0)
       E_FATAL("cont_ad_calib failed\n");

        for (;;) {
       /* Indicate listening for next utterance */
            printf ("READY....\n"); fflush (stdout); fflush (stderr);
      
       /* Await data for next utterance */
       while ((k = cont_ad_read (cont, adbuf, 4096)) == 0)
           sleep_msec(200);
      
       if (k < 0)
           E_FATAL("cont_ad_read failed\n");
      
       /*
        * Non-zero amount of data received; start recognition of new utterance.
        * NULL argument to uttproc_begin_utt => automatic generation of utterance-id.
        */
       if (uttproc_begin_utt (NULL) < 0)
           E_FATAL("uttproc_begin_utt() failed\n");
       uttproc_rawdata (adbuf, k, 0);
       printf ("Listening...\n"); fflush (stdout);

       /* Note timestamp for this first block of data */
       ts = cont->read_ts;

       /* Decode utterance until end (marked by a "long" silence, >1sec) */
       for (;;) {
           /* Read non-silence audio data, if any, from continuous listening module */
           if ((k = cont_ad_read (cont, adbuf, 4096)) < 0)
          E_FATAL("cont_ad_read failed\n");
           if (k == 0) {
          /*
           * No speech data available; check current timestamp with most recent
           * speech to see if more than 1 sec elapsed.  If so, end of utterance.
           */
          if ((cont->read_ts - ts) > DEFAULT_SAMPLES_PER_SEC)
              break;
           } else {
          /* New speech data received; note current timestamp */
          ts = cont->read_ts;
           }
          
           /*
            * Decode whatever data was read above.  NOTE: Non-blocking mode!!
            * rem = #frames remaining to be decoded upon return from the function.
            */
           rem = uttproc_rawdata (adbuf, k, 0);

           /* If no work to be done, sleep a bit */
           if ((rem == 0) && (k == 0))
          sleep_msec (20);
       }
      
       /*
        * Utterance ended; flush any accumulated, unprocessed A/D data and stop
        * listening until current utterance completely decoded
        */
       ad_stop_rec (ad);
       while (ad_read (ad, adbuf, 4096) >= 0);
       cont_ad_reset (cont);

       printf ("Stopped listening, please wait...\n"); fflush (stdout);
    #if 0
       /* Power histogram dump (FYI) */
       cont_ad_powhist_dump (stdout, cont);
    #endif
       /* Finish decoding, obtain and print result */
       uttproc_end_utt ();
       if (uttproc_result (&fr, &hyp, 1) < 0)
           E_FATAL("uttproc_result failed\n");
       printf ("%d: %s\n", fr, hyp); fflush (stdout);
      
       /* Exit if the first word spoken was GOODBYE */
       sscanf (hyp, "%s", word);
       if (strcmp (word, "goodbye") == 0)
           break;

       /* Resume A/D recording for next utterance */
       if (ad_start_rec (ad) < 0)
           E_FATAL("ad_start_rec failed\n");
        }

        cont_ad_close (cont);
    }

    static jmp_buf jbuf;
    static void sighandler(int signo)
    {
        longjmp(jbuf, 1);
    }

    void runIt(void)
    {
        char *arguements[73];

        /* constructs an array of arguements.  */
        arguements[0] = "sphinxapp";
        arguements[1] = "-live";
        arguements[2] = "TRUE";
        arguements[3] = "-ctloffset";
        arguements[4] = "0";
        arguements[5] = "-ctlcount";
        arguements[6] = "100000000";
        arguements[7] = "-cepdir";
        arguements[8] = "./ctl" ;
        arguements[9] = "-datadir";
        arguements[10] = "/ctl";
        arguements[11] = "-agcmax";
        arguements[12] = "FALSE";
        arguements[13] = "-langwt";
        arguements[14] = "6.5" ;
        arguements[15] = "-fwdflatlw";
        arguements[16] = "8.5";
        arguements[17] = "-rescorelw";
        arguements[18] = "9.5";
        arguements[19] = "-ugwt";
        arguements[20] = "0.5";
        arguements[21] = "-fillpen";
        arguements[22] = "1e-10";
        arguements[23] = "-silpen";
        arguements[24] = "0.005";
        arguements[25] = "-inspen";
        arguements[26] = "0.65";
        arguements[27] = "-top";
        arguements[28] = "1";
        arguements[29] = "-topsenfrm";
        arguements[30] = "3";
        arguements[31] = "-topsenthresh";
        arguements[32] = "-70000";
        arguements[33] = "-beam";
        arguements[34] = "2e-06";
        arguements[35] = "-npbeam";
        arguements[36] = "2e-06";
        arguements[37] = "-lpbeam";
        arguements[38] = "2e-05";
        arguements[39] = "-lponlybeam";
        arguements[40] = "0.0005";
        arguements[41] = "-nwbeam";
        arguements[42] = "0.0005";
        arguements[43] = "-fwdflat";
        arguements[44] = "FALSE";
        arguements[45] = "-fwdflatbeam";
        arguements[46] = "1e-08";
        arguements[47] = "-fwdflatnwbeam";
        arguements[48] = "0.0003";
        arguements[49] = "-bestpath";
        arguements[50] = "TRUE";
        arguements[51] = "-kbdumpdir";
        arguements[52] = ".";
        arguements[53] = "-lmctlfn";
        arguements[54] = "/home/robertr/work/said/code/marc/src/c/platforms/sphinx/model.ctl";
        arguements[55] = "-dictfn";
        arguements[56] = "/home/robertr/work/said/code/marc/src/c/platforms/sphinx/general.dict";
        arguements[57] = "-ndictfn";
        arguements[58] = "/usr/local/share/sphinx2/model/hmm/6k/noisedict";
        arguements[59] = "-phnfn";
        arguements[60] = "/usr/local/share/sphinx2/model/hmm/6k/phone";
        arguements[61] = "-mapfn";
        arguements[62] = "/usr/local/share/sphinx2/model/hmm/6k/map";
        arguements[63] = "-hmmdir";
        arguements[64] = "/usr/local/share/sphinx2/model/hmm/6k";
        arguements[65] = "-hmmdirlist";
        arguements[66] = "/usr/local/share/sphinx2/model/hmm/6k";
        arguements[67] = "-8bsen";
        arguements[68] = "TRUE";
        arguements[69] = "-sendumpfn";
        arguements[70] = "/usr/local/share/sphinx2/model/hmm/6k/sendump";
        arguements[71] = "-cbdir";
        arguements[72] = "/usr/local/share/sphinx2/model/hmm/6k";

       /* Make sure we exit cleanly (needed for profiling among other things) */
        signal(SIGINT, &sighandler);

        fbs_init (73, arguements);
       
        if ((ad = ad_open_sps (SAMPLE_RATE)) == NULL)
       E_FATAL("ad_open_sps failed\n");

        //E_INFO("%s COMPILED ON: %s, AT: %s\n\n", argv[0], __DATE__, __TIME__);

        if (setjmp(jbuf) == 0) {
       utterance_loop ();
        }

        fbs_end ();
        ad_close (ad);
       
        printf("exiting runIt\n");
    }

    int main (int argc, char *argv[])
    {
        runIt();
        runIt();
        runIt();
        runIt();
       
       
        printf("exiting\n");
        return 0;
    }

     
    • Anonymous

      Anonymous - 2003-07-14

      You didn't say, but given the context of your previous postings, I assume you're working with Sphinx2.

      One guess for your crash is that you've run out of memory.  The reason for said guess is that AFAIK Sphinx2 apparently wasn't designed to be initialized and closed multiple times within an application, and consequently it lacks the means to recover the memory that was allocated for the acoustic model, dictionary, language model(s), etc.  fbs_end() frees only a little bit of top-level allocations, but the rest is orphaned.

      cheers,
        jerry wolf
        soliloquy learning, inc.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.