public static void ps_search_base_reinit(ps_search_t search, Pointer <dict_t> dictionary,
                                          Pointer <dict2pid_t> d2p)
 {
     dict.dict_free(search.dict);
     dict2pid.dict2pid_free(search.d2p);
     /* FIXME: _retain() should just return NULL if passed NULL. */
     if (dictionary.IsNonNull)
     {
         search.dict        = dict.dict_retain(dictionary);
         search.start_wid   = dict.dict_startwid(dictionary);
         search.finish_wid  = dict.dict_finishwid(dictionary);
         search.silence_wid = dict.dict_silwid(dictionary);
         search.n_words     = dict.dict_size(dictionary);
     }
     else
     {
         search.dict      = PointerHelpers.NULL <dict_t>();
         search.start_wid = search.finish_wid = search.silence_wid = -1;
         search.n_words   = 0;
     }
     if (d2p.IsNonNull)
     {
         search.d2p = dict2pid.dict2pid_retain(d2p);
     }
     else
     {
         search.d2p = PointerHelpers.NULL <dict2pid_t>();
     }
 }
        public static trigger_adapter trigger_create(string modelDir, string dictionaryFile, bool verboseLogging)
        {
            //printf("            creating recognizer\n");

            Pointer <ps_decoder_t> ps     = PointerHelpers.NULL <ps_decoder_t>();
            Pointer <cmd_ln_t>     config = PointerHelpers.NULL <cmd_ln_t>();

            config = cmd_ln.cmd_ln_init(config, pocketsphinx.ps_args(), 1,
                                        "-hmm", modelDir,
                                        "-dict", dictionaryFile,
                                        "-verbose", "y");

            ps = pocketsphinx.ps_init(config);

            cmd_ln.cmd_ln_free_r(config);

            trigger_adapter adapter = new trigger_adapter();

            adapter.ps = ps;
            adapter.user_is_speaking = false;
            adapter.last_hyp         = PointerHelpers.Malloc <byte>(512);
            adapter.last_hyp[0]      = 0;

            return(adapter);
        }
        public static void ps_expand_file_config(Pointer <ps_decoder_t> ps, Pointer <byte> arg, Pointer <byte> extra_arg,
                                                 Pointer <byte> hmmdir, Pointer <byte> file)
        {
            Pointer <byte> val;

            if ((val = cmd_ln.cmd_ln_str_r(ps.Deref.config, arg)).IsNonNull)
            {
                cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, val);
            }
            else if (hmmdir.IsNull)
            {
                cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, PointerHelpers.NULL <byte>());
            }
            else
            {
                string         path = System.IO.Path.Combine(cstring.FromCString(hmmdir), cstring.FromCString(file));
                Pointer <byte> tmp  = cstring.ToCString(path);
                if (FILE.file_exists(tmp))
                {
                    cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, tmp);
                }
                else
                {
                    cmd_ln.cmd_ln_set_str_extra_r(ps.Deref.config, extra_arg, PointerHelpers.NULL <byte>());
                }
                ckd_alloc.ckd_free(tmp);
            }
        }
        public static List <arg_t> POCKETSPHINX_DICT_OPTIONS()
        {
            List <arg_t> args = new List <arg_t>();

            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-dict"),
                type  = cmd_ln.REQARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Main pronunciation dictionary (lexicon) input file")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-fdict"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Noise word pronunciation dictionary input file")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-dictcase"),
                type  = cmd_ln.ARG_BOOLEAN,
                deflt = cstring.ToCString("no"),
                doc   = cstring.ToCString("Dictionary is case sensitive (NOTE: case insensitivity applies to ASCII characters only)")
            });
            return(args);
        }
        public static Pointer <hash_iter_t> hash_table_iter_next(Pointer <hash_iter_t> itor)
        {
            /* If there is an entry, walk down its list. */
            if (itor.Deref.ent.IsNonNull)
            {
                itor.Deref.ent = itor.Deref.ent.Deref.next;
            }

            /* If we got to the end of the chain, or we had no entry, scan
             * forward in the table to find the next non-empty bucket. */
            if (itor.Deref.ent.IsNull)
            {
                while (itor.Deref.idx < itor.Deref.ht.Deref.size &&
                       itor.Deref.ht.Deref.table[itor.Deref.idx].key.IsNull)
                {
                    ++itor.Deref.idx;
                }

                /* If we did not find one then delete the iterator and
                 * return NULL. */
                if (itor.Deref.idx == itor.Deref.ht.Deref.size)
                {
                    hash_table_iter_free(itor);
                    return(PointerHelpers.NULL <hash_iter_t>());
                }
                /* Otherwise use this next entry. */
                itor.Deref.ent = itor.Deref.ht.Deref.table + itor.Deref.idx;
                /* Increase idx for the next time around. */
                ++itor.Deref.idx;
            }
            return(itor);
        }
        public static int ps_set_keyphrase(Pointer <ps_decoder_t> ps, Pointer <byte> name, Pointer <byte> keyphrase)
        {
            ps_search_t search;

            search = kws_search.kws_search_init(name, keyphrase, PointerHelpers.NULL <byte>(), ps.Deref.config, ps.Deref.acmod, ps.Deref.dict, ps.Deref.d2p);
            return(set_search_internal(ps, search));
        }
        public static Pointer <gnode_t> hash_table_tolist(Pointer <hash_table_t> h, BoxedValue <int> count)
        {
            Pointer <gnode_t>      g;
            Pointer <hash_entry_t> e;
            int i, j;

            g = PointerHelpers.NULL <gnode_t>();

            j = 0;
            for (i = 0; i < h.Deref.size; i++)
            {
                e = h.Deref.table.Point(i);

                if (e.Deref.key.IsNonNull)
                {
                    g = glist.glist_add_ptr(g, (object)e);
                    j++;

                    for (e = e.Deref.next; e.IsNonNull; e = e.Deref.next)
                    {
                        g = glist.glist_add_ptr(g, (object)e);
                        j++;
                    }
                }
            }

            if (count != null)
            {
                count.Val = j;
            }

            return(g);
        }
