@@ -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