Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.72 KB | None | 0 0
  1. I WANT TO PUT THIS:
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <unistd.h>
  7.  
  8. #include "iniparser.h"
  9.  
  10. /* compile this with
  11.  * gcc -o configtest configtest.c -I/usr/lib/ -liniparser
  12.  */
  13.  
  14.  
  15. int main(int argc, char * argv[])
  16. {
  17.     dictionary * ini ;
  18.     char       * ini_name ;
  19.  
  20.         if (argc<2) {
  21.         ini_name = "parser.conf";
  22.         } else {
  23.                 ini_name = argv[1] ;
  24.         }
  25.  
  26.     ini = iniparser_load(ini_name);
  27.  
  28.     char    *   s;
  29. s = iniparser_getstring(ini, "commandlineargs:dict", NULL);
  30. char* dict = s;
  31. printf(dict);
  32.  
  33. /* not from fatz: printf("%s is a %s", "jimbo", "humpback"); to print jimbo is a humpback */
  34.  
  35. s = iniparser_getstring(ini, "commandlineargs:hmm", NULL);
  36. char* hmm = s;
  37. printf(hmm);
  38.  
  39.     iniparser_freedict(ini);
  40.  
  41.         return 0 ;
  42. }
  43.  
  44. IN THIS:
  45.  
  46. #include <pocketsphinx.h>
  47.  
  48. /* compile this with
  49.  * $ gcc -o hellow hello_ps.c -I/usr/local/include/sphinxbase -I/usr/local/include/pocketsphinx -I/usr/local/include  -L/usr/local/lib -lpocketsphinx -lsphinxbase -lsphinxad -lm -llibiconv
  50.  */
  51.  
  52. int
  53. main(int argc, char *argv[])
  54. {
  55.     ps_decoder_t *ps;
  56.     cmd_ln_t *config;
  57.     FILE *fh;
  58.     char const *hyp, *uttid;
  59.         int16 buf[512];
  60.     int rv;
  61.     int32 score;
  62.  
  63. /* going to try and read a config file
  64.  
  65.     FILE *configfile;
  66.     configfile = fopen("decode.conf","r");
  67.    
  68. */
  69.  
  70.  
  71. /* below are the command line args */
  72.  
  73.     config = cmd_ln_init(NULL, ps_args(), TRUE,
  74.             "-hmm", "/usr/local/share/pocketsphinx/model/hmm/en_US/hub4wsj_sc_8k",
  75.  
  76.             /* this is our custom lm and dic    */
  77.             "-lm", "/usr/local/share/pocketsphinx/model/lm/en/0172.lm",
  78.             "-dict", "/usr/local/share/pocketsphinx/model/lm/en/0172.dic", NULL);
  79.  
  80.     if (config == NULL)
  81.         return 1;
  82.     ps = ps_init(config);
  83.     if (ps == NULL)
  84.         return 1;
  85.  
  86.     fh = fopen("/home/nobaboon/chicagoscanner/drops from laptop/1-6-2011-133311-testtranscribe/1-6-2011-12383.wav", "rb");
  87.     if (fh == NULL) {
  88.         perror("Failed to open 2324.wav");
  89.         return 1;
  90.     }
  91.  
  92.     rv = ps_decode_raw(ps, fh, "1-6-2011-133311", -1);
  93.     if (rv < 0)
  94.         return 1;
  95.     hyp = ps_get_hyp(ps, &score, &uttid);
  96.     if (hyp == NULL)
  97.         return 1;
  98.     printf("Recognized: %s\n", hyp);
  99.  
  100.         fseek(fh, 0, SEEK_SET);
  101.         rv = ps_start_utt(ps, "1-6-2011-133311");
  102.     if (rv < 0)
  103.         return 1;
  104.         while (!feof(fh)) {
  105.             size_t nsamp;
  106.             nsamp = fread(buf, 2, 5, fh);
  107.             rv = ps_process_raw(ps, buf, nsamp, FALSE, FALSE);
  108.         }
  109.         rv = ps_end_utt(ps);
  110.     if (rv < 0)
  111.         return 1;
  112.     hyp = ps_get_hyp(ps, &score, &uttid);
  113.     if (hyp == NULL)
  114.         return 1;
  115. /*  printf("Recognized: %s\n", hyp); */
  116.     printf("Recognized: %s with prob %d\n", hyp, ps_get_prob (ps, NULL));
  117.  
  118.     fclose(fh);
  119.         ps_free(ps);
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement