-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_caption.py
More file actions
35 lines (31 loc) · 1002 Bytes
/
generate_caption.py
File metadata and controls
35 lines (31 loc) · 1002 Bytes
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
def doa_to_str(doa):
if doa < -0.6:
direction = "on the left side"
elif doa < -0.2:
direction = "in the front-left"
elif doa < 0.2:
direction = "in front"
elif doa < 0.6:
direction = "in the front-right"
else:
direction = "on the right side"
return direction
def spatialize_caption(caption, doa, with_spatial):
# 文字列整形
caption = caption.strip()
caption = caption.rstrip('.')
caption = caption.strip()
caption = caption[0].upper() + caption[1:] if caption else caption
# doaに基づく方向表現
direction = doa_to_str(doa)
if with_spatial:
return f"{caption} {direction}."
else:
return f"{caption}."
def meta_to_caption(metas, with_spatial=True, sort_on_doa=False):
lis = [
(spatialize_caption(meta["caption"], meta["doa"], with_spatial), meta["doa"])
for meta in metas
]
lis.sort(key=lambda x:x[1])
return " ".join([x[0] for x in lis])