Files
LocalAI/backend/go/qwen3-tts-cpp
mudler-agentandEttore Di Giacinto f85087f992 feat(tts): stream Qwen text and add assistant preset (#12770)
* feat(tts): stream Qwen text through audio pipelines

Feed cleaned LLM deltas into one persistent Qwen synthesis session.
Return audio before input ends and preserve the live RPC through model
cache, staging and in-flight wrappers. Stop generation on sink failures
or cancellation without replaying speech through a fallback.

Pin the incremental native fork and verify early audio, late text,
finalization and cancellation with lifecycle and real-model checks.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* build(tts): use the organization Qwen fork

Fetch the reviewed incremental synthesis commit from localai-org so
backend builds use the organization-maintained fork.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* feat(gallery): add a Qwen streaming assistant preset

Expose an English pipeline using existing VAD, ASR, LLM and named-voice
TTS models. Enable incremental text and audio delivery, and document
separate component installs because the gallery has no dependency
installer.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(gallery): use Parakeet TDT v3 for the assistant

Select the existing Parakeet TDT 0.6B v3 transcription entry and update
its prerequisite install command. Keep the preset's English voice and
incremental Qwen synthesis configuration.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(kokoros): reject unsupported backend RPCs

Implement the MotionStream and SlotCache methods required by the shared
protobuf service. Return Unimplemented so Kokoros compiles without
advertising support for either operation.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(tts): mark cleanup and logging results ignored

Explicitly ignore connection shutdown, test server shutdown and
Ginkgo diagnostic writer errors. These operations do not replace the
stream's inference or sink errors, and errcheck requires their return
values to be acknowledged.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* feat(tts): stream buffered clauses in realtime pipelines

Start clause synthesis while LLM text is still arriving when both streaming flags are enabled. Keep explicit clause opt-out and native Qwen sessions, bound automatic queued work, and choose streaming support on resolved failover targets.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* test(tts): bound synthetic voice clone generation

The sine-wave reference checks speaker conditioning and WAV output, but does not provide a meaningful speech EOS target. Limit that smoke request to 128 frames and verify the request limit reaches native synthesis. Leave production sampling defaults unchanged.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* fix(tts): require explicit clause buffering opt-in

Keep whole-reply synthesis for nonnative engines when clause_chunking is unset or false. Use the bounded cancellable worker when explicitly enabled, with unary clauses when TTS streaming is disabled. Preserve native Qwen precedence for every clause setting.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* feat(gallery): add VITS and Piper streaming assistants

Provide comparable full pipeline configurations with shared VAD, Parakeet transcription, and Qwen chat components. Enable clause buffering explicitly and document the separate prerequisite model installs and Talk selection.

Assisted-by: Codex:gpt-6.1-sol
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
2026-10-19 12:30:52 +02:00
..

Qwen3-TTS C++ backend

This backend runs Qwen3-TTS GGUF models through qwentts.cpp. It supports 24 kHz speech generation, streaming, named speakers, voice design, and reference-audio cloning depending on the model variant.

The following Base models accept LocalAI Voice Library profiles:

  • qwen3-tts-cpp
  • qwen3-tts-cpp-0.6b-base-q4
  • qwen3-tts-cpp-1.7b-base
  • qwen3-tts-cpp-1.7b-base-q4

Gallery models containing customvoice or voicedesign implement those Qwen modes instead and are not advertised as raw reference-audio models.

Install a Base model with:

local-ai models install qwen3-tts-cpp

Model configuration

Base filenames are detected automatically. Set tts.voice_cloning only when a verified private conversion has a name that does not identify it as a Base or VoiceClone model:

name: private-qwen-voice
backend: qwen3-tts-cpp
parameters:
  model: qwen-private/talker.gguf
known_usecases:
  - tts
tts:
  voice_cloning: true
  audio_path: voices/default-reference.wav  # optional model-wide fallback

The tokenizer GGUF is auto-discovered when its filename contains tokenizer and it is stored beside the talker. Otherwise set options: ["tokenizer:qwen-private/tokenizer.gguf"].

tts.voice_cloning: false removes a model from Voice Library compatibility results and rejects saved localai://voice-profiles/... references. It does not disable Qwen's named-speaker or VoiceDesign modes. Setting it to true cannot add cloning to a backend that lacks LocalAI's reference-audio contract.

Request precedence is: a request voice, then tts.voice, then tts.audio_path. A saved profile supplies its private WAV and exact transcript for that request without changing the model YAML.

API example

Create or select a profile in Operate → Voice Library, then pass its stable URI to either speech endpoint:

curl http://localhost:8080/v1/audio/speech \
  -H 'Content-Type: application/json' \
  -d '{
    "model": "qwen3-tts-cpp",
    "input": "This request uses a saved reference voice.",
    "voice": "localai://voice-profiles/PROFILE_ID"
  }' \
  --output speech.wav

Native end-to-end test

The labeled test loads real GGUFs, synthesizes speech, streams audio, and exercises cloning with a generated 24 kHz reference WAV:

make -C backend/go/qwen3-tts-cpp qwen3-tts-cpp

QWEN3TTS_MODEL=/path/to/qwen-talker-0.6b-base-Q8_0.gguf \
QWEN3TTS_CODEC=/path/to/qwen-tokenizer-12hz-Q8_0.gguf \
QWEN3TTS_LIBRARY=backend/go/qwen3-tts-cpp/libgoqwen3ttscpp-fallback.so \
  go test ./backend/go/qwen3-tts-cpp -ginkgo.label-filter=e2e

Incremental text and audio

The TTSLive backend RPC accepts text fragments while emitting audio from one persistent utterance. The first TTSRequest carries voice, language and sampling options; subsequent requests carry only text. Each fragment must contain valid UTF-8; the protobuf string boundary does not accept incomplete Unicode characters. Closing the request stream commits end of input. Continue reading responses until EOF to receive the codec tail. Responses contain one streaming WAV header followed by mono PCM16 chunks at 24 kHz.

Realtime audio pipelines select this path when their TTS model uses qwen3-tts-cpp and pipeline.streaming.llm and pipeline.streaming.tts are true. Cleaned LLM content feeds the same synthesis session; clause splitting is bypassed. WebSocket and WebRTC transports receive audio as it becomes available. The text queue is bounded, so slow audio consumers apply backpressure to text generation. Audio emits before the full response is available; WebSocket conversation history still retains the final audio, as in the existing path. Cancellation stops input and audio. A failed live session is not retried because consumed text and emitted speech cannot be replayed safely.

This requires the incremental-input native fork. Its initial implementation uses one native batch slot and commits whitespace-delimited words or individual CJK, Kana and Hangul characters. Incomplete words remain buffered until a stable boundary. Reference audio without ref_text is supported; transcript-based ICL cloning is rejected for incremental sessions. Other TTS backends retain their existing whole-text or clause synthesis paths. The standard speech HTTP request continues to accept a complete JSON input.

To run the real native streaming check, provide QWEN3TTS_LIBRARY, QWEN3TTS_MODEL, QWEN3TTS_CODEC, and QWEN3TTS_LIVE_TEST=1, then run go test ./backend/go/qwen3-tts-cpp -ginkgo.focus TTSLiveNative -v from the repository root. It withholds late text and end of input until real PCM arrives.