Translate app: sound level meter; translate unfinished segments

This commit is contained in:
James Babcock committed 2026-10-25 13:12:25 -07:00
1 parent bf2addd287
commit 0b7d93a3f1
25 files changed
+679 -175

No files matched your search

+7 -2
View File
@@ -85,15 +85,20 @@ export const TRANSLATE_SYSTEM_PROMPT =
"Reply with the English translation only, with no preamble, quotes, notes, or transliteration. " +
"If the speech is empty or meaningless noise, reply with nothing.";
/** User message for the Translate app: earlier turns for context, then the speech to translate. */
/**
* User message for the Translate app: earlier turns for context, then the
* speech to translate. `language` names the spoken language when the user set
* one (the transcription was told to expect it), else "".
*/
export function buildTranslateUserMessage(
speech: string,
context: ReadonlyArray<{ source: string; translation: string }>,
language = "",
): string {
const earlier = context.length
? "Earlier in this conversation (already translated; context only):\n" +
context.map((turn) => `<speech>${turn.source}</speech>\n<english>${turn.translation}</english>`).join("\n") +
"\n\n"
: "";
return `${earlier}Translate this speech into English:\n<speech>${speech}</speech>`;
return `${earlier}Translate this ${language ? `${language} ` : ""}speech into English:\n<speech>${speech}</speech>`;
}