Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

English meetings skip whisper's language guess: the language is already known

christianmata7581649d6e1
diff --git a/app/src/main/asr/appleSpeech.ts b/app/src/main/asr/appleSpeech.ts
index 6641faa8..53c836ba 100644
--- a/app/src/main/asr/appleSpeech.ts
+++ b/app/src/main/asr/appleSpeech.ts
@@ -23,6 +23,9 @@ export const languageCode = (whisperName: string | null | undefined): string | n
return CODES[n] ?? (/^[a-z]{2}$/.test(n) ? n : null)
}
+/** whisper's name for a language code ('en' → 'english'), as its guesses name them */
+export const languageName = (code: string): string => Object.keys(CODES).find((n) => CODES[n] === code) ?? code
+
const lang = (locale: string) => locale.split(/[-_]/)[0].toLowerCase()
const region = (locale: string) => locale.split(/[-_]/)[1]?.toUpperCase()
/** the region to listen in when the interface names none: the biggest one for each language Apple covers */
diff --git a/app/src/main/asr/transcribe.ts b/app/src/main/asr/transcribe.ts
index f2f156f6..1a373da1 100644
--- a/app/src/main/asr/transcribe.ts
+++ b/app/src/main/asr/transcribe.ts
@@ -1,6 +1,7 @@
import type { Segment } from '../store'
import type { Track } from '../capture'
import type { Chunk } from './chunker'
+import { languageName } from './appleSpeech'
import { tokens } from './echo'
import { isPromptEcho, isSilenceGuess } from './hallucination'
@@ -72,7 +73,7 @@ export function createTranscriber(o: Opts): Transcribe {
const fetchFn = o.fetchFn ?? fetch
const locked: Partial<Record<Track, string>> = {}
- const call = async (c: Chunk, language: string, partial = false): Promise<{ lines: Line[]; text: string; language: string; prob: number }> => {
+ const call = async (c: Chunk, language: string, partial = false, guess = !partial): Promise<{ lines: Line[]; text: string; language: string; prob: number }> => {
let used: string | undefined
const prompt = o.prompt?.() ?? ''
// under 300 ms of clearly loud audio: a faint sound, where whisper's stock lines are made up
@@ -86,8 +87,8 @@ export function createTranscriber(o: Opts): Transcribe {
form.set('no_timestamps', 'false')
// a partial is read once, greedily: a few times faster than the server's beam search, good enough for a first look
if (partial) { form.set('beam_size', '1'); form.set('best_of', '1') }
- // its language is never read: no second pass of the encoder to guess it (about a third of each request)
- if (partial) form.set('no_language_probabilities', 'true')
+ // a language guess nobody reads costs a second pass of the encoder, about a third of the request
+ if (!guess) form.set('no_language_probabilities', 'true')
if (prompt) form.set('prompt', prompt)
used = await o.url()
return fetchFn(`${used}/inference`, { method: 'POST', body: form, signal: AbortSignal.timeout(o.timeoutMs ?? requestTimeoutMs(c.samples.length)) })
@@ -118,8 +119,8 @@ export function createTranscriber(o: Opts): Transcribe {
const forced = o.language?.()
if (forced) {
// the person said which language it is: nothing to detect, lock or look at again
- const r = await call(c, forced, !!opt?.partial)
- if (!opt?.partial && r.text.trim() && !isGarbled(r.text)) o.onLanguage?.(c.track, r.language, r.text.length, true)
+ const r = await call(c, forced, !!opt?.partial, false)
+ if (!opt?.partial && r.text.trim() && !isGarbled(r.text)) o.onLanguage?.(c.track, languageName(forced), r.text.length, true)
return r.lines
}
const had = locked[c.track]
diff --git a/app/test/transcribe.test.ts b/app/test/transcribe.test.ts
index 79491f77..55e9c347 100644
--- a/app/test/transcribe.test.ts
+++ b/app/test/transcribe.test.ts
@@ -144,6 +144,21 @@ describe('transcribe', () => {
expect(out[0].text).toBe('Hola de nuevo')
})
+ it("English only: no request asks whisper to guess the language, and what was heard is reported as English, not a guess", async () => {
+ const s = await stub([say('Hello everyone', 'welsh', 0.6), say('Next', 'welsh'), say('Next point', 'spanish')])
+ let forced: string | undefined = 'en'
+ const heard: Array<[string, number, boolean]> = []
+ const tr = createTranscriber({ url: async () => s.url, language: () => forced, onLanguage: (_t, lang, n, locked) => heard.push([lang, n, locked]) })
+ await tr(chunk('me', 0))
+ await tr(chunk('me', 2000), { partial: true })
+ expect(s.seen.map((x) => x.fields.no_language_probabilities)).toEqual(['true', 'true'])
+ expect(heard).toEqual([['english', 'Hello everyone'.length, true]])
+ // Multi-language: the final asks for the guess again
+ forced = undefined
+ await tr(chunk('them', 6000))
+ expect(s.seen[2].fields.no_language_probabilities).toBeUndefined()
+ })
+
it('English only: every chunk, quick or careful, is told English, never auto-detected, and still reports what it heard', async () => {
const s = await stub([say('Hello everyone'), say('Next'), say('la la la la la la la la la la la la'), say('Next point')])
let forced: string | undefined = 'en'