Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
75aeb8b
feat(read-aloud): add speech playback on web and mobile
Yash-Singh1 Nov 13, 2026
e3af29a
fix(read-aloud): address playback and synthesis review findings
Yash-Singh1 Nov 13, 2026
55eeadb
fix(read-aloud): preserve playback across chunk cleanup
Yash-Singh1 Nov 13, 2026
d6bf296
test(mobile): isolate speech playback in file preview fixtures
Yash-Singh1 Nov 13, 2026
9a4eca8
fix(read-aloud): synchronize playback speed and native pauses
Yash-Singh1 Nov 13, 2026
b6393fb
fix(read-aloud): guard pending playback and preserve error causes
Yash-Singh1 Nov 13, 2026
16eb66b
fix(read-aloud): preserve lock-screen resume and PCM sample rates
Yash-Singh1 Nov 13, 2026
d299960
fix(read-aloud): use public OpenAI speech and catalog capabilities
Yash-Singh1 Nov 13, 2026
8affc01
fix(read-aloud): clear stale key errors and show catalog failures
Yash-Singh1 Nov 13, 2026
9adae91
fix(mobile): ignore obsolete read-aloud key requests
Yash-Singh1 Nov 13, 2026
3c2aefa
feat(speech): stream read-aloud with local model support
Yash-Singh1 Nov 15, 2026
31c75af
fix(web): system voices read in the chosen language
Yash-Singh1 Nov 15, 2026
4bcf36a
fix(read-aloud): download progress waits for each catalog request
Yash-Singh1 Nov 15, 2026
f37d2b2
chore(audio-cpp): drop the unused test runner dependency
Yash-Singh1 Nov 15, 2026
4a907ab
fix(read-aloud): stalled providers fail, mobile can cancel downloads,…
Yash-Singh1 Nov 15, 2026
e90bc99
fix(read-aloud): resolve the key per piece and claim a download befor…
Yash-Singh1 Nov 15, 2026
28343fe
fix(read-aloud): resolve the speech key after building each request
Yash-Singh1 Nov 15, 2026
668aba2
fix(read-aloud): removals and installs do not overlap, cloud pieces f…
Yash-Singh1 Nov 15, 2026
aeb6dc4
fix(read-aloud): claim a model install before reading which runtimes …
Yash-Singh1 Nov 15, 2026
058f5e0
feat(read-aloud): local speech uses pingdotgg/audio.cpp builds with G…
Yash-Singh1 Nov 16, 2026
aaf838b
fix(read-aloud): a request waiting for the local model can be cancelled
Yash-Singh1 Nov 16, 2026
c1d3407
feat(server): run local speech models on Windows arm64
Yash-Singh1 Nov 16, 2026
ae2609e
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 16, 2026
5c53151
fix(server): local and PCM read-aloud audio is no longer near-silent
Yash-Singh1 Nov 17, 2026
ad99a83
feat(read-aloud): use a local speech model file already on the enviro…
Yash-Singh1 Nov 17, 2026
5ec77d1
fix(read-aloud): headings, list items, and table rows are spoken as s…
Yash-Singh1 Nov 17, 2026
220e1db
feat(read-aloud): choose between Supertonic 3 and Pocket TTS local mo…
Yash-Singh1 Nov 17, 2026
089bc95
feat(read-aloud): Kokoro is the default local voice, with af_heart
Yash-Singh1 Nov 17, 2026
7761251
feat(read-aloud): ElevenLabs voices and transcription, and mark the r…
Yash-Singh1 Nov 17, 2026
d05d1c5
fix(read-aloud): settings match dictation's destination menu and mode…
Yash-Singh1 Nov 18, 2026
f38e01e
fix(read-aloud): hosted providers are set up in a key dialog, like di…
Yash-Singh1 Nov 18, 2026
9a73c99
fix(read-aloud): stop the preview on leaving settings and start Kokor…
Yash-Singh1 Nov 18, 2026
452cf85
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 18, 2026
e071334
fix(read-aloud): translate the read-aloud UI and address review findings
Yash-Singh1 Nov 18, 2026
8fb4819
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 22, 2026
9659435
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 23, 2026
2321103
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 24, 2026
fab3ea8
fix(server): the CLI executable loads the MP3 encoder from disk
Yash-Singh1 Nov 24, 2026
1153f4c
Merge remote-tracking branch 'origin/main' into feat/read-aloud-provi…
Yash-Singh1 Nov 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/mobile/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ const config: ExpoConfig = {
{
microphonePermission: "Allow T3 Code to use your microphone for voice input.",
recordAudioAndroid: true,
enableBackgroundPlayback: false,
enableBackgroundPlayback: true,
enableBackgroundRecording: false,
},
],
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"expo-secure-store": "~58.0.2",
"expo-sensors": "~58.0.4",
"expo-sharing": "58.0.22",
"expo-speech": "~58.0.3",
"expo-splash-screen": "~58.0.13",
"expo-sqlite": "~58.0.15",
"expo-symbols": "~58.0.4",
Expand Down
64 changes: 64 additions & 0 deletions apps/mobile/src/features/read-aloud/ReadAloudButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useEffect, useSyncExternalStore } from "react";
import { useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import { DEFAULT_READ_ALOUD_SETTINGS } from "@t3tools/contracts";
import { useGT } from "gt-react-native";
import { Pressable } from "react-native";
import { mobilePreferencesAtom } from "../../state/preferences";
import { SymbolView } from "../../components/ui/AppSymbol";
import * as Dialog from "../../components/ui/Dialog";
import { readAloudController, warmReadAloud } from "./playback";

export function ReadAloudButton({
id,
text,
buttonSize,
iconSize,
}: {
id: string;
text: string;
buttonSize: number;
iconSize: number;
}) {
const preferences = useAtomValue(mobilePreferencesAtom);
const settings = AsyncResult.isSuccess(preferences)
? (preferences.value.readAloud ?? DEFAULT_READ_ALOUD_SETTINGS)
: DEFAULT_READ_ALOUD_SETTINGS;
const state = useSyncExternalStore(
readAloudController.subscribe,
readAloudController.getSnapshot,
);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Loading the environment's local model while replies are on screen hides its startup from the first click.
useEffect(() => warmReadAloud(settings), [settings]);
const gt = useGT();
if (settings.provider === "off") return null;
const active = state.id === id;
const stoppable = active && (state.status === "playing" || state.status === "loading");
const label = stoppable
? gt("Stop reading")
: active && state.status === "paused"
? gt("Resume reading")
: gt("Read aloud");
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={label}
className="items-center justify-center"
style={{ width: buttonSize, height: buttonSize }}
onPress={async () => {
if (stoppable) return readAloudController.stop();
if (active && state.status === "paused") await readAloudController.resume();
else await readAloudController.start(id, text, settings);
const result = readAloudController.getSnapshot();
if (result.id === id && result.status === "error")
Dialog.alert(gt("Could not read aloud"), result.error);
}}
>
<SymbolView
name={stoppable ? "stop.fill" : "play"}
size={iconSize}
tintColorClassName="accent-foreground-secondary"
/>
</Pressable>
);
}
295 changes: 295 additions & 0 deletions apps/mobile/src/features/read-aloud/playback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
import { startSpeechSynthesis } from "@t3tools/client-runtime/voice-input";
import { DEFAULT_READ_ALOUD_SETTINGS, EnvironmentId } from "@t3tools/contracts";
import { expect, it, vi } from "vite-plus/test";
import * as Speech from "expo-speech";
import { AppState, Platform } from "react-native";
import { createAudioPlayer, setAudioModeAsync, type AudioStatus } from "expo-audio";
import { acquireAudioSession, releaseAudioSession } from "../../lib/audioSession";
import { readAloudController } from "./playback";

