aboutsummaryrefslogtreecommitdiff
path: root/tests/test_converter.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-20 23:50:37 -0400
committerhistoria <historiavg@proton.me>2026-08-20 23:50:37 -0400
commit38c8fdcba7ce54ad0ad76be9ef0748df1c55ebc1 (patch)
tree911e031ee0e4b902fcd3954df3838a920416e8a3 /tests/test_converter.py
parent5c3df0a434059bd0d541bda35a51e49e3c44dd55 (diff)
downloadtts-audiobook-generator-38c8fdcba7ce54ad0ad76be9ef0748df1c55ebc1.tar.gz
feat: make_audiocpp_server_json.py takes an argument. remove chunk wording with audiocpp backend.
Diffstat (limited to 'tests/test_converter.py')
-rw-r--r--tests/test_converter.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_converter.py b/tests/test_converter.py
index 8402b30..d525c18 100644
--- a/tests/test_converter.py
+++ b/tests/test_converter.py
@@ -1,8 +1,11 @@
"""Tests for the audiobook converter orchestration helpers."""
+import io
import logging
import tempfile
+import time
import unittest
+from contextlib import redirect_stdout
from pathlib import Path
from unittest.mock import MagicMock, patch
@@ -181,6 +184,7 @@ class DebugDumpTests(unittest.TestCase):
self._debug_folder.start()
self.debug_root = Path(self._tmp.name)
self.converter = AudiobookConverter.__new__(AudiobookConverter)
+ self.converter.client_chunks = True
self.converter.tts = MagicMock()
def tearDown(self):
@@ -323,6 +327,7 @@ class SynthesizeChunkLoggingTests(unittest.TestCase):
def setUp(self):
self.converter = AudiobookConverter.__new__(AudiobookConverter)
+ self.converter.client_chunks = True
self.converter.tts = MagicMock()
def test_failed_chunk_logs_single_error(self):
@@ -342,6 +347,71 @@ class SynthesizeChunkLoggingTests(unittest.TestCase):
self.assertIn("Chunk 1/1 error: boom", logs.output[0])
+class ServerSideChunkingOutputTests(unittest.TestCase):
+ """With client-side chunking off (audiocpp default), the console skips
+ the chunk vocabulary because the whole request is one server call."""
+
+ def _converter(self, client_chunks: bool):
+ converter = AudiobookConverter.__new__(AudiobookConverter)
+ converter.client_chunks = client_chunks
+ converter.backend = tts.BACKEND_AUDIOCPP
+ converter.speed = 1.0
+ converter.output_format = "mp3"
+ converter.tts = MagicMock()
+ converter.tts.process_chunk_with_retry.return_value = "chunk.wav"
+ return converter
+
+ def test_client_chunking_prints_chunk_progress(self):
+ buf = io.StringIO()
+ with redirect_stdout(buf):
+ self._converter(client_chunks=True)._synthesize_chunks(["Hello."])
+ out = buf.getvalue()
+ self.assertIn("PROCESSING 1 CHUNKS", out)
+ self.assertIn("Chunk 1/1 completed", out)
+ self.assertIn("Successful: 1/1", out)
+
+ def test_server_side_chunking_suppresses_chunk_output(self):
+ buf = io.StringIO()
+ with redirect_stdout(buf):
+ self._converter(client_chunks=False)._synthesize_chunks(["Hello."])
+ self.assertEqual(buf.getvalue(), "")
+
+ def test_server_side_chunking_suppresses_chapter_chunk_suffix(self):
+ buf = io.StringIO()
+ with patch.object(converter_mod.audio, "combine_chunks", return_value=True), \
+ redirect_stdout(buf):
+ ok = self._converter(client_chunks=False)._convert_text(
+ "Hello world.", Path("out.mp3"), time.time(), chapter=(2, 5))
+ self.assertTrue(ok)
+ out = buf.getvalue()
+ self.assertIn("Chapter 2/5 converted", out)
+ self.assertNotIn("chunk", out.lower())
+
+ def test_single_request_run_notes_long_wait(self):
+ buf = io.StringIO()
+ with patch.object(converter_mod.audio, "combine_chunks", return_value=True), \
+ redirect_stdout(buf):
+ ok = self._converter(client_chunks=False)._convert_text(
+ "Hello world.", Path("out.mp3"), time.time(), chapter=(2, 5))
+ self.assertTrue(ok)
+ out = buf.getvalue()
+ self.assertIn("Sending the chapter 2/5 to the audio.cpp server as a "
+ "single request", out)
+ self.assertIn("expected for this to take a very long time", out)
+
+ def test_client_chunking_run_keeps_chunk_phrasing(self):
+ buf = io.StringIO()
+ with patch.object(converter_mod.audio, "combine_chunks", return_value=True), \
+ redirect_stdout(buf):
+ ok = self._converter(client_chunks=True)._convert_text(
+ "Hello world.", Path("out.mp3"), time.time(), chapter=(2, 5))
+ self.assertTrue(ok)
+ out = buf.getvalue()
+ self.assertIn("Processing 1 chunks via audio.cpp server", out)
+ self.assertNotIn("single request", out)
+ self.assertIn("Chapter 2/5 converted (1/1 chunks)", out)
+
+
class PromptOverwriteTests(unittest.TestCase):
def test_single_file_yes(self):
with patch("builtins.input", return_value="y"):