Skip to content

Commit 84e9ea0

Browse files
committed
More cleanup
1 parent 69c0745 commit 84e9ea0

3 files changed

Lines changed: 33 additions & 35 deletions

File tree

test_transcribe_audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def test_has_timestamps_mistral_format(self):
308308

309309
# Test range format
310310
transcription_with_range = "[ 0m0s694ms - 0m3s34ms ] This is a test"
311-
self.assertTrue(has_timestamps(transcription_with_range))
311+
self.assertFalse(has_timestamps(transcription_with_range))
312312

313313
# Test without timestamps
314314
transcription_without_timestamps = "Hello world this is just text"

transcribe_audio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def transcribe_segment(self, audio_path: str, language: str = None, store_result
202202
return ""
203203

204204

205-
timestamp_pattern = r'\[\s*\d+m\d+s\d+ms\s*(?:-\s*\d+m\d+s\d+ms\s*)?\]'
205+
timestamp_pattern = r'(.+?)\s+\[\s*(\d+m\d+s\d+ms)\s*]'
206206

207207

208208
def has_timestamps(transcription: str) -> bool:

web_server.py

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -254,44 +254,12 @@ def _process_job(self, job: TranscriptionJob):
254254
segment_srt_files = {}
255255
segment_info = {}
256256

257-
def process_segment(segment_data):
258-
"""Process a single segment and return the results"""
259-
i, segment = segment_data
260-
logger.info(f"Processing segment {i+1}/{len(segments)}")
261-
262-
# Transcribe segment
263-
transcription = self.transcriber.transcribe_segment(
264-
segment['path'],
265-
language=job.language if job.language != "auto" else None,
266-
max_retries=3
267-
)
268-
269-
# Convert to SRT entries
270-
srt_entries = process_transcription_to_srt(transcription, 0, False)
271-
272-
# Generate SRT file for segment
273-
segment_srt_filename = f"segment_{i+1:03d}.srt"
274-
segment_srt_path = os.path.join(temp_dir, segment_srt_filename)
275-
276-
with open(segment_srt_path, 'w', encoding='utf-8') as f:
277-
for entry in srt_entries:
278-
srt_text = SRTFormatter.create_srt_entry(
279-
entry['index'],
280-
entry['start_time'],
281-
entry['end_time'],
282-
entry['text']
283-
)
284-
f.write(srt_text)
285-
286-
return i, segment_srt_path, segment
287-
288257
# Use ThreadPoolExecutor for parallel processing
289-
290258
with ThreadPoolExecutor(max_workers=5) as executor:
291259
# Submit all segment processing tasks
292260
future_to_index = {}
293261
for i, segment in enumerate(segments):
294-
future = executor.submit(process_segment, (i, segment))
262+
future = executor.submit(self._process_segment, i, segment, job, temp_dir, len(segments))
295263
future_to_index[future] = i
296264

297265
# Collect results as they complete
@@ -353,6 +321,36 @@ def process_segment(segment_data):
353321
# Send callback if specified
354322
self._send_callback(job)
355323

324+
def _process_segment(self, i, segment, job, temp_dir, total_segments):
325+
"""Process a single segment and return the results"""
326+
logger.info(f"Processing segment {i+1}/{total_segments}")
327+
328+
# Transcribe segment
329+
transcription = self.transcriber.transcribe_segment(
330+
segment['path'],
331+
language=job.language if job.language != "auto" else None,
332+
max_retries=3
333+
)
334+
335+
# Convert to SRT entries
336+
srt_entries = process_transcription_to_srt(transcription, 0, False)
337+
338+
# Generate SRT file for segment
339+
segment_srt_filename = f"segment_{i+1:03d}.srt"
340+
segment_srt_path = os.path.join(temp_dir, segment_srt_filename)
341+
342+
with open(segment_srt_path, 'w', encoding='utf-8') as f:
343+
for entry in srt_entries:
344+
srt_text = SRTFormatter.create_srt_entry(
345+
entry['index'],
346+
entry['start_time'],
347+
entry['end_time'],
348+
entry['text']
349+
)
350+
f.write(srt_text)
351+
352+
return i, segment_srt_path, segment
353+
356354
def _generate_outputs(self, srt_entries: List[Dict], format_spec: str,
357355
output_dir: Path, base_name: str) -> Dict[str, str]:
358356
"""Generate output files based on format specification"""

0 commit comments

Comments
 (0)