Skip to content

elevenlabs: add Scribe transcription engine with realtime and live partials - #1134

Open
Ramblurr wants to merge 4 commits into
peteonrails:devfrom
Ramblurr:elevenlabs-scribe
Open

Ramblurr wants to merge 4 commits into
peteonrails:devfrom
Ramblurr:elevenlabs-scribe

Conversation

@Ramblurr

Copy link
Copy Markdown

Description

Voxtype can't dictate with ElevenLabs Scribe, and its cloud streaming engines only type committed text. This adds engine = "elevenlabs" behind the elevenlabs Cargo feature. It is a StreamingTranscriber peer to Soniox with its own [elevenlabs] section, as discussed in #545.

There are three modes:

  • mode = "batch": works like the other cloud engines. Nothing is typed while you speak. When you stop, the whole recording is uploaded and the transcript is typed in one go. Default model scribe_v3.
  • mode = "realtime", the default: audio streams to ElevenLabs while you speak. Each time you pause, ElevenLabs commits that phrase and Voxtype types it, so text appears phrase by phrase during dictation. Committed text is never changed afterwards. Default model scribe_v3_live.
  • mode = "partials": like realtime, but Voxtype also types ElevenLabs' running guess before a phrase is committed, so words appear as you say them. When ElevenLabs corrects its guess, Voxtype erases the changed words with BackSpace and types the correction. This uses a new StreamingEvent::RevisePartial. Once you stop, nothing more is erased; the last phrase is only appended.
  • Model IDs, region, language hint, commit strategy, VAD silence threshold and no_verbatim are set through [elevenlabs], --elevenlabs-* flags or VOXTYPE_ELEVENLABS_* variables.

Each of the four commits can be reviewed on its own:

  1. feat: let streaming backends revise provisional text: the engine-neutral RevisePartial event. Text that fell back to the clipboard is no longer counted as typed, so no BackSpace can reach it.
  2. feat: add ElevenLabs Scribe as a batch transcription engine
  3. feat: stream ElevenLabs Scribe realtime transcription with live partials: the daemon changes are gated on the engine, so other backends behave as before.
  4. docs: document the ElevenLabs engine

Related Issue

Fixes #545

Type of Change

  • New feature (non-breaking change that adds functionality)
  • Documentation update

Testing

  • I have tested these changes locally
  • I have run cargo test and all tests pass
  • I have run cargo clippy -- -D warnings with no warnings
  • I have run cargo fmt

Every commit passes cargo fmt --check, cargo clippy --all-targets --no-deps -- -D warnings and cargo test --lib, with and without --features elevenlabs. The realtime tests drive the session against a scripted socket on a paused clock, with no network calls. Batch, realtime and partials were also tried against the live API on a Wayland desktop.

Documentation

  • I have updated documentation as needed

Pre-merge checklist

  • This PR targets the dev branch (not main)
  • Wait for ci-success to pass before marking Ready for Review

Additional Notes

Two limitations shared with the existing engines, left for separate changes:

  • voxtype config get and voxtype config schema print [elevenlabs] api_key in plain text, as they already do for the Soniox, remote Whisper and meeting summary keys. Redacting them belongs in one change covering every secret.
  • BackSpace counts are Unicode scalar values, as in the Soniox correction path and cancel-rewind. Revising a provisional tail that ends in a multi-scalar grapheme such as 👍🏽 sends one BackSpace per scalar.

A backend that types partials can append to them (Partial) or correct
them while committing the segment (Replace). A provider that keeps
refining its in-progress hypothesis also needs to correct the typed
tail without ending the segment.

Add StreamingEvent::RevisePartial and StreamingSession::revise_partial.
A revision backspaces at most the current partial, so it can never
erase finalized text, then types the corrected suffix. A revision that
cannot be applied, or whose text a clipboard driver took instead of the
cursor, ends the session with an error, because the backend's next
revision is relative to text the cursor does not show. File output and
a disowned typing surface apply the same edit to the buffered text.

Text a clipboard driver took instead of the cursor is no longer counted
as typed, so a later cleanup rewrite, correction or cancel cannot
BackSpace over text that was there before. A partial delta that falls
back to the clipboard still joins the transcript in order; a final whose
correction reaches it fixes the transcript and only appends at the
cursor, while a correction of text typed after it still BackSpaces that
text.

