-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract_sick_features.py
43 lines (34 loc) · 1.33 KB
/
extract_sick_features.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
import imaginet.tts as tts
import cPickle as pickle
import sys
import numpy as np
import logging
import pydub
import base64
audiodir = "../data/coco/sick/wav/"
def synthesized(text):
return open("{}/{}.wav".format(audiodir, base64.urlsafe_b64encode(text)), 'rb').read()
def main():
logging.getLogger().setLevel('INFO')
for path in ["a", "b"]:
sentences_written = "../data/coco/sick/sentences_{}".format(path)
with open("{}.p".format(sentences_written), 'rb') as f:
logging.info("Loading {}.p".format(sentences_written))
sentences = pickle.load(f)
b = 0
while b < (len(sentences)/100):
batch = sentences[(b*100):((b+1)*100)]
spoken = [synthesized(sent) for sent in batch]
mfcc = [ tts.extract_mfcc(audio) for audio in spoken ]
dest = "../data/coco/sick/mfccs/{}_{}.npy".format(path, b)
np.save(dest, mfcc)
logging.info("Saved batch to {}".format(dest))
b += 1
batch = sentences[(b*100):]
spoken = [synthesized(sent) for sent in batch]
mfcc = [ tts.extract_mfcc(audio) for audio in spoken ]
dest = "../data/coco/sick/mfccs/{}_{}.npy".format(path, b)
np.save(dest, mfcc)
logging.info("Saved batch to {}".format(dest))
if __name__ == '__main__':
main()