smartwang commited on
Commit
471c527
·
1 Parent(s): 265bb42
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -296,23 +296,25 @@ def extract_voice_clone_prompt(ref_audio,ref_text,use_xvector_only):
296
  # return None, "错误:未启用 '仅使用 x-vector' 时需要参考文本。"
297
  model_size = "base"
298
  logger.info(f"开始 Whisper 语音识别任务。模型: {model_size}, 音频路径: {ref_audio}")
 
 
299
  try:
300
- model = load_whisper_model(model_size)
301
  # 使用 transcribe 方法进行转录
302
  # whisper 会自动处理音频加载和重采样
303
- result = model.transcribe(ref_audio)
304
  text = result["text"]
305
  logger.info(f"Whisper 识别完成。文本长度: {len(text)}")
306
- ref_text = text.strip()
307
  logger.error(f"Whisper 识别成功:{ref_text}")
308
- use_xvector_only = False
309
  except Exception as e:
310
  logger.error(f"Whisper 识别失败: {str(e)}", exc_info=True)
311
 
312
  voice_clone_prompt = tts.create_voice_clone_prompt(
313
  ref_audio=audio_tuple,
314
- ref_text=ref_text.strip() if ref_text else None,
315
- x_vector_only_mode=use_xvector_only
316
  )
317
  logger.info("参考音频特征提取完成。")
318
 
 
296
  # return None, "错误:未启用 '仅使用 x-vector' 时需要参考文本。"
297
  model_size = "base"
298
  logger.info(f"开始 Whisper 语音识别任务。模型: {model_size}, 音频路径: {ref_audio}")
299
+ r_text = ref_text
300
+ uxo = use_xvector_only
301
  try:
302
+ whisper_model = load_whisper_model(model_size)
303
  # 使用 transcribe 方法进行转录
304
  # whisper 会自动处理音频加载和重采样
305
+ result = whisper_model.transcribe(ref_audio)
306
  text = result["text"]
307
  logger.info(f"Whisper 识别完成。文本长度: {len(text)}")
308
+ r_text = text.strip()
309
  logger.error(f"Whisper 识别成功:{ref_text}")
310
+ uxo = False
311
  except Exception as e:
312
  logger.error(f"Whisper 识别失败: {str(e)}", exc_info=True)
313
 
314
  voice_clone_prompt = tts.create_voice_clone_prompt(
315
  ref_audio=audio_tuple,
316
+ ref_text=r_text.strip() if r_text else None,
317
+ x_vector_only_mode=uxo
318
  )
319
  logger.info("参考音频特征提取完成。")
320