Skip to content

Latest commit

 

History

History
193 lines (167 loc) · 13.5 KB

worker.md

File metadata and controls

193 lines (167 loc) · 13.5 KB

Worker protocol

This page describes speech worker, a process that another program starts to speak texts, recognize speech, enhance it or hold conversations, as ASIST does, and the protocol it speaks.

speech worker MODEL [--add-voice NAME=FILE]... [--device NAME] [--threads N] [--no-warmup] [request options]
speech worker qwen3-tts-0.6b
speech worker irodori-tts-mf --add-voice me=me.voice.gguf --add-voice calm=calm-reference.wav
speech worker irodori-tts-mf --steps 8 --add-voice me=me.voice.gguf
speech worker reazonspeech-v2
speech worker re-use

A request option given as a flag (cli.md) is the default of every request that does not set it, in place of the model's own; a request's own member wins. ready and info list these defaults.

The worker serves one model. It speaks JSON Lines: one JSON object per line on stdin and on stdout, in UTF-8.

  • stdout carries the protocol and nothing else; every log goes to stderr. A caller treats a line on stdout that is not a JSON object as a defect of the worker and fails, rather than skipping it.
  • Every line in either direction is one JSON object with a string member type. A member set to null counts as left out. A member that the message's type does not have is refused, a name that is not an option included.
  • Option members take the option's type (c-api.md): a JSON string; an integer without a fraction or an exponent; any JSON number; true or false.
  • Requests run one at a time, in the order they become complete. info and count_tokens only read the model's information and are answered as they arrive, also while a request runs.

Start

out {"type":"ready","protocol":4,"version":"0.11.2","defaults":{"steps":8},"model":{...model information...}}
out {"type":"fatal","error":{"code":"model_file","option":null,"message":"..."}}

ready comes once the model is loaded, warmed up unless --no-warmup so that a GPU has compiled its kernels before the first request, and has the voices of --add-voice. version is the release, defaults the request options given as flags with their values ({} without any), and model is the model information as JSON (c-api.md), with the device, the threads and the voices added. The model information keeps the model's own defaults.

fatal comes instead when the worker cannot start. The worker then exits with 1, or with 2 for a command line it cannot run. A detection or diarization model is unsupported: the worker serves synthesis, recognition, enhancement and dialogue models. A request option flag the model does not take is unsupported, and a value out of its range out_of_range, each naming the option.

protocol rises when a caller must change to keep working: a message or member removed, renamed or given another meaning. A member or message added, an option added to the vocabulary, or a member added to the model information does not raise it.

Requests

