-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_durations.py
More file actions
45 lines (37 loc) · 1.36 KB
/
Copy pathadd_durations.py
File metadata and controls
45 lines (37 loc) · 1.36 KB
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
import os
import json
from pathlib import Path
from pydub import AudioSegment
# Load existing manifest
with open("./commentary_audio_v2/manifest.json") as f:
manifest = json.load(f)
# Add durations to each file
for item in manifest["files"]:
mp3_path = Path(f"./commentary_audio_v2/{item['filename']}")
if mp3_path.exists():
audio = AudioSegment.from_mp3(mp3_path)
item["duration_sec"] = round(len(audio) / 1000, 2)
else:
item["duration_sec"] = 8.0 # Default estimate
# Save updated manifest
with open("./commentary_audio_v2/manifest.json", "w") as f:
json.dump(manifest, f, indent=2)
print("Updated manifest with durations:")
for item in manifest["files"]:
print(f" [{item['index']:02d}] {item['time']:5.1f}s - {item['duration_sec']:4.1f}s duration - {item['text'][:40]}...")
# Also create a JS-compatible version
js_data = {
"commentaryTiming": []
}
for item in manifest["files"]:
js_data["commentaryTiming"].append({
"index": item["index"],
"triggerTime": item["time"],
"duration": item["duration_sec"],
"text": item["text"],
"filename": item["filename"],
"subjectId": item["subjectId"]
})
with open("./data/commentary_timing.json", "w") as f:
json.dump(js_data, f, indent=2)
print(f"\nCreated commentary_timing.json with {len(js_data['commentaryTiming'])} entries")