No backend emits the event yet; the ElevenLabs engine does.
Add engine = "elevenlabs" behind the elevenlabs Cargo feature. It
uploads the finished recording to the ElevenLabs speech-to-text API as
16 kHz PCM, with a data-residency region, an optional language hint
and the provider's disfluency cleanup (no_verbatim).

The model is [elevenlabs] model, --elevenlabs-model or
VOXTYPE_ELEVENLABS_MODEL, default scribe_v3. It goes to the API as
given, like whisper's remote_model, so a new model works without a
voxtype release.

The API key comes from [elevenlabs] api_key or ELEVENLABS_API_KEY. It
travels only in a sensitive request header and is redacted from
provider error messages.

The [elevenlabs] section, the --elevenlabs-* flags and the
VOXTYPE_ELEVENLABS_* variables also carry the realtime settings (mode,
commit_strategy, vad_silence_threshold_secs). mode defaults to batch
here. The realtime modes take effect in the next commit; until then
every mode transcribes the finished recording.
mode = "realtime", now the default, streams audio to the Scribe
realtime WebSocket and types committed segments. mode = "partials" also
types the provisional transcript and revises it with RevisePartial as
the provider refines it. commit_strategy chooses provider VAD commits
or a single explicit commit when recording stops. The model is
[elevenlabs] realtime_model, --elevenlabs-realtime-model or
VOXTYPE_ELEVENLABS_REALTIME_MODEL, default scribe_v3_live, passed
through as given.

The provider sends each committed segment without a leading space.
voxtype puts one in front of a segment where a script that separates
words with spaces continues with a word, so English joins as
"Hello. World" while Japanese, Chinese and Thai join with none. The
script of the earlier text is read from its last letter or digit, so
trailing punctuation does not hide it. The rule depends only on the
committed text and the segment, so a partial and its commit agree.

The daemon treats the engine differently from other streaming backends
in five places. Each is gated on the engine, so other backends keep
their behavior:

- Every stop keeps the typing surface attached. The explicit final
  commit arrives after the microphone closes and is drained within a
  bounded time, so the last phrase is typed in place instead of
  dropped. The user may switch windows meanwhile, so from the stop on
  the session only appends: no BackSpace, and a cancel during the drain
  does not rewind. A final that extends the text typed before the stop
  adds the rest. One that corrects it leaves the typed text alone and
  logs the dropped correction, and a partial with no final after it is
  typed when the session ends. File output keeps its bookkeeping.
- In partials mode a partial that cannot be typed at the cursor, such
  as one a clipboard fallback took, ends the session with an error
  that points to realtime mode. The provider's next revision is
  relative to text the cursor does not show.
- Push-to-talk is not promoted to toggle when the built-in evdev
  listener is in use: it sees the physical key release no matter what
  synthetic typing does to the compositor's held-key state.
- Recording start rejects output settings that per-update typing cannot
  honor (non-type output modes, a profile's included, auto_submit,
  append_text, output hooks, post-processing) and points to batch mode.
- A failed session recovers its audio with Whisper first, as Soniox
  does.

The drain after the stop's commit is a small state machine: awaiting
the final, final confirmed, or speech outstanding. The protocol does
not say which commit a committed transcript answers, so a VAD commit
still in flight can answer before the stop's commit. A partial after a
final that says the same words, ignoring case, punctuation and spacing,
is an echo. Any other partial is speech the stop's commit covers, and
the drain waits for its final. Speech still outstanding at the 10 s
bound fails the session rather than ending it cleanly. With nothing
typed, the existing streaming recovery transcribes the audio. Once text
is typed, recovery would repeat it, so the last partial is appended
unconfirmed instead. A final counts as confirmed only once the daemon
has received it, so one it never gets fails the drain too. A confirmed
final ends the drain after 1 s of quiet, or 3 s when VAD commits were
on and speech was open at the stop.

The API key is redacted from provider errors and from errors about
malformed realtime messages, which can quote the message.
Add the [elevenlabs] configuration reference, a user manual section,
troubleshooting entries, and a manual smoke test for the live cleanup
workflow: manual commit, provider cleanup, partial revision, correction
drivers and failure handling.

Closes peteonrails#545

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support ElevenLabs Scribe for "realtime" typing

1 participant