Beispiel #8
0
        public static void compress_right_context_tree(Pointer <dict2pid_t> d2p,
                                                       Pointer <Pointer <Pointer <ushort> > > rdiph_rc)
        {
            int n_ci;
            int b, l, r;
            Pointer <ushort>     rmap;
            Pointer <ushort>     tmpssid;
            Pointer <short>      tmpcimap;
            Pointer <bin_mdef_t> mdef = d2p.Deref.mdef;
            uint alloc;

            n_ci = mdef.Deref.n_ciphone;

            tmpssid  = ckd_alloc.ckd_calloc <ushort>(n_ci);
            tmpcimap = ckd_alloc.ckd_calloc <short>(n_ci);

            d2p.Deref.rssid =
                (Pointer <Pointer <xwdssid_t> >)ckd_alloc.ckd_calloc <Pointer <xwdssid_t> >(mdef.Deref.n_ciphone);
            alloc = (uint)(mdef.Deref.n_ciphone * 8);

            for (b = 0; b < n_ci; b++)
            {
                d2p.Deref.rssid[b] =
                    (Pointer <xwdssid_t>)ckd_alloc.ckd_calloc_struct <xwdssid_t>(mdef.Deref.n_ciphone);
                alloc += (uint)(mdef.Deref.n_ciphone * 20);

                for (l = 0; l < n_ci; l++)
                {
                    rmap = rdiph_rc[b][l];
                    compress_table(rmap, tmpssid, tmpcimap, mdef.Deref.n_ciphone);

                    for (r = 0; r < mdef.Deref.n_ciphone && tmpssid[r] != s3types.BAD_S3SSID;
                         r++)
                    {
                        ;
                    }

                    if (tmpssid[0] != s3types.BAD_S3SSID)
                    {
                        d2p.Deref.rssid[b][l].ssid = ckd_alloc.ckd_calloc <ushort>(r);
                        tmpssid.MemCopyTo(d2p.Deref.rssid[b][l].ssid, r);
                        d2p.Deref.rssid[b][l].cimap =
                            ckd_alloc.ckd_calloc <short>(mdef.Deref.n_ciphone);
                        tmpcimap.MemCopyTo(d2p.Deref.rssid[b][l].cimap, (mdef.Deref.n_ciphone));
                        d2p.Deref.rssid[b][l].n_ssid = r;
                    }
                    else
                    {
                        d2p.Deref.rssid[b][l].ssid   = PointerHelpers.NULL <ushort>();
                        d2p.Deref.rssid[b][l].cimap  = PointerHelpers.NULL <short>();
                        d2p.Deref.rssid[b][l].n_ssid = 0;
                    }
                }
            }

            err.E_INFO(string.Format("Allocated {0} bytes ({1} KiB) for word-final triphones\n",
                                     (int)alloc, (int)alloc / 1024));
            ckd_alloc.ckd_free(tmpssid);
            ckd_alloc.ckd_free(tmpcimap);
        }
        public static List <arg_t> POCKETSPHINX_DEBUG_OPTIONS()
        {
            List <arg_t> args = new List <arg_t>();

            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-logfn"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("File to write log messages in")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-mfclogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log feature files to")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-rawlogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log raw audio files to")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-senlogdir"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Directory to log senone score files to")
            });
            return(args);
        }
        public static T hash_table_enter_bkey <T>(Pointer <hash_table_t> h, Pointer <byte> key, uint len, T val)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(enter(h, hash, key, len, val, 0));
        }
        public static object hash_table_replace_bkey(Pointer <hash_table_t> h, Pointer <byte> key, uint len, object val)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(enter(h, hash, key, len, val, 1));
        }
        public static object hash_table_delete_bkey(Pointer <hash_table_t> h, Pointer <byte> key, uint len)
        {
            uint           hash;
            Pointer <byte> str;

            str  = makekey(key, len, PointerHelpers.NULL <byte>());
            hash = key2hash(h, str);
            ckd_alloc.ckd_free(str);

            return(delete(h, hash, key, len));
        }
