fix: unlock speech playback with a playable silent WAV

This commit is contained in:
Bingxi Zhao (Frank)
2026-10-27 21:53:08 +08:00
parent 7c25ea96a0
commit 2ebc44a47f
2 changed files with 6 additions and 1 deletions

View File

@@ -1386,8 +1386,9 @@ export function CopyActionButton({
// Speaker button: synthesizes this one reply and plays it. Auto-play of later
// replies is a Settings preference (`autoPlayFresh`), not a first-click prompt.
let activePlayback: { owner: object; stop: () => void } | null = null;
// 50 ms of playable unsigned 8-bit PCM silence; an empty WAV cannot unlock playback.
const SILENT_UNLOCK_WAV =
"data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQAAAAA=";
"data:audio/wav;base64,UklGRrQBAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YZABAACAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA";
async function ttsErrorMessage(resp: Response): Promise<string> {
try {

View File

@@ -62,6 +62,10 @@ it("unlocks the audio element during the click before speech synthesis resolves"
expect(instances).toHaveLength(1);
expect(instances[0].play).toHaveBeenCalledTimes(1);
expect(instances[0].src).toContain("data:audio/wav");
const bytes = Uint8Array.from(atob(instances[0].src.split(",")[1]), (c) => c.charCodeAt(0));
const wav = new DataView(bytes.buffer);
expect(wav.getUint32(40, true)).toBeGreaterThan(0);
expect(bytes.length).toBe(44 + wav.getUint32(40, true));
expect(URL.createObjectURL).not.toHaveBeenCalled();
await act(async () => {