Skip to content

Instantly share code, notes, and snippets.

@leechanwoo
Last active May 9, 2018 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leechanwoo/1544a76b41fb57abe8ade3084a603bc2 to your computer and use it in GitHub Desktop.
Save leechanwoo/1544a76b41fb57abe8ade3084a603bc2 to your computer and use it in GitHub Desktop.
import csv
import os
hand_path = '/Users/chanwoo/Documents/sources/IEMOCAP_full_release/Session1/dialog/MOCAP_hand/'
label_path = '/Users/chanwoo/Documents/sources/IEMOCAP_full_release/Session1/dialog/EmoEvaluation/'
filename = 'Ses01F_impro01.txt'
with open(os.path.join(hand_path, filename), 'r') as f:
raw_text = f.read()
lines = raw_text.split('\n')
rows = []
for l in lines[2:]:
try:
rows.append(list(map(float, l.split(' '))))
except:
continue
with open(os.path.join(label_path, filename), 'r') as f:
raw_label = f.read()
with open(os.path.join(label_path, 'joint_dataset.csv'), 'w') as csvfile:
writer = csv.writer(csvfile, delimiter=',')
label_lines = raw_label.split('\n\n')
for l in label_lines[:100]:
if not l:
continue
if l[0] == "%":
continue
row = l.split('\n')[0].split('\t')
emotion = row[2]
stime, etime = tuple(map(float, row[0][1:-1].split(' - ')))
record = {'start_time': stime, 'end_time':etime, 'emotion': emotion}
for f in filter(lambda r: stime < r[1] and r[1] < etime, rows):
writer.writerow([emotion] + f[2:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment