mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +08:00
fix: unlock speech playback with a playable silent WAV
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user