vi.mock("react-native", () => ({
AppState: {
get currentState() {
return "active";
},
addEventListener: () => ({ remove() {} }),
},
Platform: {
get OS() {
return "ios";
},
},
}));
vi.mock("expo-speech", () => ({
getAvailableVoicesAsync: vi.fn(async () => []),
speak: vi.fn(),
resume: vi.fn(async () => {}),
pause: vi.fn(async () => {}),
stop: vi.fn(async () => {}),
}));
vi.mock("expo-audio", () => ({
AudioModule: { setAudioSessionOwner: vi.fn() },
setAudioModeAsync: vi.fn(async () => {}),
setIsAudioActiveAsync: vi.fn(async () => {}),
createAudioPlayer: vi.fn(),
}));
vi.mock("../../state/atom-registry", async () => {
const Option = await import("effect/Option");
return { appAtomRegistry: { get: () => Option.some({ environmentId: "host" }) } };
});
vi.mock("../../state/session", () => ({
environmentSession: { preparedConnectionValueAtom: () => null },
}));
vi.mock("@t3tools/client-runtime/voice-input", () => ({
startSpeechSynthesis: vi.fn(() => ({ kind: "audio" })),
getSpeechSynthesisModels: vi.fn((_prepared: unknown, provider: string) => ({
kind: "catalog",
provider,
})),
}));
vi.mock("../voice-input/voiceDestination", async () => {
const { EMPTY_SPEECH_SYNTHESIS_CATALOG } = await import("@t3tools/contracts");
return {
runSpeech: async (operation: { kind: string; provider?: string }) =>
operation.kind === "catalog"
? {
...EMPTY_SPEECH_SYNTHESIS_CATALOG,
defaultModel: "server-model",
speedAppliedByProvider: operation.provider !== "openrouter",
}
: "https://host.test/api/voice/synthesis/audio?token=stream",
};
});

