Monday, February 3, 2014

Small tricks to remember

Most of the times the output of SPTK or HTS are in binary file format. To read the binary files in Python using NumPy. Use the following command:
## commands for reading the binary file in python
import numpy as np
#to read a binary file
a = np.fromfile("file.name",dtype='<f4',count=-1)

Here dtype means datatype in general the size of datatype will be 32bit. Suppose if it is 16bit size then change the '<f4' to '<f2'.
Suppose if you want to write an ASCII file into a binary file then use the following command:
#to write into a binary file
np.ndarray.tofile(a,"file.name")

Where "a" can be a list or matrix with float numbers.

No comments: