File size: 1,002 Bytes
c22b544 | 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 | 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])
|