[PR #7353] [MERGED] feat(calls): let Calls use your own speech-to-text server #7696

Closed
opened 2026-10-24 04:06:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7353
Author: @SpicyMarinara
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/7344-custom-speech-to-text


📝 Commits (8)

  • 9ba3294 feat(calls): let Calls use your own speech-to-text server (#7344)
  • f24d4f7 Move the CHANGELOG entry away from other open PRs
  • 4e502c6 fix(calls): keep a pending Speech to Text edit when leaving Connections
  • 71a79ff fix(calls): save Speech to Text edits in order and keep failed ones
  • cc5e923 fix(calls): make Speech to Text help lines single sentences
  • 3fd12d9 fix(calls): keep Speech to Text secrets out of logs and clear them with Connections
  • 5140deb fix(calls): keep Speech to Text edits and long keys after leaving Connections
  • 5b931aa fix(calls): send a Speech to Text edit once when the language changes

📊 Changes

21 files changed (+1059 additions, -7 deletions)

View changed files

📝 .env.example (+1 -0)
📝 CHANGELOG.md (+1 -0)
📝 docs/CONFIGURATION.md (+1 -0)
📝 docs/conversation/calls.md (+24 -2)
📝 docs/data/clearing-data.md (+1 -1)
📝 docs/development/optional-agent-packages.md (+1 -0)
➕ e2e/speech-to-text-card.e2e.ts (+90 -0)
📝 packages/client/src/components/panels/ConnectionsPanel.tsx (+4 -0)
➕ packages/client/src/components/panels/settings/SpeechToTextCard.tsx (+296 -0)
➕ packages/client/src/hooks/use-speech-to-text.ts (+46 -0)
📝 packages/client/src/localization/locales/en.json (+20 -0)
📝 packages/server/src/config/runtime-config.ts (+4 -0)
📝 packages/server/src/routes/admin.routes.ts (+9 -1)
📝 packages/server/src/routes/index.ts (+2 -0)
➕ packages/server/src/routes/speech-to-text.routes.ts (+41 -0)
📝 packages/server/src/services/capability-packages/capability-integrations.service.ts (+16 -2)
📝 packages/server/src/services/capability-packages/capability-module-runtime.service.ts (+1 -1)
➕ packages/server/src/services/speech-to-text.service.ts (+210 -0)
📝 packages/shared/src/types/generation-integration.ts (+16 -0)
📝 packages/shared/src/types/tts.ts (+35 -0)

...and 1 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7344

Why this change

  • A user who enjoys Conversation calls finds that Local Whisper (even Base) misunderstands their native language, and there is no way to use a better speech-to-text model. Marinara agreed on Discord to let them replace Whisper with a self-hosted model.
  • Call transcription itself runs inside the downloadable Calls package (Marinara-Agents conversation-calls.routes.ts, POST /:id/media, which calls its own bundled copy of SidecarSpeechService.transcribeWav). Settings, stored secrets, outbound URL policy and the package capability API belong to the Engine (AGENTS.md), so this PR adds the Engine half: the setting and a host call that Calls can use. Calls needs a small follow-up update to use it (see "Follow-up in Marinara-Agents" below).

What changed

  • Speech to Text card in Connections, under Text to Speech. It shows only once Calls is installed: an on/off switch, Server URL, API key (saved encrypted, shown masked), Model (blank sends whisper-1), optional Language code, and a Test button that saves and sends a one-second silent clip. Errors use the steady accent, so they do not pulse with Accent Pulse; the card uses theme tokens only.
  • Server: GET/PUT /api/speech-to-text/config and POST /api/speech-to-text/test (new speech-to-text.routes.ts, services/speech-to-text.service.ts). Requests go to <base URL>/audio/transcriptions as OpenAI-style multipart (file, model, response_format=json, optional language) through safeFetch. As for model providers, a server on the same machine works as is; other private or LAN addresses need the new STT_LOCAL_URLS_ENABLED=true. Limits: 25 MB upload, 2-minute timeout (30 s for Test), 1 MB response. The key never appears in responses, errors or logs.
  • Capability host: api.runtime.integrations.speech.transcribe(audio, { filename, mimeType, signal }) resolves the transcript, or null while the server is off, so a package keeps Local Whisper. It requires the network permission (Calls already has it). It is an optional member, like getGameState, so no capability API bump: packages feature-detect it.
  • The multipart body is encoded before sending. While building the regression I found that cancelling a request while undici still streams a FormData body throws an uncaught ERR_INVALID_STATE and crashes the server process; pre-encoding avoids it.
  • Docs: docs/conversation/calls.md (new "Use your own speech-to-text server" section and a troubleshooting entry), docs/CONFIGURATION.md (STT_LOCAL_URLS_ENABLED), docs/development/optional-agent-packages.md (the host member), .env.example, CHANGELOG.
  • Regression scripts/regressions/speech-to-text-server.regression.ts with a loopback fake STT server (fixed routes and fixed delays): masked and encrypted key round trip, multipart fields, trailing slash and full-endpoint URLs, plain-text answers, provider errors without the key, host null when off, the network permission, refusal of private, metadata and file: addresses naming the flag, timeout, cancellation and size cap.

Follow-up in Marinara-Agents (Calls package)

  • sources/engine/packages/server/src/routes/conversation-calls.routes.ts, /:id/media local-Whisper branch: try runtime.integrations?.speech?.transcribe?.(buffer, { filename: "call-audio.wav", mimeType: "audio/wav" }) first, and fall back to sidecarSpeechService.transcribeWav(buffer) when it is missing or resolves null. scripts/build-feature-packages.mjs (Calls activate) passes api.runtime in the route options.
  • The microphone cut-off in the issue is the package's fixed CALL_MIC_SILENCE_MS = 3_000 in ConversationCallSurface.tsx: three seconds of quiet ends and sends the recording. While that piece is transcribed, anything else you say is dropped with "Still processing your last voice message." That fix also belongs in the package; it is not changed here.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify that the Speech to Text card appears in Connections only when Calls is installed, on desktop and on a phone-width window.
  • Manually verify that entering a self-hosted server (for example Speaches at http://localhost:8000/v1) and clicking Test shows "The server answered.", and that a wrong address shows the server's reason under the button.
  • Manually verify that the API key field shows only dots after a reload, and that clearing it removes the key.
  • Manually verify the error line under Test keeps a steady colour with Accent Pulse on, in light and dark mode.
  • Manually verify, once the Calls follow-up ships, that a call in Mic recording + Local Whisper mode sends speech to the server while the switch is on and goes back to Local Whisper when it is off.

Agent-run checks: pnpm check (pass, through the shared slot limiter, after the last code change); node ./scripts/run-regressions.mjs --filter scripts/regressions/speech-to-text-server (pass; it crashed on the undici FormData abort before the pre-encoding fix); node ./scripts/run-regressions.mjs --filter scripts/regressions/capability-integrations (pass); pnpm localization:check (pass). A temporary Playwright proof (deleted, not committed) drove the real Engine server with a fake loopback STT server: the card showed only with a mocked Calls install, saved the settings, Test reached /v1/audio/transcriptions with the key, the saved key came back masked, and a wrong path showed "The speech-to-text server answered 404: Not Found". It passed on desktop Chromium and mobile Chromium. On mobile WebKit, the first assertion found settings left by the parallel mobile Chromium run on the shared server; screenshots show the card rendering correctly there.

Local CodeRabbit (three runs): fixed a pending autosave dropped when the card unmounts, out-of-order or failed autosaves losing the newest edit, the regression accepting any 4xx/5xx for a bad language code (it now uses the app's error handler and expects 400), a long CHANGELOG entry and two-sentence help copy. No findings were dismissed.

Security verification follow-up (3fd12d9c8): a server URL with a user name or password reached fetch, which rejects it with the full URL in the error, and the service logged that error at warn level. An API key with a line break failed the same way and logged the whole key. Both are now refused before any request is made, and a ?, # or invalid URL gets a clear message. Danger Zone → Connections now also clears the Speech to Text settings and key, as it does for Text to Speech (docs/data/clearing-data.md updated). speech.transcribe no longer passes the internal timeoutMs through from packages. The regression covers each change and fails without it. pnpm check passes.

  • Manually verify that Settings → Advanced → Danger Zone with Connections checked clears the Speech to Text card (the switch is off and the fields are empty after a reload).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Translation follow-up: #7355 (docs/conversation/calls.md, docs/CONFIGURATION.md, docs/development/optional-agent-packages.md, docs/data/clearing-data.md).

UI evidence (if applicable)

Screenshots were taken locally (desktop, phone width, dark theme). They are not attached.

Summary by CodeRabbit

  • New Features
    • Configure and test a custom OpenAI-compatible speech-to-text server in Connections, including its URL, model, optional API key, and language.
    • Calls can use the configured server for transcription when supported; otherwise, Local Whisper remains available.
    • Capability packages can transcribe audio through the configured server when granted network permission.
  • Configuration
    • Local and private-network server addresses are blocked by default. Set STT_LOCAL_URLS_ENABLED=true to allow them; a server on the same machine works without this setting.
  • Data Management
    • Clearing the Connections category also clears saved speech-to-text settings.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7353 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/7344-custom-speech-to-text` --- ### 📝 Commits (8) - [`9ba3294`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9ba3294ec5a2c8ee4f90657ece087f2fddc1ba68) feat(calls): let Calls use your own speech-to-text server (#7344) - [`f24d4f7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f24d4f7f1e03b90ebae1f173bbbf47bcdec6afdb) Move the CHANGELOG entry away from other open PRs - [`4e502c6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4e502c634b1981f58b71e826d057cf82c5086075) fix(calls): keep a pending Speech to Text edit when leaving Connections - [`71a79ff`](https://github.com/Pasta-Devs/Marinara-Engine/commit/71a79ffa3d11ed2db300f7d52e13b7fa97269795) fix(calls): save Speech to Text edits in order and keep failed ones - [`cc5e923`](https://github.com/Pasta-Devs/Marinara-Engine/commit/cc5e92366a68761929643c1a00a7e917d90b94e4) fix(calls): make Speech to Text help lines single sentences - [`3fd12d9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3fd12d9c8beccece7fa0d092b3087c1352a245c4) fix(calls): keep Speech to Text secrets out of logs and clear them with Connections - [`5140deb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5140deb96f0600630bad3a032ae6847bbca6faf3) fix(calls): keep Speech to Text edits and long keys after leaving Connections - [`5b931aa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5b931aad279b52454fe39c6445caf9d75ce096f4) fix(calls): send a Speech to Text edit once when the language changes ### 📊 Changes **21 files changed** (+1059 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+1 -0) 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/CONFIGURATION.md` (+1 -0) 📝 `docs/conversation/calls.md` (+24 -2) 📝 `docs/data/clearing-data.md` (+1 -1) 📝 `docs/development/optional-agent-packages.md` (+1 -0) ➕ `e2e/speech-to-text-card.e2e.ts` (+90 -0) 📝 `packages/client/src/components/panels/ConnectionsPanel.tsx` (+4 -0) ➕ `packages/client/src/components/panels/settings/SpeechToTextCard.tsx` (+296 -0) ➕ `packages/client/src/hooks/use-speech-to-text.ts` (+46 -0) 📝 `packages/client/src/localization/locales/en.json` (+20 -0) 📝 `packages/server/src/config/runtime-config.ts` (+4 -0) 📝 `packages/server/src/routes/admin.routes.ts` (+9 -1) 📝 `packages/server/src/routes/index.ts` (+2 -0) ➕ `packages/server/src/routes/speech-to-text.routes.ts` (+41 -0) 📝 `packages/server/src/services/capability-packages/capability-integrations.service.ts` (+16 -2) 📝 `packages/server/src/services/capability-packages/capability-module-runtime.service.ts` (+1 -1) ➕ `packages/server/src/services/speech-to-text.service.ts` (+210 -0) 📝 `packages/shared/src/types/generation-integration.ts` (+16 -0) 📝 `packages/shared/src/types/tts.ts` (+35 -0) _...and 1 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7344 ## Why this change - A user who enjoys Conversation calls finds that Local Whisper (even Base) misunderstands their native language, and there is no way to use a better speech-to-text model. Marinara agreed on Discord to let them replace Whisper with a self-hosted model. - Call transcription itself runs inside the downloadable **Calls** package (Marinara-Agents `conversation-calls.routes.ts`, `POST /:id/media`, which calls its own bundled copy of `SidecarSpeechService.transcribeWav`). Settings, stored secrets, outbound URL policy and the package capability API belong to the Engine (AGENTS.md), so this PR adds the Engine half: the setting and a host call that Calls can use. **Calls needs a small follow-up update to use it** (see "Follow-up in Marinara-Agents" below). ## What changed - **Speech to Text card** in **Connections**, under Text to Speech. It shows only once Calls is installed: an on/off switch, **Server URL**, **API key** (saved encrypted, shown masked), **Model** (blank sends `whisper-1`), optional **Language** code, and a **Test** button that saves and sends a one-second silent clip. Errors use the steady accent, so they do not pulse with Accent Pulse; the card uses theme tokens only. - **Server**: `GET/PUT /api/speech-to-text/config` and `POST /api/speech-to-text/test` (new `speech-to-text.routes.ts`, `services/speech-to-text.service.ts`). Requests go to `<base URL>/audio/transcriptions` as OpenAI-style multipart (`file`, `model`, `response_format=json`, optional `language`) through `safeFetch`. As for model providers, a server on the same machine works as is; other private or LAN addresses need the new `STT_LOCAL_URLS_ENABLED=true`. Limits: 25 MB upload, 2-minute timeout (30 s for Test), 1 MB response. The key never appears in responses, errors or logs. - **Capability host**: `api.runtime.integrations.speech.transcribe(audio, { filename, mimeType, signal })` resolves the transcript, or `null` while the server is off, so a package keeps Local Whisper. It requires the `network` permission (Calls already has it). It is an optional member, like `getGameState`, so no capability API bump: packages feature-detect it. - The multipart body is encoded before sending. While building the regression I found that cancelling a request while undici still streams a `FormData` body throws an uncaught `ERR_INVALID_STATE` and crashes the server process; pre-encoding avoids it. - Docs: `docs/conversation/calls.md` (new "Use your own speech-to-text server" section and a troubleshooting entry), `docs/CONFIGURATION.md` (`STT_LOCAL_URLS_ENABLED`), `docs/development/optional-agent-packages.md` (the host member), `.env.example`, CHANGELOG. - Regression `scripts/regressions/speech-to-text-server.regression.ts` with a loopback fake STT server (fixed routes and fixed delays): masked and encrypted key round trip, multipart fields, trailing slash and full-endpoint URLs, plain-text answers, provider errors without the key, host `null` when off, the network permission, refusal of private, metadata and `file:` addresses naming the flag, timeout, cancellation and size cap. ### Follow-up in Marinara-Agents (Calls package) - `sources/engine/packages/server/src/routes/conversation-calls.routes.ts`, `/:id/media` local-Whisper branch: try `runtime.integrations?.speech?.transcribe?.(buffer, { filename: "call-audio.wav", mimeType: "audio/wav" })` first, and fall back to `sidecarSpeechService.transcribeWav(buffer)` when it is missing or resolves `null`. `scripts/build-feature-packages.mjs` (Calls `activate`) passes `api.runtime` in the route options. - The microphone cut-off in the issue is the package's fixed `CALL_MIC_SILENCE_MS = 3_000` in `ConversationCallSurface.tsx`: three seconds of quiet ends and sends the recording. While that piece is transcribed, anything else you say is dropped with "Still processing your last voice message." That fix also belongs in the package; it is not changed here. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify that the **Speech to Text** card appears in **Connections** only when Calls is installed, on desktop and on a phone-width window. - Manually verify that entering a self-hosted server (for example Speaches at `http://localhost:8000/v1`) and clicking **Test** shows "The server answered.", and that a wrong address shows the server's reason under the button. - Manually verify that the API key field shows only dots after a reload, and that clearing it removes the key. - Manually verify the error line under **Test** keeps a steady colour with Accent Pulse on, in light and dark mode. - Manually verify, once the Calls follow-up ships, that a call in **Mic recording + Local Whisper** mode sends speech to the server while the switch is on and goes back to Local Whisper when it is off. Agent-run checks: `pnpm check` (pass, through the shared slot limiter, after the last code change); `node ./scripts/run-regressions.mjs --filter scripts/regressions/speech-to-text-server` (pass; it crashed on the undici `FormData` abort before the pre-encoding fix); `node ./scripts/run-regressions.mjs --filter scripts/regressions/capability-integrations` (pass); `pnpm localization:check` (pass). A temporary Playwright proof (deleted, not committed) drove the real Engine server with a fake loopback STT server: the card showed only with a mocked Calls install, saved the settings, **Test** reached `/v1/audio/transcriptions` with the key, the saved key came back masked, and a wrong path showed "The speech-to-text server answered 404: Not Found". It passed on desktop Chromium and mobile Chromium. On mobile WebKit, the first assertion found settings left by the parallel mobile Chromium run on the shared server; screenshots show the card rendering correctly there. Local CodeRabbit (three runs): fixed a pending autosave dropped when the card unmounts, out-of-order or failed autosaves losing the newest edit, the regression accepting any 4xx/5xx for a bad language code (it now uses the app's error handler and expects 400), a long CHANGELOG entry and two-sentence help copy. No findings were dismissed. Security verification follow-up (3fd12d9c8): a server URL with a user name or password reached `fetch`, which rejects it with the full URL in the error, and the service logged that error at warn level. An API key with a line break failed the same way and logged the whole key. Both are now refused before any request is made, and a `?`, `#` or invalid URL gets a clear message. **Danger Zone → Connections** now also clears the Speech to Text settings and key, as it does for Text to Speech (`docs/data/clearing-data.md` updated). `speech.transcribe` no longer passes the internal `timeoutMs` through from packages. The regression covers each change and fails without it. `pnpm check` passes. - Manually verify that **Settings → Advanced → Danger Zone** with **Connections** checked clears the Speech to Text card (the switch is off and the fields are empty after a reload). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Translation follow-up: #7355 (`docs/conversation/calls.md`, `docs/CONFIGURATION.md`, `docs/development/optional-agent-packages.md`, `docs/data/clearing-data.md`). ## UI evidence (if applicable) Screenshots were taken locally (desktop, phone width, dark theme). They are not attached. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Configure and test a custom OpenAI-compatible speech-to-text server in **Connections**, including its URL, model, optional API key, and language. * Calls can use the configured server for transcription when supported; otherwise, Local Whisper remains available. * Capability packages can transcribe audio through the configured server when granted network permission. * **Configuration** * Local and private-network server addresses are blocked by default. Set `STT_LOCAL_URLS_ENABLED=true` to allow them; a server on the same machine works without this setting. * **Data Management** * Clearing the **Connections** category also clears saved speech-to-text settings. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:06:37 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7696
No description provided.