LiKenun commited on
Commit
62f7cb7
·
1 Parent(s): 06d7b2d

WebVTT timestamp interpolation proof-of-concept

Browse files
Files changed (1) hide show
  1. notebooks/web-vtt.ipynb +13 -6
notebooks/web-vtt.ipynb CHANGED
@@ -13,6 +13,7 @@
13
  "metadata": {},
14
  "outputs": [],
15
  "source": [
 
16
  "from functools import partial\n",
17
  "from html import escape\n",
18
  "from io import BytesIO\n",
@@ -20,6 +21,8 @@
20
  "from itertools import chain\n",
21
  "import re\n",
22
  "from webvtt import Caption, WebVTT\n",
 
 
23
  "\n",
24
  "display_html = partial(display_html, raw=True)"
25
  ]
@@ -30,7 +33,9 @@
30
  "metadata": {},
31
  "outputs": [],
32
  "source": [
33
- "FILE_PATH = #"
 
 
34
  ]
35
  },
36
  {
@@ -73,9 +78,10 @@
73
  "\n",
74
  " <strong>Caption</strong> #344\n",
75
  " <ul>\n",
76
- " <li><strong>Time:</strong> 01:01:19.390–01:01:22.370</li>\n",
77
  " <li><strong>Speaker:</strong> CUNY Tech Prep (CTP)</li>\n",
78
- " <li><strong>Speech:</strong> <em>Alright. You can pick the rooms. Now go into your rooms.</em></li>\n",
 
79
  " </ul>\n",
80
  " "
81
  ]
@@ -88,15 +94,16 @@
88
  "speaker_speech_pattern = re.compile('(?:([^:]+): )?(.*)')\n",
89
  "\n",
90
  "match web_vtt.captions[343]:\n",
91
- " case Caption(identifier=identifier, start=start, end=end, text=text):\n",
92
  " match speaker_speech_pattern.search(text).groups():\n",
93
  " case (speaker, speech):\n",
94
  " display_html(f\"\"\"\n",
95
  " <strong>Caption</strong> #{identifier}\n",
96
  " <ul>\n",
97
- " <li><strong>Time:</strong> {start}–{end}</li>\n",
98
  " <li><strong>Speaker:</strong> {escape(speaker)}</li>\n",
99
- " <li><strong>Speech:</strong> <em>{escape(speech)}</em></li>\n",
 
100
  " </ul>\n",
101
  " \"\"\")"
102
  ]
 
13
  "metadata": {},
14
  "outputs": [],
15
  "source": [
16
+ "from datetime import datetime, timedelta\n",
17
  "from functools import partial\n",
18
  "from html import escape\n",
19
  "from io import BytesIO\n",
 
21
  "from itertools import chain\n",
22
  "import re\n",
23
  "from webvtt import Caption, WebVTT\n",
24
+ "from webvtt.models import Timestamp\n",
25
+ "from zoneinfo import ZoneInfo\n",
26
  "\n",
27
  "display_html = partial(display_html, raw=True)"
28
  ]
 
33
  "metadata": {},
34
  "outputs": [],
35
  "source": [
36
+ "FILE_PATH = 'GMT20250411-223535_Recording.transcript.vtt'\n",
37
+ "TIME_ZONE = ZoneInfo(\"America/New_York\")\n",
38
+ "BASE_TIME = datetime(2025, 4, 11, hour=22, minute=35, second=35, tzinfo=ZoneInfo(\"GMT\")).astimezone(TIME_ZONE)"
39
  ]
40
  },
41
  {
 
78
  "\n",
79
  " <strong>Caption</strong> #344\n",
80
  " <ul>\n",
81
+ " <li><strong>Start:</strong> Friday, April 11, 2025, 07:36:54 PM EDT</li>\n",
82
  " <li><strong>Speaker:</strong> CUNY Tech Prep (CTP)</li>\n",
83
+ " <li><strong>Speech:</strong> Alright. You can pick the rooms. Now go into your rooms.</li>\n",
84
+ " <li><strong>End:</strong> Friday, April 11, 2025, 07:36:57 PM EDT</li>\n",
85
  " </ul>\n",
86
  " "
87
  ]
 
94
  "speaker_speech_pattern = re.compile('(?:([^:]+): )?(.*)')\n",
95
  "\n",
96
  "match web_vtt.captions[343]:\n",
97
+ " case Caption(identifier=identifier, start_time=start_time, end_time=end_time, text=text):\n",
98
  " match speaker_speech_pattern.search(text).groups():\n",
99
  " case (speaker, speech):\n",
100
  " display_html(f\"\"\"\n",
101
  " <strong>Caption</strong> #{identifier}\n",
102
  " <ul>\n",
103
+ " <li><strong>Start:</strong> {BASE_TIME + timedelta(**start_time.__dict__):%A, %B %d, %Y, %I:%M:%S %p %Z}</li>\n",
104
  " <li><strong>Speaker:</strong> {escape(speaker)}</li>\n",
105
+ " <li><strong>Speech:</strong> {escape(speech)}</li>\n",
106
+ " <li><strong>End:</strong> {BASE_TIME + timedelta(**end_time.__dict__):%A, %B %d, %Y, %I:%M:%S %p %Z}</li>\n",
107
  " </ul>\n",
108
  " \"\"\")"
109
  ]