#!/usr/bin/env python # import required modules: # note that the path to the module htkmfc must be included in the # PYTHONPATH environment variable. # import os import sys import numpy as np # define binary read mode parameters # MODE_READ_BINARY = "rb" SAMPLE_SIZE = sys.getsizeof(np.int16) # main: this is the main function of this Python # def main(argv): # open the file for binary I/O # fp = open(argv[1], MODE_READ_BINARY) # demonstrate seek in Python # fp.seek(0, os.SEEK_SET) # read 10 short integers: do this by reading the correct number of bytes # num_samps = int(10) data = fp.read(num_samps * SAMPLE_SIZE) # close the file # fp.close() # convert the binary data to floats # buf_f = np.frombuffer(data, dtype = "short", count = num_samps).astype(np.float64) # convert the binary data to short ints # buf_s = np.frombuffer(data, dtype = "short", count = num_samps).astype(np.int16) # print the values # for i in range(0,len(buf_s)): print("buf[%d] = short: %d, float: %f" % (i, buf_s[i], buf_f[i])) # begin gracefully # if __name__ == "__main__": main(sys.argv[0:]) # # end of file