Beispiel #13
0
        public static Pointer <byte> cmd_ln_str_r(Pointer <cmd_ln_t> cmdln, Pointer <byte> name)
        {
            Pointer <cmd_ln_val_t> val;

            val = cmd_ln_access_r(cmdln, name);
            if (val.IsNull || val.Deref.val == null)
            {
                return(PointerHelpers.NULL <byte>());
            }
            return((Pointer <byte>)val.Deref.val);
        }
Beispiel #14
0
        public static void phone_loop_search_free_renorm(phone_loop_search_t pls)
        {
            Pointer <gnode_t> gn;

            for (gn = pls.renorm; gn.IsNonNull; gn = glist.gnode_next(gn))
            {
                ckd_alloc.ckd_free((Pointer <phone_loop_renorm_t>)glist.gnode_ptr(gn));
            }
            glist.glist_free(pls.renorm);
            pls.renorm = PointerHelpers.NULL <gnode_t>();
        }
Beispiel #15
0
        public static Pointer <cmd_ln_val_t> cmd_ln_access_r(Pointer <cmd_ln_t> cmdln, Pointer <byte> name)
        {
            BoxedValue <object> val = new BoxedValue <object>();

            if (hash_table.hash_table_lookup(cmdln.Deref.ht, name, val) < 0)
            {
                err.E_ERROR(string.Format("Unknown argument: {0}\n", cstring.FromCString(name)));
                return(PointerHelpers.NULL <cmd_ln_val_t>());
            }
            return((Pointer <cmd_ln_val_t>)val.Val);
        }
Beispiel #16
0
        public void TestPointerReallocMalloc()
        {
            Pointer <int> pointer = PointerHelpers.NULL <int>();

            pointer = pointer.Realloc(4);

            for (int c = 0; c < 4; c++)
            {
                pointer[c] = c;
            }
            for (int c = 0; c < 4; c++)
            {
                Assert.AreEqual(c, pointer[c]);
            }
        }
