Add dictation and streamed read-aloud to the chat

- A mic in the composer records, transcribes with the bot's
  transcription model (api/admin/bots/transcribe) and writes the text
  into the input at the cursor to edit before sending. Escape cancels;
  recordings aren't stored.
- Every bot message has a read-aloud button that plays
  GET api/admin/bots/speak-message, streamed from the provider as the
  audio is made, so it starts in a couple of seconds. One message plays
  at a time; only the user's own sessions can be read.
- Both buttons stay visible but disabled while the bot has no model for
  them (bot_voice page prop).
- Transcription and speech no longer pick free models automatically:
  they're not available until a model is picked, and Settings says so.
  Transcription lists speech-to-text models only, so the chat-model
  transcript path and its missing-audio check are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 21:21:04 +01:00
co-authored by Claude Opus 5.5
parent 727cbf53c8
commit 163d9a434c
37 changed files with 936 additions and 197 deletions
@@ -0,0 +1,37 @@
import fetchApi from "@moduletrace/twui/utils/fetch/fetchApi";
import fileInputToBase64 from "@moduletrace/twui/utils/form/fileInputToBase64";
import type { APIResponseObject } from "@moduletrace/bunext/types";
import type { TranscribeVoiceRequest } from "@/src/schemas/bot-schema";
type Params = {
bot_id: number;
workspace_id?: number | null;
audio: Blob;
};
/**
* Sends a composer dictation to be turned into text with the bot's
* transcription model.
*/
export default async function transcribeVoice({
bot_id,
workspace_id,
audio,
}: Params): Promise<APIResponseObject<{ text: string }>> {
const ext = audio.type.split("/").pop() || "webm";
const { fileBase64Full } = await fileInputToBase64({
inputFile: new File([audio], `dictation.${ext}`, { type: audio.type }),
});
if (!fileBase64Full) {
return { success: false, msg: `Couldn't read the recording.` };
}
return await fetchApi<
TranscribeVoiceRequest,
APIResponseObject<{ text: string }>
>(`/api/admin/bots/transcribe`, {
method: "POST",
body: { bot_id, workspace_id, data_url: fileBase64Full },
});
}