Attachment 'pocketsphinx-patch.diff'

Download

   1 Index: src/libpocketsphinx/dict.c
   2 ===================================================================
   3 --- src/libpocketsphinx/dict.c	(revision 8731)
   4 +++ src/libpocketsphinx/dict.c	(working copy)
   5 @@ -734,8 +734,8 @@
   6      }
   7  
   8      /* For the moment, no single phone new word... */
   9 -    if (pronoun_len < 2) {
  10 -        E_ERROR("Pronunciation string too short\n");
  11 +    if (pronoun_len < 1) {
  12 +        E_ERROR("Pronunciation string is empty\n");
  13          return (0);
  14      }
  15  
  16 @@ -743,43 +743,54 @@
  17      {
  18          char *p = strrchr(word_str, '(');
  19          if (p && (word_str[strlen(word_str) - 1] == ')')) {
  20 -            *p = '\0';
  21 -            if (hash_table_lookup_int32(dict->dict, word_str, &idx)) {
  22 -                *p = '(';
  23 -                E_ERROR("Base word missing for %s\n", word_str);
  24 -                return 0;
  25 -            }
  26 -            *p = '(';
  27 -            basewid = (long)idx;
  28 -        }
  29 -        else
  30 -            basewid = -1;
  31 +    	    *p = '\0';
  32 +    	    if (hash_table_lookup_int32(dict->dict, word_str, &idx)) {
  33 +        	*p = '(';
  34 +            	E_ERROR("Base word missing for %s\n", word_str);
  35 +            	return 0;
  36 +    	    }
  37 +        *p = '(';
  38 +        basewid = (long)idx;
  39 +	} else {
  40 +    	    basewid = -1;
  41 +	}
  42      }
  43  
  44 -    /* Parse pron; for the moment, the boundary diphones must be already known... */
  45 -    i = 0;
  46 -    sprintf(triphoneStr, "%s(%%s,%s)b", phone[i], phone[i + 1]);
  47 -    if (hash_table_lookup_int32(dict->lcHT, triphoneStr, &idx) < 0) {
  48 -        E_ERROR("Unknown left diphone '%s'\n", triphoneStr);
  49 -        return (0);
  50 -    }
  51 -    triphone_ids[i] = idx;
  52 +    if (pronoun_len >= 2) {
  53  
  54 -    for (i = 1; i < pronoun_len - 1; i++) {
  55 -        triphone_ids[i] = bin_mdef_phone_id(dict->mdef,
  56 -                                            dict_ciphone_id(dict, phone[i]),
  57 -                                            dict_ciphone_id(dict, phone[i-1]),
  58 -                                            dict_ciphone_id(dict, phone[i+1]),
  59 -                                            WORD_POSN_INTERNAL);
  60 -        triphone_ids[i] = bin_mdef_pid2ssid(dict->mdef, triphone_ids[i]);
  61 +	/* Parse pron; for the moment, the boundary diphones must be already known... */
  62 +        i = 0;
  63 +	sprintf(triphoneStr, "%s(%%s,%s)b", phone[i], phone[i + 1]);
  64 +        if (hash_table_lookup_int32(dict->lcHT, triphoneStr, &idx) < 0) {
  65 +	    E_ERROR("Unknown left diphone '%s'\n", triphoneStr);
  66 +            return (0);
  67 +	}
  68 +        triphone_ids[i] = idx;
  69 +
  70 +	for (i = 1; i < pronoun_len - 1; i++) {
  71 +            triphone_ids[i] = bin_mdef_phone_id(dict->mdef,
  72 +                    	                        dict_ciphone_id(dict, phone[i]),
  73 +                    		                dict_ciphone_id(dict, phone[i-1]),
  74 +                	                        dict_ciphone_id(dict, phone[i+1]),
  75 +        	                                WORD_POSN_INTERNAL);
  76 +    	    triphone_ids[i] = bin_mdef_pid2ssid(dict->mdef, triphone_ids[i]);
  77 +	}
  78 +    
  79 +        sprintf(triphoneStr, "%s(%s,%%s)e", phone[i], phone[i - 1]);
  80 +	if (hash_table_lookup_int32(dict->rcHT, triphoneStr, &idx) < 0) {
  81 +        	E_ERROR("Unknown right diphone '%s'\n", triphoneStr);
  82 +    	    return (0);
  83 +	}
  84 +        triphone_ids[i] = idx;
  85      }
  86  
  87 -    sprintf(triphoneStr, "%s(%s,%%s)e", phone[i], phone[i - 1]);
  88 -    if (hash_table_lookup_int32(dict->rcHT, triphoneStr, &idx) < 0) {
  89 -        E_ERROR("Unknown right diphone '%s'\n", triphoneStr);
  90 -        return (0);
  91 +    /*
  92 +     * Add single phone words without context
  93 +     */
  94 +    if (pronoun_len == 1) {
  95 +        triphone_ids[0] = dict_ciphone_id(dict,phone[0]);
  96 +        triphone_ids[0] = bin_mdef_pid2ssid(dict->mdef,triphone_ids[0]);
  97      }
  98 -    triphone_ids[i] = idx;
  99  
 100      /*
 101       * Set up dictionary entry.  Free the existing attributes (where applicable) and
 102 Index: src/libpocketsphinx/fsg_search.c
 103 ===================================================================
 104 --- src/libpocketsphinx/fsg_search.c	(revision 8731)
 105 +++ src/libpocketsphinx/fsg_search.c	(working copy)
 106 @@ -201,6 +201,30 @@
 107  
 108  
 109  static int
 110 +fsg_search_clean_oov(fsg_search_t *fsgs, fsg_model_t *fsg)
 111 +{
 112 +    dict_t *dict;
 113 +    int i;
 114 +
 115 +    dict = ps_search_dict(fsgs);
 116 +
 117 +    for (i = 0; i < fsg_model_n_word(fsg); ++i) {
 118 +        char const *word;
 119 +        int32 wid;
 120 +        char buf[4] = "SIL";
 121 +        
 122 +        word = fsg_model_word_str(fsg, i);
 123 +        wid = dict_to_id(dict, word);
 124 +        if (wid == NO_WORD) {
 125 +            E_WARN("Word %s is missing in the dictionary, adding with a SIL pron\n", word);
 126 +	    dict_add_word (dict, word, buf);
 127 +    	}
 128 +    }
 129 +    
 130 +    return 0;
 131 +}
 132 +
 133 +static int
 134  fsg_search_add_silences(fsg_search_t *fsgs, fsg_model_t *fsg)
 135  {
 136      dict_t *dict;
 137 @@ -282,6 +306,8 @@
 138  {
 139      if (name == NULL)
 140          name = fsg_model_name(fsg);
 141 +    
 142 +    fsg_search_clean_oov(fsgs, fsg);
 143  
 144      /* Add silence transitions and alternate words. */
 145      if (cmd_ln_boolean_r(ps_search_config(fsgs), "-fsgusefiller")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2021-02-25 09:45:36, 4.8 KB) [[attachment:pocketsphinx-patch.diff]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.