qqwjq1981 commited on
Commit
d3b873d
·
verified ·
1 Parent(s): 44dc269

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -1371,19 +1371,30 @@ def upload_and_manage(file, target_language, process_mode):
1371
 
1372
  logger.info(f"Using audio path: {audio_path}, output video path: {output_video_path}, voiceover path: {voiceover_path}")
1373
 
1374
- # Step 1: Transcribe audio from uploaded media file and get timestamps
1375
- logger.info("Transcribing audio...")
1376
- transcription_json, source_language = transcribe_segments_with_scribe(file.name)
 
 
 
 
 
 
 
 
 
 
 
1377
  logger.info(f"Transcription completed. Detected source language: {source_language}")
1378
 
1379
  transcription_json_merged = transcription_json
1380
  #post_edit_transcribed_segments(transcription_json, file.name, source_language)
 
1381
  # Step 2: Translate the transcription
1382
  logger.info(f"Translating transcription from {source_language} to {target_language}...")
1383
  translated_json_raw = translate_text(transcription_json_merged, source_language, target_language)
1384
  logger.info(f"Translation completed. Number of translated segments: {len(translated_json_raw)}")
1385
 
1386
-
1387
  translated_json = apply_adaptive_speed(translated_json_raw, source_language, target_language, process_mode)
1388
 
1389
  # New: Save the translated JSON to a file
 
1371
 
1372
  logger.info(f"Using audio path: {audio_path}, output video path: {output_video_path}, voiceover path: {voiceover_path}")
1373
 
1374
+ # Step 1: Segment audio from the uploaded video/audio file
1375
+ logger.info("Segmenting audio...")
1376
+ temp_audio_for_vad, speech_segments, seg_error = segment_audio_from_video(file.name)
1377
+ if seg_error:
1378
+ raise Exception(f"Audio segmentation failed: {seg_error}")
1379
+ if not speech_segments:
1380
+ raise Exception("No speech segments detected in the audio.")
1381
+ logger.info(f"Audio segmentation completed. Found {len(speech_segments)} segments.")
1382
+
1383
+ # Step 2: Transcribe the segments using ElevenLabs Scribe
1384
+ logger.info("Transcribing audio segments...")
1385
+ transcription_json, source_language, trans_error = transcribe_segments_with_scribe(temp_audio_for_vad, speech_segments)
1386
+ if trans_error:
1387
+ raise Exception(f"Transcription failed: {trans_error}")
1388
  logger.info(f"Transcription completed. Detected source language: {source_language}")
1389
 
1390
  transcription_json_merged = transcription_json
1391
  #post_edit_transcribed_segments(transcription_json, file.name, source_language)
1392
+
1393
  # Step 2: Translate the transcription
1394
  logger.info(f"Translating transcription from {source_language} to {target_language}...")
1395
  translated_json_raw = translate_text(transcription_json_merged, source_language, target_language)
1396
  logger.info(f"Translation completed. Number of translated segments: {len(translated_json_raw)}")
1397
 
 
1398
  translated_json = apply_adaptive_speed(translated_json_raw, source_language, target_language, process_mode)
1399
 
1400
  # New: Save the translated JSON to a file