type Members Task Answer
synthesize id, text, option members synthesis progress and chunks, then one terminal message
chunk id, seq, pcm recognition, enhancement, dialogue none of its own; it adds audio to request id
transcribe id, sample_rate, option members recognition progress, then one terminal message
enhance id, sample_rate, option members enhancement progress and chunks, then one terminal message
dialogue id, sample_rate, option members dialogue a chunk for each frame, then one terminal message
hang_up id dialogue none of its own; it ends conversation id after the audio sent
add_voice id, name, path models that take voice files one terminal message
info id any one terminal message, at once
count_tokens id, text synthesis one terminal message, at once
cancel id any none of its own
  • id is a non-empty string, unique among the requests that have not had their terminal message.
  • A recognition request is its chunk lines, seq 0, 1, 2 … in order, then its transcribe line, which makes it complete, and an enhancement request its chunk lines, then its enhance line. The chunks of several requests may interleave. sample_rate is the rate of the chunks' audio: any rate for a recognition, which the library resamples, and a rate the model takes for an enhancement (8000 to 48000 Hz for RE-USE), unless its bwe resamples it.
  • A conversation is its dialogue line, which starts it when its turn comes and sends the model's first frame before any audio, its chunk lines, seq 0, 1, 2 … in order and of any length, which the model hears as they arrive, also those that arrive while it waits, and its hang_up, which ends it once it has heard the audio sent; the audio short of a frame is dropped. sample_rate is the rate of its chunks, any rate, which the library resamples. A conversation holds the worker until it ends, and the requests after it wait. The worker keeps no time: it sends a frame as soon as it has computed it, and a caller that plays the frames as they come and sends the microphone's audio as it comes sees whether the model keeps up.
  • pcm, in both directions, is base64 of 16-bit little-endian mono samples. Audio from the worker is at the model's sample_rate, or for an enhancement at the rate it was enhanced at, the request's sample_rate or its bwe, each sample round(clamp(x, −1, 1) × 32767). Audio to the worker is read as x / 32768.
  • path of add_voice is a voice file, or a WAVE file for a model whose voice_recordings is true (Irodori-TTS, Haru); Drama 3 takes a voice file alone (models.md).
  • info gives the voices added so far: one sent before an add_voice has had its end may not list that voice yet.
  • count_tokens counts a text's tokens as a synthesis counts them against max_text_tokens, so that a caller can split a long text before it sends it, also while a synthesis runs.
  • cancel of a request that is collecting chunks or waiting ends it with cancelled at once. A running request stops at the next point where its work can stop and ends with cancelled, a conversation at its next frame; add_voice cannot be stopped once it runs. A cancel of an id that no request in flight has is ignored.
  • Once a request has had its error or cancelled while it collected chunks, its later chunk lines are dropped up to and including its transcribe or enhance line, which frees its id, or until a chunk 0 under its id starts a new request. A caller that cancels need not send the transcribe or enhance.
  • Once a conversation has had its error or cancelled before its hang_up, its later chunk lines are dropped up to and including its hang_up, or until a dialogue line starts a new conversation under its id.

When stdin closes, the worker answers the requests it has, answers each request still collecting chunks with an error, since no transcribe or enhance can follow, ends each conversation once it has heard the audio sent, as its hang_up does, and exits with 0.

Answers