Beispiel #17
0
        public static void kws_detections_reset(Pointer <kws_detections_t> detections)
        {
            Pointer <gnode_t> gn;

            if (detections.Deref.detect_list.IsNull)
            {
                return;
            }

            for (gn = detections.Deref.detect_list; gn.IsNonNull; gn = glist.gnode_next(gn))
            {
                ckd_alloc.ckd_free((Pointer <kws_detection_t>)glist.gnode_ptr(gn));
            }
            glist.glist_free(detections.Deref.detect_list);
            detections.Deref.detect_list = PointerHelpers.NULL <gnode_t>();
        }
Beispiel #18
0
        public static Pointer <byte> ckd_salloc(Pointer <byte> orig)
        {
            uint           len;
            Pointer <byte> buf;

            if (orig.IsNull)
            {
                return(PointerHelpers.NULL <byte>());
            }

            len = cstring.strlen(orig) + 1;
            buf = ckd_malloc <byte>(len);

            cstring.strcpy(buf, orig);
            return(buf);
        }
Beispiel #19
0
        public static ps_search_t phone_loop_search_init(
            Pointer <cmd_ln_t> config,
            Pointer <acmod_t> acmod,
            Pointer <dict_t> dict)
        {
            phone_loop_search_t pls;

            /* Allocate and initialize. */
            pls = new phone_loop_search_t();
            pocketsphinx.ps_search_init((ps_search_t)pls, phone_loop_search_funcs,
                                        pocketsphinx.PS_SEARCH_TYPE_PHONE_LOOP, pocketsphinx.PS_DEFAULT_PL_SEARCH,
                                        config, acmod, dict, PointerHelpers.NULL <dict2pid_t>());
            phone_loop_search_reinit((ps_search_t)pls, pls.dict, pls.d2p);

            return((ps_search_t)pls);
        }
Beispiel #20
0
        public static Pointer <byte> arg_resolve_env(Pointer <byte> str)
        {
            BoxedValue <Pointer <byte> > resolved_str = new BoxedValue <Pointer <byte> >(PointerHelpers.NULL <byte>());
            Pointer <byte>    env_name = PointerHelpers.Malloc <byte>(100);
            Pointer <byte>    env_val;
            BoxedValue <uint> alloced = new BoxedValue <uint>(0);
            Pointer <byte>    i       = str;
            Pointer <byte>    j;

            /* calculate required resolved_str size */
            do
            {
                j = cstring.strstr(i, cstring.ToCString("$("));
                if (j.IsNonNull)
                {
                    if (j != i)
                    {
                        strnappend(resolved_str, alloced, i, checked ((uint)(j - i)));
                        i = j;
                    }
                    j = cstring.strchr(i + 2, (byte)')');
                    if (j.IsNonNull)
                    {
                        if (j - (i + 2) < 100)
                        {
                            cstring.strncpy(env_name, i + 2, checked ((uint)(j - (i + 2))));
                            env_name[j - (i + 2)] = (byte)'\0';
                            env_val = PointerHelpers.NULL <byte>();
                        }
                        i = j + 1;
                    }
                    else
                    {
                        /* unclosed, copy and skip */
                        j = i + 2;
                        strnappend(resolved_str, alloced, i, checked ((uint)(j - i)));
                        i = j;
                    }
                }
                else
                {
                    strappend(resolved_str, alloced, i);
                }
            } while (j.IsNonNull);

            return(resolved_str.Val);
        }
