-
Notifications
You must be signed in to change notification settings - Fork 3
/
embed_generator.py
71 lines (48 loc) · 1.56 KB
/
embed_generator.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import os
import json
import numpy as np
import random
import argparse
import pickle
import math
embedding_list=[]
os.mkdir("Embeddings")
path = "Paths/"
mesh_files = os.listdir(path)
embed_c = 0
for file in mesh_files:
embedding_list=[]
# print("files in ",file)
# input("summa")
mesh_path1 = file[0:len(file)-8] + ".pickle"
mesh_path = file[0:len(file)-8] + "_new_simplified.pickle"
filepath = path + file
data=np.loadtxt(filepath, delimiter=',')
len_data = len(data)
source_list = []
listener_list = []
for j in range(len_data):
if(data[j][0]<0):
source_list.append(data[j][1:].tolist())
else:
listener_list.append(data[j][1:].tolist())
num_listeners = len(listener_list)
num_sources = len(source_list)
print("num sources ",num_sources," num listeners ",num_listeners)
for s in range(num_sources):
for l in range(num_listeners):
folder_name = "S"+ str(s+1)
wave_name = str(l+1) +".wav"
embeddings = [mesh_path,folder_name,wave_name,source_list[s],listener_list[l]]
embedding_list.append(embeddings)
print("embdiing_list", len(embedding_list))
filler = 256 - (len(embedding_list) % 256)
len_embed_list = len(embedding_list) -1
if(filler < 256):
for i in range(filler):
embedding_list.append(embedding_list[len_embed_list-filler+i])
print("embdiing_list123", len(embedding_list))
embeddings_pickle ="Embeddings/"+str(mesh_path1)
embed_c = embed_c + 1
with open(embeddings_pickle, 'wb') as f:
pickle.dump(embedding_list, f, protocol=2)