Athspi commited on
Commit
c463c7e
·
verified ·
1 Parent(s): e4d42f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -70,6 +70,7 @@ def transcribe_audio_with_gemini(audio_file):
70
  [HH:MM:SS] Sentence 1
71
  [HH:MM:SS] Sentence 2
72
  ...
 
73
  Respond only with the transcription and timestamps. Do not add explanations or extra text.
74
  """
75
 
@@ -98,12 +99,26 @@ def generate_subtitles(transcription):
98
 
99
  # Convert timestamp to SRT format
100
  start_time = timestamp[1:-1] # Remove brackets
101
- end_time = "00:00:05" # Placeholder: 5 seconds per line
 
 
102
 
103
  srt_subtitles += f"{i}\n{start_time},000 --> {end_time},000\n{text}\n\n"
104
 
105
  return srt_subtitles
106
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  def translate_srt(srt_text, target_language):
108
  """Translate an SRT file while preserving timestamps using a magic prompt."""
109
  # Magic prompt for translation
 
70
  [HH:MM:SS] Sentence 1
71
  [HH:MM:SS] Sentence 2
72
  ...
73
+ Ensure the timestamps are accurate and correspond to the start of each sentence.
74
  Respond only with the transcription and timestamps. Do not add explanations or extra text.
75
  """
76
 
 
99
 
100
  # Convert timestamp to SRT format
101
  start_time = timestamp[1:-1] # Remove brackets
102
+ start_seconds = time_to_seconds(start_time)
103
+ end_seconds = start_seconds + 5 # Placeholder: 5 seconds per line
104
+ end_time = seconds_to_time(end_seconds)
105
 
106
  srt_subtitles += f"{i}\n{start_time},000 --> {end_time},000\n{text}\n\n"
107
 
108
  return srt_subtitles
109
 
110
+ def time_to_seconds(time_str):
111
+ """Convert HH:MM:SS to seconds."""
112
+ hh, mm, ss = map(int, time_str.split(":"))
113
+ return hh * 3600 + mm * 60 + ss
114
+
115
+ def seconds_to_time(seconds):
116
+ """Convert seconds to HH:MM:SS."""
117
+ hh = seconds // 3600
118
+ mm = (seconds % 3600) // 60
119
+ ss = seconds % 60
120
+ return f"{hh:02}:{mm:02}:{ss:02}"
121
+
122
  def translate_srt(srt_text, target_language):
123
  """Translate an SRT file while preserving timestamps using a magic prompt."""
124
  # Magic prompt for translation