chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"use client";
|
||||
|
||||
export let globalAudio: any = undefined;
|
||||
|
||||
export function resetGlobalAudio() {
|
||||
if (globalAudio) {
|
||||
globalAudio.pause();
|
||||
globalAudio.currentTime = 0;
|
||||
} else {
|
||||
globalAudio = new Audio();
|
||||
}
|
||||
}
|
||||
|
||||
export async function speak(text: string) {
|
||||
const encodedText = encodeURIComponent(text);
|
||||
const url = `/api/tts?text=${encodedText}`;
|
||||
globalAudio.src = url;
|
||||
globalAudio.play();
|
||||
await new Promise<void>((resolve) => {
|
||||
globalAudio.onended = function () {
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
}
|
||||
Reference in New Issue
Block a user