Spaces:
Running
Running
Download static/js/audio.js from alphappp/PromptDialog-demo: direct link, hf CLI and curl.
- Browser
- Download file 791 Bytes
-
https://huggingface.co/spaces/alphappp/PromptDialog-demo/resolve/main/static/js/audio.js
- Command line
-
hf download hf://spaces/alphappp/PromptDialog-demo/static/js/audio.js
-
curl -L -o audio.js https://huggingface.co/spaces/alphappp/PromptDialog-demo/resolve/main/static/js/audio.js
791 Bytes
| export async function fetchText(path) { | |
| const response = await fetch(path, { cache: "no-cache" }); | |
| if (!response.ok) { | |
| throw new Error(`Failed to load ${path}`); | |
| } | |
| return response.text(); | |
| } | |
| export function createAudio(src) { | |
| const audio = document.createElement("audio"); | |
| audio.controls = true; | |
| audio.preload = "none"; | |
| audio.src = src; | |
| audio.setAttribute("aria-label", "Play speech sample"); | |
| audio.addEventListener("play", () => { | |
| document.querySelectorAll("audio").forEach((other) => { | |
| if (other !== audio) other.pause(); | |
| }); | |
| }); | |
| return audio; | |
| } | |
| export function escapeHtml(text) { | |
| return String(text ?? "").replace(/[&<>"']/g, (char) => ({ | |
| "&": "&", | |
| "<": "<", | |
| ">": ">", | |
| '"': """, | |
| "'": "'" | |
| }[char])); | |
| } | |