Beispiel #21
0
        public static Pointer <byte> kws_detections_hyp_str(Pointer <kws_detections_t> detections, int frame, int delay)
        {
            Pointer <gnode_t> gn;
            Pointer <byte>    c;
            int            len;
            Pointer <byte> hyp_str;

            len = 0;
            for (gn = detections.Deref.detect_list; gn.IsNonNull; gn = glist.gnode_next(gn))
            {
                Pointer <kws_detection_t> det = (Pointer <kws_detection_t>)glist.gnode_ptr(gn);
                if (det.Deref.ef < frame - delay)
                {
                    len += (int)cstring.strlen(det.Deref.keyphrase) + 1;
                }
            }

            if (len == 0)
            {
                return(PointerHelpers.NULL <byte>());
            }

            hyp_str = ckd_alloc.ckd_calloc <byte>(len);
            c       = hyp_str;
            bool cMoved = false; // LOGAN modified

            for (gn = detections.Deref.detect_list; gn.IsNonNull; gn = glist.gnode_next(gn))
            {
                Pointer <kws_detection_t> det = (Pointer <kws_detection_t>)glist.gnode_ptr(gn);
                if (det.Deref.ef < frame - delay)
                {
                    det.Deref.keyphrase.MemCopyTo(c, (int)cstring.strlen(det.Deref.keyphrase));
                    c      += cstring.strlen(det.Deref.keyphrase);
                    c.Deref = (byte)' ';
                    c++;
                    cMoved = true;
                }
            }

            if (cMoved)
            {
                c--;
                c.Deref = (byte)'\0';
            }

            return(hyp_str);
        }
        public static void ps_free_searches(Pointer <ps_decoder_t> ps)
        {
            if (ps.Deref.searches.IsNonNull)
            {
                Pointer <hash_iter_t> search_it;
                for (search_it = hash_table.hash_table_iter(ps.Deref.searches); search_it.IsNonNull;
                     search_it = hash_table.hash_table_iter_next(search_it))
                {
                    ps_search_free((ps_search_t)hash_table.hash_entry_val(search_it.Deref.ent));
                }

                hash_table.hash_table_free(ps.Deref.searches);
            }

            ps.Deref.searches = PointerHelpers.NULL <hash_table_t>();
            ps.Deref.search   = null;
        }
        public static T enter <T>(Pointer <hash_table_t> h, uint hash, Pointer <byte> key, uint len, T val, int replace)
        {
            Pointer <hash_entry_t> cur, _new;

            if ((cur = lookup(h, hash, key, len)).IsNonNull)
            {
                object oldval;
                /* Key already exists. */
                oldval = cur.Deref.val;
                if (replace != 0)
                {
                    /* Replace the pointer if replacement is requested,
                     * because this might be a different instance of the same
                     * string (this verges on magic, sorry) */
                    cur.Deref.key = key;
                    cur.Deref.val = val;
                }
                return((T)oldval);
            }

            cur = h.Deref.table.Point(hash);
            if (!cur.Deref.key.IsNonNull)
            {
                /* Empty slot at hashed location; add this entry */
                cur.Deref.key = key;
                cur.Deref.len = len;
                cur.Deref.val = val;

                /* Added by ARCHAN at 20050515. This allows deletion could work. */
                cur.Deref.next = PointerHelpers.NULL <hash_entry_t>();
            }
            else
            {
                /* Key collision; create new entry and link to hashed location */
                _new            = ckd_alloc.ckd_calloc_struct <hash_entry_t>(1);
                _new.Deref.key  = key;
                _new.Deref.len  = len;
                _new.Deref.val  = val;
                _new.Deref.next = cur.Deref.next;
                cur.Deref.next  = _new;
            }
            ++h.Deref.inuse;

            return(val);
        }
