sushant09 commited on
Commit
b6edc25
·
verified ·
1 Parent(s): dc3188c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -120,12 +120,18 @@ def process_audio(audio_path):
120
 
121
  output_lines = []
122
  display_text = ""
 
 
 
 
 
 
 
123
  for ts, para in transcript:
124
- timestamp = re.sub(r"^00:", "", ts.split(',')[0])
125
- timestamp = re.sub(r"^0", "", timestamp)
126
- out = f"{timestamp} {para}"
127
  output_lines.append(out)
128
- display_text += f"**{timestamp}** — {para}\n\n"
129
 
130
  output_txt_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
131
  with open(output_txt_path, "w", encoding="utf-8") as f:
@@ -145,7 +151,7 @@ demo = gr.Interface(
145
  gr.File(label="📥 Download TXT File")
146
  ],
147
  title="🕓 Audio Timestamp Generator",
148
- description="Upload an MP3 file. The tool splits the audio into chunks, transcribes them with timestamps using Whisper, and returns a timestamped transcript with downloadable TXT.",
149
  )
150
 
151
  if __name__ == "__main__":
 
120
 
121
  output_lines = []
122
  display_text = ""
123
+
124
+ def timestamp_to_seconds(ts):
125
+ h, m, s_ms = ts.split(":")
126
+ s, ms = s_ms.split(",")
127
+ total_seconds = int(h) * 3600 + int(m) * 60 + int(s)
128
+ return total_seconds # integer seconds only
129
+
130
  for ts, para in transcript:
131
+ seconds = timestamp_to_seconds(ts)
132
+ out = f"{seconds} {para}"
 
133
  output_lines.append(out)
134
+ display_text += f"**{seconds}s** — {para}\n\n"
135
 
136
  output_txt_path = tempfile.NamedTemporaryFile(delete=False, suffix=".txt").name
137
  with open(output_txt_path, "w", encoding="utf-8") as f:
 
151
  gr.File(label="📥 Download TXT File")
152
  ],
153
  title="🕓 Audio Timestamp Generator",
154
+ description="Upload an MP3 file. The tool splits the audio into chunks, transcribes them with Whisper, and returns a paragraph-wise timestamped transcript (timestamps in integer seconds).",
155
  )
156
 
157
  if __name__ == "__main__":