Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(speech): stop rewriting Auto-detect to English on the cloud engine

enes2759476bd4ba
diff --git a/src/core/speech/register-ipc.test.ts b/src/core/speech/register-ipc.test.ts
index 29d02f3ca..443305b86 100644
--- a/src/core/speech/register-ipc.test.ts
+++ b/src/core/speech/register-ipc.test.ts
@@ -7,8 +7,9 @@ import { SpeechService, type WhisperEngineHandle } from './speech-service'
import { WhisperModelStore } from './whisper-models'
import { DEFAULT_SETTINGS } from '../../shared/types'
-function setup(engine: 'whisper' | 'cloud' = 'whisper') {
+function setup(engine: 'whisper' | 'cloud' = 'whisper', language = 'auto', cloudOk = false) {
const handlers = new Map<string, (payload: any) => Promise<any>>()
+ const sent: string[] = []
const dir = mkdtempSync(join(tmpdir(), 'ipc-'))
const models = new WhisperModelStore({ dir })
writeFileSync(models.modelPath('tiny'), 'x')
@@ -21,13 +22,23 @@ function setup(engine: 'whisper' | 'cloud' = 'whisper') {
service, models,
settings: () => ({
...DEFAULT_SETTINGS,
- speech: { engine, model: 'tiny', language: 'auto', shortcut: DEFAULT_SETTINGS.speech.shortcut }
+ speech: { engine, model: 'tiny', language, shortcut: DEFAULT_SETTINGS.speech.shortcut }
}),
licenseToken: () => null,
apiBase: 'https://api.example.dev',
- fetchFn: (async () => ({ ok: false, status: 404, json: async () => ({}) })) as any,
+ fetchFn: (async (_url: string, init: any) => {
+ sent.push(Buffer.from(init.body).toString('latin1'))
+ return cloudOk
+ ? { ok: true, status: 200, json: async () => ({ text: 'from cloud' }) }
+ : { ok: false, status: 404, json: async () => ({}) }
+ }) as any,
})
- return { handlers }
+ return { handlers, sent }
+}
+
+/** The `locale` part of the multipart body the cloud request actually put on the wire. */
+function localeOnWire(body: string): string | undefined {
+ return /name="locale"\r\n\r\n([^\r]*)\r\n/.exec(body)?.[1]
}
describe('registerSpeechIpc', () => {
@@ -43,6 +54,25 @@ describe('registerSpeechIpc', () => {
.rejects.toThrow("Cloud transcription isn't available yet.")
})
+ it('sends the picked language to cloud as-is, `auto` included', async () => {
+ // Regression, issue #586: this used to rewrite `auto` to `en`, so "Auto-detect" was a hard
+ // English on cloud — no way for a Polish speaker to be heard, and no sign anything happened.
+ const auto = setup('cloud', 'auto', true)
+ await expect(auto.handlers.get('speech:transcribe')!({ pcm: new Float32Array(16).buffer }))
+ .resolves.toEqual({ text: 'from cloud' })
+ expect(localeOnWire(auto.sent[0])).toBe('auto')
+
+ const pl = setup('cloud', 'pl', true)
+ await pl.handlers.get('speech:transcribe')!({ pcm: new Float32Array(16).buffer })
+ expect(localeOnWire(pl.sent[0])).toBe('pl')
+ })
+
+ it('lets a per-call language override the setting', async () => {
+ const cloud = setup('cloud', 'auto', true)
+ await cloud.handlers.get('speech:transcribe')!({ pcm: new Float32Array(16).buffer, language: 'uk' })
+ expect(localeOnWire(cloud.sent[0])).toBe('uk')
+ })
+
it('lists models merged with catalog metadata', async () => {
const { handlers } = setup()
const list = await handlers.get('speech:models')!({})
diff --git a/src/core/speech/register-ipc.ts b/src/core/speech/register-ipc.ts
index ef8f07c0f..f26a39eb3 100644
--- a/src/core/speech/register-ipc.ts
+++ b/src/core/speech/register-ipc.ts
@@ -27,7 +27,12 @@ export function registerSpeechIpc(deps: {
const text = speech.engine === 'cloud'
? await cloudTranscribe(pcm, {
apiBase: deps.apiBase,
- locale: language === 'auto' ? 'en' : language,
+ // The language goes to the endpoint UNCHANGED, `auto` included (issue #586). This used
+ // to read `language === 'auto' ? 'en' : language`, which made "Auto-detect" a hard `en`
+ // on cloud — silently, and for exactly the speakers auto-detect is there to serve. The
+ // endpoint does not exist yet (every call 404s), so its contract is still ours to write:
+ // `auto` means detect, and iOS sends the same field the same way.
+ locale: language,
token: deps.licenseToken(),
fetchFn: deps.fetchFn,
})