out {"type":"chunk","id":"a","seq":0,"pcm":"..."}
out {"type":"chunk","id":"d","seq":12,"pcm":"...","text":"そう"}
out {"type":"progress","id":"r","done":0.42}
out {"type":"end","id":"a","seed":1234,"samples":96000,"stop":"complete"}
out {"type":"end","id":"r","text":"...","stop":"complete","segments":[{"start":0.0,"end":2.48,"text":"..."}],"tokens":[{"start":0.0,"end":0.16,"text":"..."}]}
out {"type":"end","id":"q","text":"...","stop":"complete","languages":["ja"]}
out {"type":"end","id":"d","frames":151,"samples":483200}
out {"type":"end","id":"v"}
out {"type":"end","id":"i","defaults":{"steps":8},"model":{...model information...}}
out {"type":"end","id":"c","tokens":14}
out {"type":"error","id":"a","error":{"code":"out_of_range","option":"speed","message":"..."}}
out {"type":"cancelled","id":"a"}
  • Every request gets exactly one terminal message, end, error or cancelled, and nothing for its id after it.
  • end of a synthesis has seed (the request's, or the one the library drew), samples (the number sent in its chunks) and stop (complete, max_seconds or model_limit).
  • end of a recognition has text and stop (complete, or model_limit when it reached the most tokens the model writes or a loop of them that the model's guardrail keeps once, with the text written up to there). It has languages, the tags of the languages the model heard in the order of the audio, where there are any (Qwen3-ASR), segments and tokens when the request set timestamps, and segments with each one's speaker, a number from 0 or null, when it set speakers. Where the model cannot time its text (Nemotron 3.5 Transcribe), it has untimed, why, and neither.
  • end of an enhancement has samples (the number sent in its chunks, as many as its audio has at the rate it was enhanced at) and stop (complete).
  • A conversation sends a chunk for each frame of the model's, frame_samples of the model information at its sample_rate, with text, what the model began to say in the frame: often empty, a space where it fell silent. Its end has frames and samples, the numbers it sent. One that reaches its max_seconds ends with an error, out_of_range naming max_seconds.
  • end of info has model, end of count_tokens has tokens, and end of add_voice has nothing more.
  • error has code (an error category, c-api.md), option (the input it concerns: an option's name, text, audio, id, type, seq, pcm, name, path, sample_rate or another member's name, or null) and message.
  • progress comes for a running request that is passing no chunks, when the library reports progress and at least 1 s has passed since the request's last message. done is a fraction from 0 to 1. A caller that takes a silent worker for a hung one allows for the longest single step: the encoder of a long recording runs as one (3.7 s for 311 s of audio with reazonspeech-nemo-v2 in F16 on an Apple M5).
  • A line that names no request it could belong to (not a JSON object, no string id, a cancel or a hang_up with a member it does not have, a line that starts a request under an id already in flight, or a chunk or a hang_up for no conversation in flight) gets an error without id.
  • A request of another task is unsupported with the option type: a synthesize to a model of another task, a chunk to a synthesis model, whose later lines are dropped, a transcribe, an enhance or a dialogue to a model of another task, and a hang_up to a model of another task, without id. A member the type does not have is invalid_argument with that member as option. Option values are checked by the library's setters when the request runs, so their errors are the C API's.

What each family does

  • Qwen3-TTS passes audio as it makes it, from the first 0.08 s, at 24 kHz. A cancel takes effect at the next chunk.
  • Irodori-TTS makes a request's speech at once and passes it as the codec decodes it, at 48 kHz, so a request should be one sentence: the first audio waits for the whole text. A text it predicts to last over 30 s is cut after its sentences, or after its commas, or at its spaces, and spoken in pieces as speech tts speaks it, a sentence's end holding 0.9 s of silence; a text with no place to cut is refused, naming it. A cancel takes effect at the next sampler step or piece of audio.
  • FastConformer recognizes a request's audio at once, and loses whole sentences of a stretch that holds several, so a request should be one utterance. A cancel takes effect before or after the encoder, or during the decoding.
  • Qwen3-ASR recognizes up to 1200 s at once, and longer audio in parts. A cancel takes effect within a fraction of a second.
  • Haru hears and gives frames of 3,200 samples at 24 kHz, 133 ms. Its start runs the character card and the voice as a prompt before the first frame. A cancel takes effect at the next frame.
  • RE-USE enhances a request's audio in chunks of chunk_size_in_seconds (5 s) that start every hop_length_portion of a chunk (0.5), and sends each part of it once the chunk after it is done, the rest after the last chunk. A cancel takes effect at the next chunk.

A session

Irodori-TTS speaking a sentence, a recognizer taking a request in two chunks, and Haru in a conversation of two seconds:

in  {"type":"synthesize","id":"1","text":"明日の東京は晴れです。","voice":"me","seed":42}
out {"type":"chunk","id":"1","seq":0,"pcm":"..."}
out {"type":"chunk","id":"1","seq":1,"pcm":"..."}
out {"type":"end","id":"1","seed":42,"samples":134400,"stop":"complete"}

in  {"type":"chunk","id":"r","seq":0,"pcm":"..."}
in  {"type":"chunk","id":"r","seq":1,"pcm":"..."}
in  {"type":"transcribe","id":"r","sample_rate":16000}
out {"type":"end","id":"r","text":"群島や湖では必ずしもヨットは必要ありません。","stop":"complete"}

in  {"type":"dialogue","id":"d","sample_rate":48000,"language":"ja","name":"ハル","voice":"me"}
out {"type":"chunk","id":"d","seq":0,"pcm":"...","text":""}
in  {"type":"chunk","id":"d","seq":0,"pcm":"..."}
out {"type":"chunk","id":"d","seq":1,"pcm":"...","text":""}
...
in  {"type":"hang_up","id":"d"}
out {"type":"end","id":"d","frames":16,"samples":51200}

checks/smoke/worker_client.py is a client in Python that checks every line and one terminal message per request.