Beispiel #24
0
        public static void fe_warp_affine_set_parameters(Pointer <byte> param_str, float sampling_rate)
        {
            Pointer <byte> tok;
            Pointer <byte> seps           = cstring.ToCString(" \t");
            Pointer <byte> temp_param_str = PointerHelpers.Malloc <byte>(256);
            int            param_index    = 0;

            nyquist_frequency = sampling_rate / 2;
            if (param_str.IsNull)
            {
                is_neutral = 1;
                return;
            }
            /* The new parameters are the same as the current ones, so do nothing. */
            if (cstring.strcmp(param_str, p_str) == 0)
            {
                return;
            }
            is_neutral = 0;
            cstring.strcpy(temp_param_str, param_str);
            parameters.MemSet(0, N_PARAM);
            cstring.strcpy(p_str, param_str);
            /* FIXME: strtok() is not re-entrant... */
            tok = cstring.strtok(temp_param_str, seps);
            while (tok.IsNonNull)
            {
                parameters[param_index++] = (float)strfuncs.atof_c(tok);
                tok = cstring.strtok(PointerHelpers.NULL <byte>(), seps);
                if (param_index >= N_PARAM)
                {
                    break;
                }
            }
            if (tok.IsNonNull)
            {
                err.E_INFO(string.Format("Affine warping takes up to two arguments, {0} ignored.\n", cstring.FromCString(tok)));
            }
            if (parameters[0] == 0)
            {
                is_neutral = 1;
                err.E_INFO
                    ("Affine warping cannot have slope zero, warping not applied.\n");
            }
        }
        public static Pointer <ps_decoder_t> ps_init(Pointer <cmd_ln_t> config)
        {
            Pointer <ps_decoder_t> ps;

            if (config.IsNull)
            {
                err.E_ERROR("No configuration specified");
                return(PointerHelpers.NULL <ps_decoder_t>());
            }

            ps = ckd_alloc.ckd_calloc_struct <ps_decoder_t>(1);
            ps.Deref.refcount = 1;
            if (ps_reinit(ps, config) < 0)
            {
                ps_free(ps);
                return(PointerHelpers.NULL <ps_decoder_t>());
            }
            return(ps);
        }
Beispiel #26
0
        public static Pointer <lineiter_t> lineiter_next_plain(Pointer <lineiter_t> li)
        {
            /* We are reading the next line */
            li.Deref.lineno++;

            /* Read a line and check for EOF. */
            if (li.Deref.fh.fgets(li.Deref.buf, li.Deref.bsiz).IsNull)
            {
                lineiter_free(li);
                return(PointerHelpers.NULL <lineiter_t>());
            }

            /* If we managed to read the whole thing, then we are done
             * (this will be by far the most common result). */
            li.Deref.len = (int)cstring.strlen(li.Deref.buf);
            if (li.Deref.len < li.Deref.bsiz - 1 || li.Deref.buf[li.Deref.len - 1] == '\n')
            {
                return(li);
            }

            /* Otherwise we have to reallocate and keep going. */
            while (true)
            {
                li.Deref.bsiz *= 2;
                li.Deref.buf   = ckd_alloc.ckd_realloc(li.Deref.buf, (uint)li.Deref.bsiz);
                /* If we get an EOF, we are obviously done. */
                if (li.Deref.fh.fgets(li.Deref.buf + li.Deref.len, li.Deref.bsiz - li.Deref.len).IsNull)
                {
                    li.Deref.len += (int)cstring.strlen(li.Deref.buf + li.Deref.len);
                    return(li);
                }
                li.Deref.len += (int)cstring.strlen(li.Deref.buf + li.Deref.len);
                /* If we managed to read the whole thing, then we are done. */
                if (li.Deref.len < li.Deref.bsiz - 1 || li.Deref.buf[li.Deref.len - 1] == '\n')
                {
                    return(li);
                }
            }

            /* Shouldn't get here. */
            return(li);
        }
