From dec476ab9b8602225964cfa534bb004676ff6419 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Fri, 29 Mar 2024 00:06:11 -0400 Subject: Update frontend --- fig-frontend-client/src/Audio.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 fig-frontend-client/src/Audio.js (limited to 'fig-frontend-client/src/Audio.js') diff --git a/fig-frontend-client/src/Audio.js b/fig-frontend-client/src/Audio.js new file mode 100644 index 0000000..2a9ae54 --- /dev/null +++ b/fig-frontend-client/src/Audio.js @@ -0,0 +1,30 @@ +let initialized = false; +let ctx = null; +let voiceTracks = null; + +function initializeCtx() { + if (!initialized) { + try { + initialized = true; + ctx = new window.AudioContext(); + voiceTracks = [ + document.getElementById("lcolonq-audio-voice-0"), + document.getElementById("lcolonq-audio-voice-1"), + document.getElementById("lcolonq-audio-voice-2"), + document.getElementById("lcolonq-audio-voice-3"), + document.getElementById("lcolonq-audio-voice-4"), + document.getElementById("lcolonq-audio-voice-5"), + document.getElementById("lcolonq-audio-voice-6"), + ]; + } catch (e) { + initialized = false; + } + } +} + +export const _playVoice = (b) => (i) => () => { + if (b) initializeCtx(); + try { + if (initialized) voiceTracks[i].play(); + } catch (e) {} +}; -- cgit v1.2.3