diff options
Diffstat (limited to 'app/converter/converter.py')
| -rw-r--r-- | app/converter/converter.py | 76 |
1 files changed, 16 insertions, 60 deletions
diff --git a/app/converter/converter.py b/app/converter/converter.py index cef4808..4c1ffad 100644 --- a/app/converter/converter.py +++ b/app/converter/converter.py @@ -140,7 +140,7 @@ class AudiobookConverter: speed: float = 1.0, single_file: bool = False, output_format: str = config.AUDIO_FORMAT, language: Optional[str] = None, backend: str = config.BACKEND, voice: Optional[str] = None, debug: bool = False, - chunk: bool = False, model_id: Optional[str] = None, + model_id: Optional[str] = None, instructions: Optional[str] = None, request_options: Optional[Dict[str, str]] = None): if speed <= 0: @@ -162,12 +162,6 @@ class AudiobookConverter: self.backend = backend self.voice = voice self.debug = bool(debug) - # Client-side chunking: the qwen and faster backends always chunk - # (their servers do one generation per request and silently truncate - # long text). The audio.cpp server chunks long text itself, so it - # defaults to one request per chapter; --chunk forces client-side - # chunking on top (possible needless double-chunking). - self.client_chunks = bool(chunk) or backend != BACKEND_AUDIOCPP # Voice design / style instruction and free-form request options # (audio.cpp only): forwarded to AudioCppTTSClient, which validates # them against the server-hosted model at connect time. @@ -185,7 +179,6 @@ class AudiobookConverter: # instructions describe or style the voice, request_options pass # per-model controls through to the server. self.tts = AudioCppTTSClient(voice=voice, language=self.language, - chunk_text=self.client_chunks, model_id=model_id, instructions=instructions, request_options=self.request_options) @@ -437,10 +430,9 @@ class AudiobookConverter: and every request/response is logged. """ total_chunks = len(chunks) - if self.client_chunks: - print(f"\n{'=' * 50}") - print(f"PROCESSING {total_chunks} CHUNKS") - print(f"{'=' * 50}") + print(f"\n{'=' * 50}") + print(f"PROCESSING {total_chunks} CHUNKS") + print(f"{'=' * 50}") results: Dict[int, Optional[Path]] = {} for chunk_num, chunk_text in enumerate(chunks, 1): @@ -461,8 +453,7 @@ class AudiobookConverter: destination = f" -> {copied.name}" if copied else "" logger.debug("Chunk %d/%d response in %.1fs%s", chunk_num, total_chunks, elapsed, destination) - if self.client_chunks: - print(f"[OK] Chunk {chunk_num:3d}/{total_chunks} completed") + print(f"[OK] Chunk {chunk_num:3d}/{total_chunks} completed") logger.info("+ Chunk %d/%d completed", chunk_num, total_chunks) else: logger.error("Chunk %d/%d failed; aborting the remaining chunks", @@ -476,25 +467,16 @@ class AudiobookConverter: break successful_chunks = sum(1 for path in results.values() if path) - if self.client_chunks: - print(f"\n{'=' * 50}") - print("CHUNK PROCESSING COMPLETE") - print(f"Successful: {successful_chunks}/{total_chunks}") - print(f"{'=' * 50}") + print(f"\n{'=' * 50}") + print("CHUNK PROCESSING COMPLETE") + print(f"Successful: {successful_chunks}/{total_chunks}") + print(f"{'=' * 50}") logger.info("Chunk processing completed: %d/%d chunks", successful_chunks, total_chunks) return results def _chapter_chunks(self, text: str) -> List[str]: - """Split chapter text into TTS requests. - - Client-side chunking splits into CHUNK_SIZE-word chunks (qwen and - faster always; audio.cpp only with --chunk). Otherwise (audio.cpp - default) the whole text is one request and the server does its own - long-form chunking. - """ - if self.client_chunks: - return chunking.split_into_chunks(text) - return [text] if text.strip() else [] + """Split chapter text into CHUNK_SIZE-word TTS requests.""" + return chunking.split_into_chunks(text) def _convert_text(self, text: str, output_path: Path, start_time: float, speed: Optional[float] = None, @@ -530,31 +512,14 @@ class AudiobookConverter: chunk_sizes = [len(chunk.split()) for chunk in chunks] avg_chunk_size = sum(chunk_sizes) / len(chunk_sizes) - if len(chunks) == 1: - logger.info("Sending the whole text as one request (%d words; " - "the server chunks long text itself)", - chunk_sizes[0]) - else: - logger.info("Split into %d chunks (avg %.0f words per chunk)", - total_chunks, avg_chunk_size) + logger.info("Split into %d chunks (avg %.0f words per chunk)", + total_chunks, avg_chunk_size) backend_labels = { BACKEND_FASTER: "faster TTS API", BACKEND_AUDIOCPP: "audio.cpp server", } backend = backend_labels.get(self.backend, "Qwen API") - if self.client_chunks: - print(f"[INFO] Processing {total_chunks} chunks via {backend}...") - else: - # The whole request is sent at once and the server does its - # own long-form chunking, so the chunk vocabulary does not - # apply; warn that this one request can take a very long time. - subject = (f"chapter {chapter[0]}/{chapter[1]}" - if chapter is not None else "text") - print(f"[INFO] Sending the {subject} to the {backend} as a " - "single request...") - print("[NOTE] It is expected for this to take a very long " - "time: the server synthesizes the entire request before " - "returning any audio.") + print(f"[INFO] Processing {total_chunks} chunks via {backend}...") results = self._synthesize_chunks(chunks, debug_dir=debug_dir) successful_chunks = sum(1 for path in results.values() if path) @@ -578,11 +543,8 @@ class AudiobookConverter: logger.info("Chapter %d/%d converted in %dm %ds (%d/%d chunks)", chapter[0], chapter[1], minutes, seconds, successful_chunks, total_chunks) - if self.client_chunks: - print(f"[INFO] Chapter {chapter[0]}/{chapter[1]} converted " - f"({successful_chunks}/{total_chunks} chunks)") - else: - print(f"[INFO] Chapter {chapter[0]}/{chapter[1]} converted") + print(f"[INFO] Chapter {chapter[0]}/{chapter[1]} converted " + f"({successful_chunks}/{total_chunks} chunks)") else: logger.info("Conversion completed in %dm %ds: %s", minutes, seconds, output_path) else: @@ -621,12 +583,6 @@ class AudiobookConverter: print(f"Speaker: {config.SPEAKER}") if self.request_options: print(f"Request options: {self.request_options}") - if self.client_chunks: - print("Chunking: client-side (--chunk; the server also chunks " - "long text itself, so this may double-chunk)") - else: - print("Chunking: server-side (one request per chapter; " - "--chunk forces client-side chunking)") print(f"Language: {self.language}") else: api_url = (config.CLONE_API_URL if self.voice_mode == VOICE_MODE_CLONE |
