Hack sphinx3module

From Sphinx

Open python/_sphinx3module.c and replace sphinx3_process_raw() with:

static PyObject *
sphinx3_process_raw(PyObject *self, PyObject *args)
{

    PyObject *str;
    int16 *data;
    int32 nsamps;
    mfcc_t **cep_block, ***feat_block;
    int32 nframes;
    char *uttid = NULL;

    if (!PyArg_ParseTuple(args, "O|s", &str, &uttid))
	    return NULL;
    if ((data = (int16 *)PyString_AsString(str)) == NULL)
	    return NULL;
    nsamps = PyString_Size(str)/2;

    if (fe_process_utt(fe, data, nsamps, &cep_block, &nframes) == -1) {
	    PyErr_SetString(PyExc_ValueError, "Problem in fe_process_utt()");
	    return NULL;
    }
    feat_block = feat_array_alloc(kbcore_fcb(decoder.kbcore),nframes);

    /* In theory we should check the return from this, but it will
     * always process the whole thing if both beginutt and endutt
     * are TRUE. */
    decoder.num_frames_entered
	    = feat_s2mfc2feat_block(kbcore_fcb(decoder.kbcore),
				    cep_block, nframes, TRUE, TRUE,
				    feat_block);
    ckd_free_2d((void **)cep_block);
    if (nframes == 0) {
	    PyErr_SetString(PyExc_ValueError, "Utterance too short");
	    ckd_free_2d((void **)feat_block);
	    return NULL;
    }

    /* Unfortunately we have to bypass s3_decode.c a bit here. */
    utt_decode_block(feat_block, nframes, &decoder.num_frames_decoded, &decoder.kb);
    feat_array_free(feat_block);

    /* Now get the results and return them. */
    return Py_BuildValue("i", nframes);

}
related