Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions js/components/home.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { checkConnection } from "../api/checkconnection.mjs";
import { sendkml } from "../api/sendkml.mjs";
import { showballoon } from "../api/balloon.mjs";
import { flytoview } from "../api/flytoview.mjs";
import { stopAllSounds } from "../utils/audio.mjs";
import "./voice.mjs";
import {exportprocessQueryExternally} from "./voice.mjs"
import "./sample-queries-tab.mjs";
Expand Down Expand Up @@ -223,18 +224,3 @@ export class Home extends HTMLElement {
}
}
}

const oceanSound = new Audio('./assets/ocean.mp3');
const fireSound = new Audio('./assets/fire.mp3');

oceanSound.loop = true;
fireSound.loop = true;
fireSound.volume = 0.25;
oceanSound.volume = 0.25;

function stopAllSounds() {
oceanSound.pause();
fireSound.pause();
oceanSound.currentTime = 0;
fireSound.currentTime = 0;
}
45 changes: 2 additions & 43 deletions js/components/voice.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { flytoview } from "../api/flytoview.mjs";
import { startOrbit } from "../api/orbit.mjs";
import { stopOrbit } from "../api/orbit.mjs";
import { showballoon } from "../api/balloon.mjs";
import { stopAllSounds, playSoundscapeBasedOnText } from "../utils/audio.mjs";
import ReadAloudComponent from "./read-aloud.mjs";
customElements.define("read-aloud", ReadAloudComponent);

Expand Down Expand Up @@ -823,49 +824,7 @@ export class LGVoice extends HTMLElement {
}
}

const oceanSound = new Audio('./assets/ocean.mp3');
const fireSound = new Audio('./assets/fire.mp3');

oceanSound.loop = true;
fireSound.loop = true;
fireSound.volume = 0.15;
oceanSound.volume = 0.15;

function stopAllSounds() {
oceanSound.pause();
fireSound.pause();
oceanSound.currentTime = 0;
fireSound.currentTime = 0;
}

function playSoundscapeBasedOnText(text) {
stopAllSounds();

const lower = text.toLowerCase();
let soundToPlay = null;

if (lower.includes("ocean") || lower.includes("sea") || lower.includes("wave") || lower.includes("beach") || lower.includes("coast") || lower.includes("island") || lower.includes("tsunami") || lower.includes("flood") || lower.includes("water")) {
soundToPlay = oceanSound;
} else if (lower.includes("fire") || lower.includes("burning") || lower.includes("flame") || lower.includes("campfire") || lower.includes("wildfire")) {
soundToPlay = fireSound;
}

if (soundToPlay) {
soundToPlay.play().then(() => {
console.log("Sound started");
}).catch(err => {
console.error("Play error:", err);
});

setTimeout(() => {
soundToPlay.pause();
soundToPlay.currentTime = 0;
console.log("Sound stopped");
}, 10000);
}
}

customElements.define("lg-voice", LGVoice);
customElements.define("lg-voice", LGVoice);

export async function exportprocessQueryExternally(query) {
const lgVoiceInstance = document.querySelector("lg-voice");
Expand Down
43 changes: 43 additions & 0 deletions js/utils/audio.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const oceanSound = new Audio('./assets/ocean.mp3');
const fireSound = new Audio('./assets/fire.mp3');

oceanSound.loop = true;
fireSound.loop = true;
oceanSound.volume = 0.25;
fireSound.volume = 0.25;

function stopAllSounds() {
oceanSound.pause();
fireSound.pause();
oceanSound.currentTime = 0;
fireSound.currentTime = 0;
}

function playSoundscapeBasedOnText(text) {
stopAllSounds();

const lower = text.toLowerCase();
let soundToPlay = null;

if (lower.includes("ocean") || lower.includes("sea") || lower.includes("wave") || lower.includes("beach") || lower.includes("coast") || lower.includes("island") || lower.includes("tsunami") || lower.includes("flood") || lower.includes("water")) {
soundToPlay = oceanSound;
} else if (lower.includes("fire") || lower.includes("burning") || lower.includes("flame") || lower.includes("campfire") || lower.includes("wildfire")) {
soundToPlay = fireSound;
}

if (soundToPlay) {
soundToPlay.play().then(() => {
console.log("Sound started");
}).catch(err => {
console.error("Play error:", err);
});

setTimeout(() => {
soundToPlay.pause();
soundToPlay.currentTime = 0;
console.log("Sound stopped");
}, 10000);
}
}

export { oceanSound, fireSound, stopAllSounds, playSoundscapeBasedOnText };