diff options
| author | historia <historiavg@proton.me> | 2026-08-20 16:17:57 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-20 16:17:57 -0400 |
| commit | 4d3530f63730b47870d25629802c0c41f0c9ffae (patch) | |
| tree | 319311a69f7ace225a4ef0f8040fc22857c304b8 /audiobook.py | |
| parent | c2afb9d01b854bb709345c1b33bdba741daceb25 (diff) | |
| download | tts-audiobook-generator-4d3530f63730b47870d25629802c0c41f0c9ffae.tar.gz | |
feat: audio.cpp backend support
Diffstat (limited to 'audiobook.py')
| -rwxr-xr-x | audiobook.py | 90 |
1 files changed, 65 insertions, 25 deletions
diff --git a/audiobook.py b/audiobook.py index b8c445e..c2639ce 100755 --- a/audiobook.py +++ b/audiobook.py @@ -27,7 +27,14 @@ from converter.converter import ( setup_directories, setup_logging, ) -from converter.tts import VOICE_MODE_CLONE, VOICE_MODE_CUSTOM, normalize_language +from converter.tts import ( + BACKEND_AUDIOCPP, + BACKEND_FASTER, + BACKEND_GRADIO, + VOICE_MODE_CLONE, + VOICE_MODE_CUSTOM, + normalize_language, +) def main() -> None: @@ -37,14 +44,17 @@ def main() -> None: formatter_class=argparse.RawDescriptionHelpFormatter, epilog=""" Examples: - # Use custom voice (default - Vivian speaker) + # Use the Qwen Gradio demo with a custom voice (default - Vivian speaker) python audiobook.py - # Use voice cloning with reference audio + # Use the Qwen Gradio demo with voice cloning from reference audio python audiobook.py --clone path/to/reference.wav # Use the faster-qwen3-tts server (voice cloning, configured server-side) - python audiobook.py --faster + python audiobook.py --backend faster [--voice NAME] + + # Use an audio.cpp audiocpp_server (speaker mode, or a server-side voice) + python audiobook.py --backend audiocpp [--voice NAME] """ ) @@ -105,23 +115,26 @@ Examples: ) parser.add_argument( - "--faster", - action="store_true", - help=("Use a faster-qwen3-tts OpenAI-compatible server instead of the Qwen " - "Gradio demos (5-10x faster inference via CUDA graphs). Always voice " - "cloning: the reference audio and transcript are configured on the " - "server itself (see the 'Faster backend' section of the README).") + "--backend", + choices=[BACKEND_GRADIO, BACKEND_FASTER, BACKEND_AUDIOCPP], + default=config.BACKEND, + help=("TTS server to talk to: the Qwen3-TTS Gradio demos (gradio), the " + "faster-qwen3-tts OpenAI-compatible server (faster), or an " + "audio.cpp audiocpp_server (audiocpp). Defaults to the BACKEND " + "setting in converter/config.py (gradio).") ) parser.add_argument( - "--faster-voice", + "--voice", type=str, default=None, metavar="NAME", - help=("Voice entry to request from the faster server's voice config " - "(default: the FASTER_VOICE setting in converter/config.py, " - "typically 'default'). Must match a key in the server's voices.json, " - "or 'default' when the server was started with --ref-audio.") + help=("Voice to request from a server-side voice configuration. faster: " + "a key in the server's voices.json ('default' when it was started " + "with --ref-audio). audiocpp: a voice_preset or voice_dir entry " + "(cloning); without this flag the audiocpp backend uses a built-in " + "CustomVoice speaker instead. Not used by the gradio backend " + "(use converter/config.py SPEAKER or --clone there).") ) parser.add_argument( @@ -137,23 +150,44 @@ Examples: if args.speed <= 0: parser.error(f"--speed must be a positive number (got {args.speed:g})") - if args.faster: + if args.backend == BACKEND_FASTER: if args.clone: - print("[WARNING] --clone is ignored with --faster: the faster backend " + print("[WARNING] --clone is ignored with --backend faster: that backend " "always uses voice cloning, and the reference voice is configured " - "on the faster server (see README)") + "on the server (see README)") args.clone = None if args.transcription or args.no_transcription: print("[WARNING] --transcription/--no-transcription are ignored with " - "--faster: the reference transcript is configured on the faster " + "--backend faster: the reference transcript is configured on the " "server (--ref-text or voices.json, see README)") args.transcription = None args.no_transcription = False if args.language is not None: - print("[WARNING] --language is ignored with --faster: language is " - "configured on the faster server (see README)") + print("[WARNING] --language is ignored with --backend faster: language " + "is configured on the server (see README)") args.language = None + elif args.backend == BACKEND_AUDIOCPP: + if args.clone: + print("[WARNING] --clone is ignored with --backend audiocpp: cloning " + "uses a voice configured on the server (voice_presets or " + "voice_dir in its config); select it with --voice (see README)") + args.clone = None + if args.transcription or args.no_transcription: + print("[WARNING] --transcription/--no-transcription are ignored with " + "--backend audiocpp: the reference transcript is configured on " + "the server (see README)") + args.transcription = None + args.no_transcription = False + if args.language is not None: + try: + args.language = normalize_language(args.language) + except ValueError as exc: + parser.error(str(exc)) else: + if args.voice is not None: + parser.error("--voice requires --backend faster or audiocpp; the " + "gradio backend uses built-in speakers " + "(converter/config.py SPEAKER) or --clone") if args.language is not None: try: args.language = normalize_language(args.language) @@ -167,10 +201,16 @@ Examples: setup_logging(debug=args.debug) setup_directories() + if args.backend == BACKEND_FASTER: + voice_mode = VOICE_MODE_CLONE + elif args.backend == BACKEND_AUDIOCPP: + voice_mode = VOICE_MODE_CLONE if args.voice else VOICE_MODE_CUSTOM + else: + voice_mode = VOICE_MODE_CLONE if args.clone else VOICE_MODE_CUSTOM + try: converter = AudiobookConverter( - voice_mode=VOICE_MODE_CLONE if (args.clone or args.faster) - else VOICE_MODE_CUSTOM, + voice_mode=voice_mode, voice_clone_ref_audio=args.clone, voice_clone_ref_text=args.transcription, skip_transcription=args.no_transcription, @@ -178,8 +218,8 @@ Examples: single_file=args.single_file, output_format=args.format, language=args.language, - faster=args.faster, - faster_voice=args.faster_voice, + backend=args.backend, + voice=args.voice, debug=args.debug, ) ok = converter.run() |
