abinjoyal commited on
Commit
95aabd7
·
1 Parent(s): b04d544

feat: add backend dubbing and translation services for audio processing

Browse files
services/dubbing_service.py CHANGED
@@ -445,7 +445,7 @@ class VideoDubbingService:
445
 
446
  # 2. Smooth pitch-preserving speed adjustment capped at max 1.15x to preserve natural cadence
447
  if seg_duration > max_allowed_duration:
448
- speed_factor = max(1.0, min(1.15, seg_duration / max_allowed_duration))
449
  speed_path = os.path.join(temp_dir, f"seg_{idx}_speed.mp3")
450
  adjusted_path = adjust_audio_speed_ffmpeg(seg_audio_path, speed_path, speed_factor)
451
  if os.path.exists(adjusted_path) and os.path.getsize(adjusted_path) > 0 and adjusted_path != seg_audio_path:
@@ -458,7 +458,7 @@ class VideoDubbingService:
458
 
459
  # 3. STRICT NON-OVERLAPPING SEQUENTIAL ANCHORING:
460
  target_start_ms = int(orig_start * 1000)
461
- play_pos_ms = max(target_start_ms, last_end_ms + 40) if last_end_ms > 0 else target_start_ms
462
 
463
  needed_duration_ms = play_pos_ms + len(seg_audio)
464
  if len(master_audio) < needed_duration_ms:
 
445
 
446
  # 2. Smooth pitch-preserving speed adjustment capped at max 1.15x to preserve natural cadence
447
  if seg_duration > max_allowed_duration:
448
+ speed_factor = max(1.0, min(1.35, seg_duration / max_allowed_duration))
449
  speed_path = os.path.join(temp_dir, f"seg_{idx}_speed.mp3")
450
  adjusted_path = adjust_audio_speed_ffmpeg(seg_audio_path, speed_path, speed_factor)
451
  if os.path.exists(adjusted_path) and os.path.getsize(adjusted_path) > 0 and adjusted_path != seg_audio_path:
 
458
 
459
  # 3. STRICT NON-OVERLAPPING SEQUENTIAL ANCHORING:
460
  target_start_ms = int(orig_start * 1000)
461
+ play_pos_ms = max(target_start_ms, last_end_ms + 10) if last_end_ms > 0 else target_start_ms
462
 
463
  needed_duration_ms = play_pos_ms + len(seg_audio)
464
  if len(master_audio) < needed_duration_ms:
services/translation_service.py CHANGED
@@ -216,7 +216,7 @@ class TranslationService:
216
  is_large_gap = False
217
  if idx < len(segments) - 1:
218
  next_start = segments[idx + 1].get("start", 0)
219
- if next_start - seg.get("end", 0) > 0.8:
220
  is_large_gap = True
221
 
222
  if (is_sentence_end and current_duration >= 2.5) or current_duration >= 4.5 or is_large_gap or len(current_group) >= 8 or idx == len(segments) - 1:
 
216
  is_large_gap = False
217
  if idx < len(segments) - 1:
218
  next_start = segments[idx + 1].get("start", 0)
219
+ if next_start - seg.get("end", 0) > 1.2:
220
  is_large_gap = True
221
 
222
  if (is_sentence_end and current_duration >= 2.5) or current_duration >= 4.5 or is_large_gap or len(current_group) >= 8 or idx == len(segments) - 1: