();
+ upstream.mockImplementationOnce(() => {
+ uploadStarted.resolve();
+ return rejection.promise;
+ });
+ const uploads = upstream.mock.calls.length;
+ const job = yield* transcribe("en").pipe(Effect.forkChild);
+ yield* Effect.promise(() => uploadStarted.promise);
+ yield* service.setKey("deepgram", null);
+ rejection.resolve(keytermLimit());
+ expect(yield* Effect.flip(Fiber.join(job))).toMatchObject({ reason: "missing-key" });
+ expect(upstream).toHaveBeenCalledTimes(uploads + 1);
+ }),
+);
+
it.effect("removing a key while a catalog read is pending prevents the upload", () =>
Effect.gen(function* () {
const service = yield* CloudSpeech.CloudSpeech.pipe(
diff --git a/apps/server/src/speech/CloudSpeech.ts b/apps/server/src/speech/CloudSpeech.ts
index 31702c80a87ee..66d3ff40918f3 100644
--- a/apps/server/src/speech/CloudSpeech.ts
+++ b/apps/server/src/speech/CloudSpeech.ts
@@ -31,12 +31,22 @@ const endpoints = {
openai: { url: "https://api.openai.com/v1/audio/transcriptions", model: "gpt-transcribe" },
xai: { url: "https://api.x.ai/v1/stt", model: "grok-voice-transcribe-2.0" },
openrouter: { url: "https://openrouter.ai/api/v1/audio/transcriptions" },
+ deepgram: { url: "https://api.deepgram.com/v1/listen", model: "nova-3" },
};
const OPENROUTER_CATALOG_URL =
"https://openrouter.ai/api/v1/models?output_modalities=transcription&zdr=true";
const isApiKey = Schema.is(CloudSpeechApiKey);
const isModelId = Schema.is(CloudSpeechModelId);
const sameCredential = Schema.toEquivalence(SettingsSecretValue);
+const DeepgramResult = Schema.Struct({
+ results: Schema.Struct({
+ channels: Schema.NonEmptyArray(
+ Schema.Struct({
+ alternatives: Schema.NonEmptyArray(Schema.Struct({ transcript: Schema.String })),
+ }),
+ ),
+ }),
+});
const OpenRouterCatalog = Schema.Struct({
data: Schema.Array(Schema.Struct({ id: Schema.String, name: Schema.optionalKey(Schema.String) })),
});
@@ -104,6 +114,20 @@ function openRouterBody(model: string, audio: ArrayBuffer, language: string) {
});
}
+function deepgramUrl(language: string, options: SpeechTranscriptionOptions, keyterms: boolean) {
+ const url = new URL(endpoints.deepgram.url);
+ url.searchParams.set("model", endpoints.deepgram.model);
+ url.searchParams.set("smart_format", "true");
+ url.searchParams.set("redact_usage", "true");
+ // `multi` transcribes speech that switches languages, such as English terms in other speech.
+ url.searchParams.set("language", language === "auto" ? "multi" : language);
+ if (keyterms)
+ for (const { term } of options.speechCustomWords) url.searchParams.append("keyterm", term);
+ if (!options.speechRemoveFillerWords || options.speechCorrectionWord)
+ url.searchParams.set("filler_words", "true");
+ return url;
+}
+
export class CloudSpeech extends Context.Service<
CloudSpeech,
{
@@ -133,10 +157,11 @@ export const layer = Layer.effect(
Effect.map((value) => value.cloudSpeechCredentials),
);
const configured = credentials.pipe(
- Effect.map(({ openai, xai, openrouter }) => ({
+ Effect.map(({ openai, xai, openrouter, deepgram }) => ({
openai: Boolean(openai),
xai: Boolean(xai),
openrouter: Boolean(openrouter),
+ deepgram: Boolean(deepgram),
})),
);
const execute = (request: HttpClientRequest.HttpClientRequest) =>
@@ -211,21 +236,42 @@ export const layer = Layer.effect(
);
if (!isApiKey(key)) return yield* unreadable();
const audio = wave(samples);
- const request = HttpClientRequest.post(endpoints[provider].url).pipe(
- HttpClientRequest.bearerToken(Redacted.make(key)),
- provider === "openrouter"
- ? openRouterBody(model!, audio, language)
- : audioBody(provider, audio, language, options),
- );
+ const deepgramRequest = (keyterms: boolean) =>
+ HttpClientRequest.post(deepgramUrl(language, options, keyterms)).pipe(
+ HttpClientRequest.setHeader("authorization", `Token ${key}`),
+ HttpClientRequest.bodyUint8Array(new Uint8Array(audio), "audio/wav"),
+ );
+ const request =
+ provider === "deepgram"
+ ? deepgramRequest(true)
+ : HttpClientRequest.post(endpoints[provider].url).pipe(
+ HttpClientRequest.bearerToken(Redacted.make(key)),
+ provider === "openrouter"
+ ? openRouterBody(model!, audio, language)
+ : audioBody(provider, audio, language, options),
+ );
const unavailable = () => new CloudSpeechError({ provider, reason: "unavailable" });
- // A catalog fetch or vault lookup may have outlived the credential it started with.
- const current = (yield* credentials)[provider];
- if (!current || !sameCredential(source, current))
- return yield* new CloudSpeechError({
- provider,
- reason: current ? "key-changed" : "missing-key",
- });
- const response = yield* execute(request).pipe(Effect.mapError(unavailable));
+ // A catalog fetch, vault lookup, or earlier upload may have outlived the credential.
+ const ensureCurrentKey = Effect.gen(function* () {
+ const current = (yield* credentials)[provider];
+ if (!current || !sameCredential(source, current))
+ return yield* new CloudSpeechError({
+ provider,
+ reason: current ? "key-changed" : "missing-key",
+ });
+ });
+ yield* ensureCurrentKey;
+ let response = yield* execute(request).pipe(Effect.mapError(unavailable));
+ // Deepgram caps keyterms in tokens clients cannot count; the dictionary still fixes the text below.
+ if (
+ provider === "deepgram" &&
+ response.status === 400 &&
+ options.speechCustomWords.length > 0 &&
+ (yield* response.text.pipe(Effect.orElseSucceed(() => ""))).includes("Keyterm limit")
+ ) {
+ yield* ensureCurrentKey;
+ response = yield* execute(deepgramRequest(false)).pipe(Effect.mapError(unavailable));
+ }
if (response.status < 200 || response.status >= 300)
return yield* new CloudSpeechError({
provider,
@@ -238,9 +284,14 @@ export const layer = Layer.effect(
? "model-unavailable"
: "unavailable",
});
- const { text } = yield* HttpClientResponse.schemaBodyJson(
- EnvironmentSpeechTranscriptionResult,
- )(response).pipe(Effect.mapError(unavailable));
+ const text =
+ provider === "deepgram"
+ ? (yield* HttpClientResponse.schemaBodyJson(DeepgramResult)(response).pipe(
+ Effect.mapError(unavailable),
+ )).results.channels[0].alternatives[0].transcript
+ : (yield* HttpClientResponse.schemaBodyJson(EnvironmentSpeechTranscriptionResult)(
+ response,
+ ).pipe(Effect.mapError(unavailable))).text;
const corrected = applySpeechAliases(text, options.speechCustomWords);
return (
options.speechRemoveFillerWords
diff --git a/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx b/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
index f859695e3360d..545e8e1b7811d 100644
--- a/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
+++ b/apps/web/src/components/settings/CloudVoiceConfiguration.browser.test.tsx
@@ -98,8 +98,14 @@ it("cancelling a provider's setup keeps the current destination and writes nothi
const destination = screen.getByRole("combobox", { name: "Transcribe with" });
await expect.element(destination).toHaveTextContent("Laptop");
await destination.click();
- await page.getByRole("option", { name: "OpenAI via Laptop" }).click();
+ await page.getByRole("option", { name: "Deepgram via Laptop" }).click();
const dialog = page.getByRole("dialog");
+ await expect
+ .element(dialog.getByText("Update Laptop to use Deepgram dictation."))
+ .toBeVisible();
+ await dialog.getByRole("button", { name: "Cancel" }).click();
+ await destination.click();
+ await page.getByRole("option", { name: "OpenAI via Laptop" }).click();
await dialog.getByRole("button", { name: "Cancel" }).click();
await expect.element(dialog).not.toBeInTheDocument();
await expect.element(destination).toHaveTextContent("Laptop");
diff --git a/apps/web/src/components/settings/CloudVoiceConfiguration.tsx b/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
index 0a992f4f93b61..bdce8814b1c0b 100644
--- a/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
+++ b/apps/web/src/components/settings/CloudVoiceConfiguration.tsx
@@ -228,7 +228,7 @@ export function CloudVoiceConfiguration({
const destination = (): CloudDestination =>
routed && isModelId(model)
? { kind: "cloud", provider: "openrouter", environmentId: id, model }
- : { kind: "cloud", provider: provider as "openai" | "xai", environmentId: id };
+ : { kind: "cloud", provider: provider as "openai" | "xai" | "deepgram", environmentId: id };
const enable = () => chooseAudioDestination(destination());
const canSubmit = routed
? modelChosen && keyReady && (!active || modelChanged || keyChanged)
@@ -367,13 +367,10 @@ export function CloudVoiceConfiguration({
- ) : routed &&
- AsyncResult.isSuccess(presence) &&
- presence.value &&
- saved === undefined ? (
+ ) : AsyncResult.isSuccess(presence) && presence.value && saved === undefined ? (
- Update {environment.label} to use OpenRouter dictation.
+ Update {environment.label} to use {name} dictation.
) : saved === undefined ? (
diff --git a/apps/web/src/components/settings/VoiceSettingsPanel.tsx b/apps/web/src/components/settings/VoiceSettingsPanel.tsx
index 84a76f373c8be..f88740d214b1f 100644
--- a/apps/web/src/components/settings/VoiceSettingsPanel.tsx
+++ b/apps/web/src/components/settings/VoiceSettingsPanel.tsx
@@ -151,6 +151,7 @@ import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings"
const OFF = "off";
const DEVICE = "device";
function CloudSpeechLogo({ provider }: { provider: CloudSpeechProvider }) {
+ if (provider === "deepgram") return ;
if (provider === "openrouter")
return ;
return (
diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts
index 4f57b8d730842..578d76477162a 100644
--- a/apps/web/src/components/settings/settingsSearch.ts
+++ b/apps/web/src/components/settings/settingsSearch.ts
@@ -591,6 +591,7 @@ export const SETTINGS_SEARCH_ITEMS = [
msg(
"send microphone audio dictation destination speech voice stt transcription environment machine consent privacy cloud OpenAI Grok OpenRouter",
),
+ "Deepgram",
],
},
{
diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json
index 8d5cb7d817bb1..d5a53d546627b 100644
--- a/apps/web/src/i18n/translations/de.json
+++ b/apps/web/src/i18n/translations/de.json
@@ -7910,14 +7910,20 @@
", um fortzufahren."
],
"1d33877ef8ea3559": "Laden des API-Schlüssels wiederholen",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Aktualisiere ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- ", um OpenRouter-Diktat zu nutzen."
+ ", um ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "-Diktat zu nutzen."
],
"d7acad5dde4c1d1b": "Es wird nach einem API-Schlüssel gesucht…",
"8257030da7a4ad4e": "Modell",
diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json
index 6c5ef49b77f43..dfac897f489d5 100644
--- a/apps/web/src/i18n/translations/en.json
+++ b/apps/web/src/i18n/translations/en.json
@@ -7917,14 +7917,20 @@
" with dictation access to continue."
],
"1d33877ef8ea3559": "Retry loading API key",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Update ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " to use OpenRouter dictation."
+ " to use ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ " dictation."
],
"d7acad5dde4c1d1b": "Checking for an API key…",
"8257030da7a4ad4e": "Model",
diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json
index 1f4ed2cf548ee..250a1f3fdeb2b 100644
--- a/apps/web/src/i18n/translations/es.json
+++ b/apps/web/src/i18n/translations/es.json
@@ -7909,14 +7909,20 @@
" con acceso al dictado para continuar."
],
"1d33877ef8ea3559": "Reintentar la carga de la clave de API",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Actualiza ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " para usar el dictado con OpenRouter."
+ " para usar el dictado de ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "."
],
"d7acad5dde4c1d1b": "Buscando una clave de API…",
"8257030da7a4ad4e": "Modelo",
diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json
index 72da8bf8e23b2..0f5bd0a56d208 100644
--- a/apps/web/src/i18n/translations/fr.json
+++ b/apps/web/src/i18n/translations/fr.json
@@ -7910,14 +7910,20 @@
" avec l’accès à la dictée pour continuer."
],
"1d33877ef8ea3559": "Réessayer de charger la clé API",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Mettez à jour ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " pour utiliser la dictée OpenRouter."
+ " pour utiliser la dictée ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "."
],
"d7acad5dde4c1d1b": "Recherche d’une clé API…",
"8257030da7a4ad4e": "Modèle",
diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json
index 28945ae29dca3..6d2d6438f638e 100644
--- a/apps/web/src/i18n/translations/ja.json
+++ b/apps/web/src/i18n/translations/ja.json
@@ -7874,8 +7874,13 @@
" に接続してください。"
],
"1d33877ef8ea3559": "API キーの読み込みを再試行",
- "be805c1729dc0726": [
- "OpenRouter の音声入力を使うには ",
+ "2b5b356019c6857b": [
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ " の音声入力を使うには ",
{
"i": 1,
"k": "_gt_value_1",
diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json
index 35f6cc3549436..f391eb2e381bd 100644
--- a/apps/web/src/i18n/translations/ko.json
+++ b/apps/web/src/i18n/translations/ko.json
@@ -7876,8 +7876,13 @@
"에 연결하세요."
],
"1d33877ef8ea3559": "API 키 다시 불러오기",
- "be805c1729dc0726": [
- "OpenRouter 받아쓰기를 사용하려면 ",
+ "2b5b356019c6857b": [
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ " 받아쓰기를 사용하려면 ",
{
"i": 1,
"k": "_gt_value_1",
diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json
index 85fefb672d30c..e3b60d29721b4 100644
--- a/apps/web/src/i18n/translations/pt-BR.json
+++ b/apps/web/src/i18n/translations/pt-BR.json
@@ -7909,14 +7909,20 @@
" com acesso ao ditado para continuar."
],
"1d33877ef8ea3559": "Tentar carregar a chave de API novamente",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Atualize ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " para usar o ditado do OpenRouter."
+ " para usar o ditado do ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "."
],
"d7acad5dde4c1d1b": "Verificando se há uma chave de API…",
"8257030da7a4ad4e": "Modelo",
diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json
index f4d45a79d0b52..a238294a8f762 100644
--- a/apps/web/src/i18n/translations/ru.json
+++ b/apps/web/src/i18n/translations/ru.json
@@ -7909,14 +7909,20 @@
" с доступом к диктовке, чтобы продолжить."
],
"1d33877ef8ea3559": "Повторить загрузку API-ключа",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Обновите ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- ", чтобы использовать диктовку OpenRouter."
+ ", чтобы использовать диктовку ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "."
],
"d7acad5dde4c1d1b": "Проверка наличия API-ключа…",
"8257030da7a4ad4e": "Модель",
diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json
index 99818c1f2ed37..a7318c0e35582 100644
--- a/apps/web/src/i18n/translations/sv.json
+++ b/apps/web/src/i18n/translations/sv.json
@@ -7915,14 +7915,20 @@
" med dikteringsåtkomst för att fortsätta."
],
"1d33877ef8ea3559": "Försök läsa in API-nyckeln igen",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"Uppdatera ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " för att använda diktering med OpenRouter."
+ " för att använda diktering med ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ "."
],
"d7acad5dde4c1d1b": "Söker efter en API-nyckel…",
"8257030da7a4ad4e": "Modell",
diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json
index 09d04201cd2f8..6a7df998d987e 100644
--- a/apps/web/src/i18n/translations/zh.json
+++ b/apps/web/src/i18n/translations/zh.json
@@ -7927,14 +7927,20 @@
" 以继续。"
],
"1d33877ef8ea3559": "重新加载 API 密钥",
- "be805c1729dc0726": [
+ "2b5b356019c6857b": [
"请更新 ",
{
"i": 1,
"k": "_gt_value_1",
"v": "v"
},
- " 以使用 OpenRouter 听写。"
+ " 以使用 ",
+ {
+ "i": 2,
+ "k": "_gt_value_2",
+ "v": "v"
+ },
+ " 听写。"
],
"d7acad5dde4c1d1b": "正在检查 API 密钥…",
"8257030da7a4ad4e": "模型",
diff --git a/docs/user/voice-input.md b/docs/user/voice-input.md
index 9831eeafd49f8..19abbaad4bcfc 100644
--- a/docs/user/voice-input.md
+++ b/docs/user/voice-input.md
@@ -31,8 +31,8 @@ recording in a language can take longer while macOS downloads its speech model.
filler-word removal are not available; the dictionary applies only when transcript
cleanup is on.
-For cloud dictation, choose **OpenAI** or **Grok Voice Transcribe** via the environment
-you want to use. If it needs a key, enter one and choose **Save and enable**.
+For cloud dictation, choose **OpenAI**, **Grok Voice Transcribe**, or **Deepgram** via the
+environment you want to use. If it needs a key, enter one and choose **Save and enable**.
You can also choose a [secret provider](secrets.md) instead of **Value** and enter a
reference. Unlock the vault on that environment before dictating. Anyone with
dictation access to the environment can use the key, but only this device opts in.
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index 4538065ee5c50..c83bd217e12f8 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -398,7 +398,7 @@ export const VoiceTranscriptionDestination = Schema.Union([
Schema.Struct({
kind: Schema.Literal("cloud"),
environmentId: EnvironmentId,
- provider: Schema.Literals(["openai", "xai"]),
+ provider: Schema.Literals(["openai", "xai", "deepgram"]),
}),
Schema.Struct({
kind: Schema.Literal("cloud"),
@@ -1375,6 +1375,7 @@ export const CloudSpeechCredentials = Schema.Struct({
openai: CloudSpeechCredential,
xai: CloudSpeechCredential,
openrouter: CloudSpeechCredential,
+ deepgram: CloudSpeechCredential,
});
export const ServerSettings = Schema.Struct({
@@ -1416,7 +1417,9 @@ export const ServerSettings = Schema.Struct({
/** Lets clients reach this machine's loopback ports over `/api/preview/tunnel`. */
enablePreviewTunnel: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(true))),
cloudSpeechCredentials: CloudSpeechCredentials.pipe(
- Schema.withDecodingDefault(Effect.succeed({ openai: "", xai: "", openrouter: "" })),
+ Schema.withDecodingDefault(
+ Effect.succeed({ openai: "", xai: "", openrouter: "", deepgram: "" }),
+ ),
),
speechModelId: Schema.String.pipe(
Schema.withDecodingDefault(Effect.succeed("handy-computer/parakeet-unified-en-0.6b-gguf")),
@@ -1884,6 +1887,7 @@ export const ServerSettingsPatch = Schema.Struct({
openai: Schema.optionalKey(SettingsSecretValue),
xai: Schema.optionalKey(SettingsSecretValue),
openrouter: Schema.optionalKey(SettingsSecretValue),
+ deepgram: Schema.optionalKey(SettingsSecretValue),
}),
),
speechModelId: Schema.optionalKey(Schema.String),
diff --git a/packages/contracts/src/speech.ts b/packages/contracts/src/speech.ts
index 0784c92be4ab6..a1cd197de5c29 100644
--- a/packages/contracts/src/speech.ts
+++ b/packages/contracts/src/speech.ts
@@ -8,23 +8,26 @@ export const CloudSpeechApiKey = TrimmedNonEmptyString.check(
Schema.isPattern(/^(?![a-z][a-z\d+.-]*:\/\/)[!-~]+$/i),
);
-export const CloudSpeechProvider = Schema.Literals(["openai", "xai", "openrouter"]);
+export const CloudSpeechProvider = Schema.Literals(["openai", "xai", "openrouter", "deepgram"]);
export type CloudSpeechProvider = typeof CloudSpeechProvider.Type;
export const CLOUD_SPEECH_LABELS = {
openai: "OpenAI",
xai: "Grok Voice Transcribe",
openrouter: "OpenRouter",
+ deepgram: "Deepgram",
} as const;
export const CLOUD_SPEECH_PROVIDER_NAMES = {
openai: "OpenAI",
xai: "xAI",
openrouter: "OpenRouter",
+ deepgram: "Deepgram",
} as const;
-/** Servers that predate OpenRouter report only the first two providers. */
+/** Older servers omit providers added after OpenAI and xAI. */
export const CloudSpeechKeys = Schema.Struct({
openai: Schema.Boolean,
xai: Schema.Boolean,
openrouter: Schema.optionalKey(Schema.Boolean),
+ deepgram: Schema.optionalKey(Schema.Boolean),
});
export type CloudSpeechKeys = typeof CloudSpeechKeys.Type;