colab-user commited on
Commit
3e50eb1
·
1 Parent(s): 6099ac3

fix processor

Browse files
Files changed (1) hide show
  1. app/services/processor.py +27 -15
app/services/processor.py CHANGED
@@ -197,10 +197,31 @@ class Processor:
197
  raise ValueError("Empty audio")
198
  duration = len(y) / sr
199
 
200
- # 3: Diarization
201
- logger.info("Step 3: Running diarization...")
202
-
203
- diarization: DiarizationResult = await DiarizationService.diarize_async(wav_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
 
205
  diarization_segments = diarization.segments or []
206
  speakers = diarization.speakers or []
@@ -238,7 +259,7 @@ class Processor:
238
 
239
  speakers = list(speaker_map.values())
240
 
241
- # 5. NORMALIZE ROLES
242
  speaker_duration = defaultdict(float)
243
  for seg in diarization_segments:
244
  speaker_duration[seg.speaker] += seg.end - seg.start
@@ -261,16 +282,7 @@ class Processor:
261
 
262
  logger.info(f"roles(mapped) = {roles}")
263
 
264
- # 7: Transcribe segments after diarization
265
- logger.info("Step 7: Running ASR with external VAD batch...")
266
-
267
- asr_result = await TranscriptionService.transcribe_with_words_async(
268
- audio_array=y,
269
- model_name=model_name,
270
- language=language,
271
- vad_options=True
272
- )
273
-
274
  text, raw_words = normalize_asr_result(asr_result)
275
 
276
  processed_segments: List[TranscriptSegment] = []
 
197
  raise ValueError("Empty audio")
198
  duration = len(y) / sr
199
 
200
+ # 3: Run diarization and ASR in parallel
201
+ logger.info("Step 3+7: Running diarization and ASR in parallel...")
202
+
203
+ diarization_task = asyncio.create_task(
204
+ DiarizationService.diarize_async(wav_path)
205
+ )
206
+
207
+ asr_task = asyncio.create_task(
208
+ TranscriptionService.transcribe_with_words_async(
209
+ audio_array=y,
210
+ model_name=model_name,
211
+ language=language,
212
+ vad_options=True
213
+ )
214
+ )
215
+
216
+ try:
217
+ diarization, asr_result = await asyncio.gather(
218
+ diarization_task,
219
+ asr_task
220
+ )
221
+ except Exception:
222
+ logger.exception("Parallel AI processing failed")
223
+ raise
224
+
225
 
226
  diarization_segments = diarization.segments or []
227
  speakers = diarization.speakers or []
 
259
 
260
  speakers = list(speaker_map.values())
261
 
262
+ # 5. Normalize roles
263
  speaker_duration = defaultdict(float)
264
  for seg in diarization_segments:
265
  speaker_duration[seg.speaker] += seg.end - seg.start
 
282
 
283
  logger.info(f"roles(mapped) = {roles}")
284
 
285
+ # 7: Normalize asr result
 
 
 
 
 
 
 
 
 
286
  text, raw_words = normalize_asr_result(asr_result)
287
 
288
  processed_segments: List[TranscriptSegment] = []