Complete processing pipeline: from input to audio output Args: input_path (str): Input path (URL, PDF or TXT file) output_dir (str): Output directory language (str): Language for the podcast script ('en' or 'zh')
(
input_path: str, output_dir: str = "examples", language: str = "zh"
)
| 359 | |
| 360 | |
| 361 | def process_input_to_audio( |
| 362 | input_path: str, output_dir: str = "examples", language: str = "zh" |
| 363 | ): |
| 364 | """Complete processing pipeline: from input to audio output |
| 365 | |
| 366 | Args: |
| 367 | input_path (str): Input path (URL, PDF or TXT file) |
| 368 | output_dir (str): Output directory |
| 369 | language (str): Language for the podcast script ('en' or 'zh') |
| 370 | """ |
| 371 | |
| 372 | # Select prompts based on language |
| 373 | if language == "zh": |
| 374 | prompt_audio_speaker1 = ZH_PROMPT_AUDIO_SPEAKER1 |
| 375 | prompt_text_speaker1 = ZH_PROMPT_TEXT_SPEAKER1 |
| 376 | prompt_audio_speaker2 = ZH_PROMPT_AUDIO_SPEAKER2 |
| 377 | prompt_text_speaker2 = ZH_PROMPT_TEXT_SPEAKER2 |
| 378 | else: # Default to English |
| 379 | prompt_audio_speaker1 = EN_PROMPT_AUDIO_SPEAKER1 |
| 380 | prompt_text_speaker1 = EN_PROMPT_TEXT_SPEAKER1 |
| 381 | prompt_audio_speaker2 = EN_PROMPT_AUDIO_SPEAKER2 |
| 382 | prompt_text_speaker2 = EN_PROMPT_TEXT_SPEAKER2 |
| 383 | |
| 384 | print(f"Using {language} prompts:") |
| 385 | print(f"Speaker 1: {prompt_audio_speaker1}") |
| 386 | print(f"Speaker 2: {prompt_audio_speaker2}") |
| 387 | |
| 388 | # 1. Parse input content |
| 389 | print("Step 1: Parse input content") |
| 390 | content = parse_input_content(input_path) |
| 391 | if not content: |
| 392 | print("Unable to parse input content, program terminated") |
| 393 | return |
| 394 | |
| 395 | print(f"Content parsed successfully, content preview: {content[:200]}...") |
| 396 | |
| 397 | # 2. Use large model to generate dialogue script |
| 398 | print("\nStep 2: Generate dialogue script") |
| 399 | script = generate_podcast_script(content, language=language) |
| 400 | if not script: |
| 401 | print("Dialogue script generation failed, program terminated") |
| 402 | return |
| 403 | |
| 404 | # 3. Load TTS model |
| 405 | print("\nStep 3: Load TTS model") |
| 406 | tokenizer, model, spt = load_model(MODEL_PATH, SPT_CONFIG_PATH, SPT_CHECKPOINT_PATH) |
| 407 | spt = spt.to(device) |
| 408 | model = model.to(device) |
| 409 | print("TTS model loading completed") |
| 410 | |
| 411 | # 4. Prepare TTS input data with language-specific prompts |
| 412 | print("\nStep 4: Prepare TTS input data") |
| 413 | items = [ |
| 414 | { |
| 415 | "text": script, |
| 416 | "base_path": "", |
| 417 | "prompt_audio_speaker1": prompt_audio_speaker1, |
| 418 | "prompt_text_speaker1": prompt_text_speaker1, |
no test coverage detected