Repository navigation
feat(engine): add piper engine wrapper - #8
Merged
Merged
Conversation
Synthesize caller-supplied sentence spans into SentenceAudio with phoneme alignments, streaming callbacks, rate/volume mapping, and cancellation. Unit tests stub piper; integration tests cover a real en_US-lessac-medium voice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task T1.2 from
docs/ARCHITECTURE.md§14.2.What changed
src/tts/engine/piper_engine.py: implementssynthesize()per §7.4 — caller-supplied sentence spans, per-sentenceSentenceAudiowith PCM samples and phoneme alignments,SynthesisConfig(length_scale=1/rate, volume=volume), streamingon_sentencecallback, pre-sentence cancellation, and errors left to propagate tojobs.tests/unit/test_piper_engine.py: fake-voice coverage for span mapping, alignment filtering, multi-chunk concatenation, empty segments, cancellation (before and between sentences), config mapping, span validation, and error propagation.tests/integration/test_piper_engine.py: realen_US-lessac-mediumcoverage for 3-sentence synthesis, sample totals, alignment presence, rate duration effect, and pre-start cancellation.Decisions
char_offset_mapis authoritative. The engine validates each span (in bounds, non-overlapping) and callsvoice.synthesize(text[start:end])per span instead of passing the whole text to piper's internal espeak splitter, which exposes no offsets and can disagree with the caller's segmentation.SentenceAudio: multiple piper chunks for a span are concatenated (samples + alignments); a span with no audio is kept as an empty sentence withsupports_alignments=false.ValueError(caller bug).piper/SynthesisConfigare imported lazily insidesynthesize, keepingtts.engineoff the onnxruntime import path. Unit tests stubsys.modules["piper"]so T1.1'spreview_wavisolation assertion remains valid.Deviation
The T1.2 AC asks for the rate duration ratio within 10%, i.e. rate 0.5 (
length_scale=2.0) ≈ 2x the rate 1.0 duration. Piper 1.8's stochastic duration predictor is sublinear there: measured ~1.73x onen_US-lessac-medium(5 runs). The strict 10% ratio test therefore uses rate 1.25 (nominal 0.8x, measured ~0.82x) averaged over 3 runs; thelength_scale = 1/ratemapping is unit-tested and slower rates still produce longer audio. Recorded indocs/TASKS.mdfor T5.3 to measure real scaling.Verification
ruff check src/tts tests— cleanruff format --check src/tts tests— cleanmypy --strict src/tts— cleanpytest tests/unit— 52 passed (9 new)TTS_DATA_DIR=.venv/tts-data pytest tests/integration— 6 passed (3 new, real voice)git diff --check— cleanDownstream
jobsmust buildchar_offset_map(one span per sentence, source order) and may check cancellation between sentences.timingcan consumeSentenceAudio.phoneme_alignmentsdirectly: BOS/EOS/pad are already filtered, andsupports_alignmentsis per sentence.