-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtk2npy.py
36 lines (24 loc) · 904 Bytes
/
htk2npy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import struct
import sys
import numpy as np
def main():
# assert len(sys.argv) > 1, "File paths must be provided."
# fin = open(sys.argv[1], "rb")
fin = open(0, "rb")
n_samples, sample_period = struct.unpack(">ii", fin.read(8))
sample_size, parm_kind = struct.unpack(">hh", fin.read(4))
n_states = sample_size // 4
print(f"[INFO] n_samples = {n_samples}")
print(f"[INFO] sample_period = {sample_period}")
print(f"[INFO] sample_size = {sample_size}")
print(f"[INFO] parm_kind = {parm_kind}")
print(f"[INFO] n_states = {n_states}")
state_posts = np.zeros((n_samples, n_states))
for i in range(n_samples):
state_post = struct.unpack(">" + "f" * n_states, fin.read(sample_size))
state_posts[i] = state_post
print(state_posts)
print(state_posts.shape)
fin.close()
if __name__ == "__main__":
main()