VoxForge
Hi!
I am making a Java application that uses HTK recognition.
I need Java to create feature files in HTK format from
certain data that the program handles. So, I need from
Java to create new files and add data to them. I have
a MatLab function that does this I want:
function escribeHTK(file,d,fp,tc)
fid = fopen(file,'w','b');
[nf,nv] = size(d);
fwrite(fid,nf,'long'); % write frame count
fwrite(fid,round(fp*1.E7),'long'); % write frame period (in 100 ns units)
nby = nv * 4;
fwrite(fid,nby,'short'); % write byte count
fwrite(fid,tc,'short'); % write type code
fwrite(fid,d.','float'); % write data array
fclose(fid);
But I need to do that in Java. The function above generates
a file whose data format is IEEE754 floating-point big-endian.
Then, the function adds a header and append the features, where
every variable has its own precission.
I have tried to deploy the function above in Java defining
every variable correspondingly (short, long...) and after,
writing in an output stream the header and features using
the method "floatToIntBits" from "Float" class. This
did not work because HTk does not recognize the resulting files
(as if the file does not have the correct format).
I do not want to use MatLab Builder JA so, what can I do?
Anybody knows how can I deploy it?
Thanks a lot.
Regards.
--- (Edited on 12/17/2010 5:49 pm [GMT-0600] by iloes) ---
I use the next method for JAVA.
Regards ;).
public void generaFichero(double[][] samples, String file, double samplePeriod, int paramKind) throws FileNotFoundException, IOException {
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
int nf = samples.length;
int nv = samples[0].length;
out.writeInt(nf);
out.writeInt((int) (samplePeriod * 1e7));
out.writeShort(4 * nv);
out.writeShort(paramKind);
for (int n = 0; n < nf; n++) {
for (int m = 0; m < nv; m++) {
out.writeFloat((float) samples[n][m]);
}
}
out.close();
}
--- (Edited on 3/6/2011 6:46 am [GMT-0600] by iloes) ---