Files
OPEN_CODEX_API/src/utils/sound.ts
T
2026-03-18 01:07:27 -03:00

26 lines
940 B
TypeScript

/**
* Toca um som curto de sucesso (dois tons) usando Web Audio API.
* Não requer arquivos de áudio.
*/
export function playSuccessSound(): void {
try {
const ctx = new (window.AudioContext || (window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext)();
const playTone = (frequency: number, startTime: number, duration: number) => {
const osc = ctx.createOscillator();
const gain = ctx.createGain();
osc.connect(gain);
gain.connect(ctx.destination);
osc.frequency.value = frequency;
osc.type = "sine";
gain.gain.setValueAtTime(0.15, startTime);
gain.gain.exponentialRampToValueAtTime(0.01, startTime + duration);
osc.start(startTime);
osc.stop(startTime + duration);
};
playTone(523.25, 0, 0.15);
playTone(659.25, 0.18, 0.2);
} catch {
// Ignora se AudioContext não for suportado ou bloqueado (autoplay policy)
}
}