it("falls back from a removed system voice and completes playback", async () => {
vi.mocked(Speech.getAvailableVoicesAsync).mockResolvedValue([]);
vi.mocked(Speech.speak).mockImplementation((_text, options) => options?.onDone?.());
try {
await readAloudController.start("system", "reply", {
...DEFAULT_READ_ALOUD_SETTINGS,
provider: "system",
voice: "removed-voice",
});
expect(Speech.speak).toHaveBeenLastCalledWith(
"reply.",
expect.not.objectContaining({ voice: "removed-voice" }),
);
expect(readAloudController.getSnapshot().status).toBe("idle");
} finally {
readAloudController.stop();
}
});

it("removes lock-screen playback when recording takes audio focus", async () => {
const started = Promise.withResolvers<void>();
const playing = Promise.withResolvers<void>();
const unsubscribe = readAloudController.subscribe(() => {
if (readAloudController.getSnapshot().status === "playing") playing.resolve();
});
using cleanup = new DisposableStack();
cleanup.defer(() => {
readAloudController.stop();
unsubscribe();
});
const player = {
play: vi.fn(() => started.resolve()),
pause: vi.fn(),
release: vi.fn(),
setPlaybackRate: vi.fn(),
setActiveForLockScreen: vi.fn(),
addListener:
vi.fn<(_event: string, listener: (status: Partial<AudioStatus>) => void) => void>(),
};
vi.mocked(createAudioPlayer).mockReturnValue(
player as unknown as ReturnType<typeof createAudioPlayer>,
);
const run = readAloudController.start("cloud", "reply", {
...DEFAULT_READ_ALOUD_SETTINGS,
provider: "openrouter",
speed: 1.25,
environmentId: EnvironmentId.make("host"),
backgroundPlayback: true,
});
await started.promise;
await playing.promise;
expect(player.setPlaybackRate).toHaveBeenCalledWith(1.25);
expect(createAudioPlayer).toHaveBeenLastCalledWith(
"https://host.test/api/voice/synthesis/audio?token=stream",
expect.anything(),
);
expect(startSpeechSynthesis).toHaveBeenLastCalledWith(
expect.anything(),
"openrouter",
expect.objectContaining({ model: "server-model", speed: 1.25 }),
);
const statusChanged = player.addListener.mock.calls[0]![1];
statusChanged({
currentTime: 1,
duration: 10,
playing: false,
isLoaded: true,
isBuffering: true,
timeControlStatus: "waiting",
});
expect(readAloudController.getSnapshot().status).toBe("playing");
statusChanged({
currentTime: 10,
duration: 10,
playing: false,
isLoaded: true,
isBuffering: false,
timeControlStatus: "paused",
});
expect(readAloudController.getSnapshot().status).toBe("playing");
statusChanged({
currentTime: 1,
duration: 10,
playing: false,
isLoaded: true,
isBuffering: false,
timeControlStatus: "paused",
});
expect(readAloudController.getSnapshot().status).toBe("paused");
expect(player.setActiveForLockScreen).toHaveBeenLastCalledWith(true, expect.anything());
const pausedRecorder = acquireAudioSession("recording");
try {
expect(player.setActiveForLockScreen).toHaveBeenLastCalledWith(false);
} finally {
await releaseAudioSession(pausedRecorder);
}
await readAloudController.resume();
statusChanged({
currentTime: 1,
duration: 10,
playing: false,
isLoaded: true,
isBuffering: false,
timeControlStatus: "paused",
});
const resumed = Promise.withResolvers<void>();
const unsubscribeResume = readAloudController.subscribe(() => {
if (readAloudController.getSnapshot().status === "playing") resumed.resolve();
});
cleanup.defer(unsubscribeResume);
statusChanged({ playing: true, isLoaded: true });
await resumed.promise;
const recorder = acquireAudioSession("recording");
try {
expect(player.setActiveForLockScreen).toHaveBeenLastCalledWith(false);
} finally {
readAloudController.stop();
await run;
await releaseAudioSession(recorder);
unsubscribe();
}
});

