qqwjq1981 commited on
Commit
2c764e8
·
verified ·
1 Parent(s): f67d3e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -474,12 +474,12 @@ def generate_voiceover_clone(translated_json, desired_duration, target_language,
474
  logger.error(msg)
475
  return None, msg, msg
476
 
477
- try:
478
- with wave.open(speaker_wav_path, 'rb') as wav_file:
479
- duration = wav_file.getnframes() / wav_file.getframerate()
480
- logger.info(f"🔊 Speaker WAV Duration: {duration:.2f}s")
481
- except Exception as e:
482
- logger.warning(f"⚠️ Could not read speaker WAV duration: {e}")
483
 
484
  speed_tts = calculate_speed(full_text, desired_duration)
485
  tts.tts_to_file(
 
474
  logger.error(msg)
475
  return None, msg, msg
476
 
477
+ # Truncate text based on max token assumption (~60 tokens)
478
+ MAX_TTS_TOKENS = 60
479
+ tokens = full_text.split() # crude token count
480
+ if len(tokens) > MAX_TTS_TOKENS:
481
+ logger.warning(f"⚠️ Text too long for TTS model ({len(tokens)} tokens). Truncating to {MAX_TTS_TOKENS} tokens.")
482
+ full_text = " ".join(tokens[:MAX_TTS_TOKENS])
483
 
484
  speed_tts = calculate_speed(full_text, desired_duration)
485
  tts.tts_to_file(