diff --git a/public/sounds/ambient/.placeholder b/public/assets/audio/ambient/.placeholder similarity index 100% rename from public/sounds/ambient/.placeholder rename to public/assets/audio/ambient/.placeholder diff --git a/public/sounds/bgm/.placeholder b/public/assets/audio/bgm/.placeholder similarity index 100% rename from public/sounds/bgm/.placeholder rename to public/assets/audio/bgm/.placeholder diff --git a/public/scripts/extensions/audio/index.js b/public/scripts/extensions/audio/index.js index c9be046d5..68d8571ac 100644 --- a/public/scripts/extensions/audio/index.js +++ b/public/scripts/extensions/audio/index.js @@ -58,10 +58,9 @@ const DEFAULT_EXPRESSIONS = [ "neutral" ]; const SPRITE_DOM_ID = "#expression-image"; -const AMBIENT_FOLDER = "sounds/ambient/"; -let fallback_BGMS = []; // Initialized only once with module workers -let ambients = []; // Initialized only once with module workers +let fallback_BGMS = null; // Initialized only once with module workers +let ambients = null; // Initialized only once with module workers let characterMusics = {}; // Updated with module workers let currentCharacterBGM = null; @@ -259,7 +258,7 @@ $(document).ready(function () { //#############################// async function getAmbientList() { - console.debug(DEBUG_PREFIX, "getting ambient adio files"); + console.debug(DEBUG_PREFIX, "getting ambient audio files"); try { const result = await fetch(`/get_default_ambient_list`); @@ -556,7 +555,7 @@ async function updateAmbient() { let audio_file_path = null; for(const i of ambients) { console.debug(i) - if (i.includes(currentBackground)) { + if (i.includes(decodeURIComponent(currentBackground))) { audio_file_path = i; break; } @@ -571,6 +570,7 @@ async function updateAmbient() { console.log(DEBUG_PREFIX,"Updating ambient"); console.log(DEBUG_PREFIX,"Checking file",audio_file_path); + const audio = $("#audio_ambient"); audio.animate({volume: 0.0}, 2000, function() { audio.attr("src",audio_file_path); audio[0].play(); diff --git a/public/scripts/extensions/audio/manifest.json b/public/scripts/extensions/audio/manifest.json index 1e48f5c3b..746362cc7 100644 --- a/public/scripts/extensions/audio/manifest.json +++ b/public/scripts/extensions/audio/manifest.json @@ -1,5 +1,5 @@ { - "display_name": "Sounds", + "display_name": "Audio", "loading_order": 14, "requires": [], "optional": ["classify"], diff --git a/server.js b/server.js index 18e9edf19..c66f109fb 100644 --- a/server.js +++ b/server.js @@ -317,8 +317,9 @@ const directories = { instruct: 'public/instruct', context: 'public/context', backups: 'backups/', - quickreplies: 'public/QuickReplies' - // TODO: add ambient music here + quickreplies: 'public/QuickReplies', + assets_bgm: 'public/assets/audio/bgm', + assets_ambient: 'public/assets/audio/ambient' }; // CSRF Protection // @@ -4943,32 +4944,27 @@ app.post('/delete_extension', jsonParser, async (request, response) => { * @returns {void} */ app.get('/get_default_bgm_list', jsonParser, function (request, response) { - const AUDIO_FOLDER = "sounds"; - const BGM_FOLDER = "bgm"; - const musicsPath = path.join(AUDIO_FOLDER,BGM_FOLDER); - let musics = []; + const musicsPath = directories.assets_bgm; + let files = []; + let files_paths = []; + console.info("Checking audio file into",musicsPath); try { if (fs.existsSync(musicsPath) && fs.statSync(musicsPath).isDirectory()) { - musics = fs.readdirSync(musicsPath) + files = fs.readdirSync(musicsPath) .filter(file => { const mimeType = mime.lookup(file); return mimeType && mimeType.startsWith('audio/'); - }) - .map((file) => { - const pathToMusic = path.join(musicsPath, file); - return { - label: path.parse(pathToMusic).name.toLowerCase(), - path: `/${AUDIO_FOLDER}/${BGM_FOLDER}/${file}`, - }; }); + for(const i of files) + files_paths.push(`/assets/audio/bgm/${i}`); } } catch (err) { console.log(err); } finally { - return response.send(musics); + return response.send(files_paths); } }); @@ -4981,32 +4977,27 @@ app.get('/get_default_bgm_list', jsonParser, function (request, response) { * @returns {void} */ app.get('/get_default_ambient_list', jsonParser, function (request, response) { - const AUDIO_FOLDER = "sounds"; - const BGM_FOLDER = "ambient"; - const musicsPath = path.join(AUDIO_FOLDER,BGM_FOLDER); - let musics = []; + const musicsPath = directories.assets_ambient; + let files = []; + let files_paths = []; + console.info("Checking audio file into",musicsPath); try { if (fs.existsSync(musicsPath) && fs.statSync(musicsPath).isDirectory()) { - musics = fs.readdirSync(musicsPath) + files = fs.readdirSync(musicsPath) .filter(file => { const mimeType = mime.lookup(file); return mimeType && mimeType.startsWith('audio/'); - }) - .map((file) => { - const pathToMusic = path.join(musicsPath, file); - return { - label: path.parse(pathToMusic).name.toLowerCase(), - path: `/${AUDIO_FOLDER}/${BGM_FOLDER}/${file}`, - }; }); + for(const i of files) + files_paths.push(path.join(`/assets/audio/ambient/${i}`)); } } catch (err) { console.log(err); } finally { - return response.send(musics); + return response.send(files_paths); } });