it("keeps a reply resumable when recording takes focus while playback activates", async () => {
const activating = Promise.withResolvers<void>();
const activated = Promise.withResolvers<void>();
vi.mocked(setAudioModeAsync).mockImplementationOnce(async () => {
activating.resolve();
await activated.promise;
});
vi.mocked(createAudioPlayer).mockReturnValue({
play: vi.fn(),
pause: vi.fn(),
release: vi.fn(),
setPlaybackRate: vi.fn(),
setActiveForLockScreen: vi.fn(),
addListener: vi.fn(),
} as unknown as ReturnType<typeof createAudioPlayer>);
const settled = Promise.withResolvers<string>();
const unsubscribe = readAloudController.subscribe(() => {
const { status } = readAloudController.getSnapshot();
if (status === "playing" || status === "error") settled.resolve(status);
});
void readAloudController.start("cloud", "reply", {
...DEFAULT_READ_ALOUD_SETTINGS,
provider: "openai",
environmentId: EnvironmentId.make("host"),
});
await activating.promise;
const recorder = acquireAudioSession("recording");
try {
expect(readAloudController.getSnapshot().status).toBe("paused");
activated.resolve();
await readAloudController.resume();
expect(await settled.promise).toBe("playing");
} finally {
unsubscribe();
readAloudController.stop();
await releaseAudioSession(recorder);
}
});

it("cancels Android default speech while the native engine initializes", async () => {
using _os = vi.spyOn(Platform, "OS", "get").mockReturnValue("android");
const loading = Promise.withResolvers<void>();
const initialized = Promise.withResolvers<Speech.Voice[]>();
vi.mocked(Speech.getAvailableVoicesAsync).mockClear();
vi.mocked(Speech.getAvailableVoicesAsync).mockImplementationOnce(() => {
loading.resolve();
return initialized.promise;
});
vi.mocked(Speech.speak).mockClear();
const run = readAloudController.start("android", "reply", {
...DEFAULT_READ_ALOUD_SETTINGS,
provider: "system",
voice: "",
});
expect(Speech.getAvailableVoicesAsync).toHaveBeenCalled();
await loading.promise;
readAloudController.stop();
initialized.resolve([]);
await run;
expect(Speech.speak).not.toHaveBeenCalled();
});

it.each(["system", "xai"] as const)(
"keeps %s silent when backgrounded during activation",
async (provider) => {
using state = vi.spyOn(AppState, "currentState", "get").mockReturnValue("active");
const activating = Promise.withResolvers<void>();
const activated = Promise.withResolvers<void>();
vi.mocked(setAudioModeAsync).mockImplementationOnce(async () => {
activating.resolve();
await activated.promise;
});
const play = vi.fn();
vi.mocked(Speech.speak).mockClear();
const player = {
play,
pause: vi.fn(),
release: vi.fn(),
addListener: vi.fn(),
setActiveForLockScreen: vi.fn(),
};
vi.mocked(createAudioPlayer).mockReturnValue(
player as unknown as ReturnType<typeof createAudioPlayer>,
);
const paused = Promise.withResolvers<void>();
const unsubscribe = readAloudController.subscribe(() => {
if (["paused", "playing"].includes(readAloudController.getSnapshot().status))
paused.resolve();
});
const run = readAloudController.start("activation", "reply", {
...DEFAULT_READ_ALOUD_SETTINGS,
provider,
environmentId: EnvironmentId.make("host"),
backgroundPlayback: false,
});
try {
await activating.promise;
state.mockReturnValue("background");
activated.resolve();
await paused.promise;
expect(play).not.toHaveBeenCalled();
expect(Speech.speak).not.toHaveBeenCalled();
} finally {
readAloudController.stop();
await run;
unsubscribe();
}
},
);
Loading
Loading