Beispiel #27
0
        public static Pointer <cmd_ln_t> cmd_ln_init(Pointer <cmd_ln_t> inout_cmdln, Pointer <arg_t> defn, int strict, params string[] args)
        {
            Pointer <Pointer <byte> > f_argv;
            int f_argc = args.Length;

            if (f_argc % 2 != 0)
            {
                err.E_ERROR("Number of arguments must be even!\n");
                return(PointerHelpers.NULL <cmd_ln_t>());
            }

            // C# variable arguments simplify this function immensely
            f_argv = ckd_alloc.ckd_calloc <Pointer <byte> >(f_argc);
            for (int c = 0; c < f_argc; c++)
            {
                f_argv[c] = cstring.ToCString(args[c]);
            }

            return(parse_options(inout_cmdln, defn, f_argc, f_argv, strict));
        }
        public static List <arg_t> POCKETSPHINX_KWS_OPTIONS()
        {
            List <arg_t> args = new List <arg_t>();

            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-keyphrase"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("Keyphrase to spot")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-kws"),
                type  = cmd_ln.ARG_STRING,
                deflt = PointerHelpers.NULL <byte>(),
                doc   = cstring.ToCString("(MODIFIED - DO NOT USE) A file with keyphrases to spot, one per line")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-kws_plp"),
                type  = cmd_ln.ARG_FLOATING,
                deflt = cstring.ToCString("1e-1"),
                doc   = cstring.ToCString("Phone loop probability for keyphrase spotting")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-kws_delay"),
                type  = cmd_ln.ARG_INTEGER,
                deflt = cstring.ToCString("10"),
                doc   = cstring.ToCString("Delay to wait for best detection score")
            });
            args.Add(new arg_t()
            {
                name  = cstring.ToCString("-kws_threshold"),
                type  = cmd_ln.ARG_FLOATING,
                deflt = cstring.ToCString("1e-30"),
                doc   = cstring.ToCString("(MODIFIED - DO NOT USE) Threshold for p(hyp)/p(alternatives) ratio")
            });
            return(args);
        }
Beispiel #29
0
        public static int cmd_ln_free_r(Pointer <cmd_ln_t> cmdln)
        {
            if (cmdln.IsNull)
            {
                return(0);
            }
            if (--cmdln.Deref.refcount > 0)
            {
                return(cmdln.Deref.refcount);
            }

            if (cmdln.Deref.ht.IsNonNull)
            {
                Pointer <gnode_t> entries;
                Pointer <gnode_t> gn;
                BoxedValue <int>  n = new BoxedValue <int>();
                entries = hash_table.hash_table_tolist(cmdln.Deref.ht, n);
                for (gn = entries; gn.IsNonNull; gn = glist.gnode_next(gn))
                {
                    Pointer <hash_entry_t> e = (Pointer <hash_entry_t>)glist.gnode_ptr(gn);
                    cmd_ln_val_free((Pointer <cmd_ln_val_t>)e.Deref.val);
                }
                glist.glist_free(entries);
                hash_table.hash_table_free(cmdln.Deref.ht);
                cmdln.Deref.ht = PointerHelpers.NULL <hash_table_t>();
            }

            if (cmdln.Deref.f_argv.IsNonNull)
            {
                int i;
                for (i = 0; i < cmdln.Deref.f_argc; ++i)
                {
                    ckd_alloc.ckd_free(cmdln.Deref.f_argv[i]);
                }
                ckd_alloc.ckd_free(cmdln.Deref.f_argv);
                cmdln.Deref.f_argv = PointerHelpers.NULL <Pointer <byte> >();
                cmdln.Deref.f_argc = 0;
            }
            ckd_alloc.ckd_free(cmdln);
            return(0);
        }
        public static void ps_search_init(
            ps_search_t search,
            ps_searchfuncs_t vt,
            Pointer <byte> type,
            Pointer <byte> name,
            Pointer <cmd_ln_t> config,
            Pointer <acmod_t> acousticmod,
            Pointer <dict_t> dictionary,
            Pointer <dict2pid_t> d2p)
        {
            search.vt   = vt;
            search.name = ckd_alloc.ckd_salloc(name);
            search.type = ckd_alloc.ckd_salloc(type);

            search.config = config;
            search.acmod  = acousticmod;
            if (d2p.IsNonNull)
            {
                search.d2p = dict2pid.dict2pid_retain(d2p);
            }
            else
            {
                search.d2p = PointerHelpers.NULL <dict2pid_t>();
            }
            if (dictionary.IsNonNull)
            {
                search.dict        = dict.dict_retain(dictionary);
                search.start_wid   = dict.dict_startwid(dictionary);
                search.finish_wid  = dict.dict_finishwid(dictionary);
                search.silence_wid = dict.dict_silwid(dictionary);
                search.n_words     = dict.dict_size(dictionary);
            }
            else
            {
                search.dict      = PointerHelpers.NULL <dict_t>();
                search.start_wid = search.finish_wid = search.silence_wid = -1;
                search.n_words   = 0;
            }
        }