diff --git a/public/index.html b/public/index.html index 46a2e81b5..f65aa4960 100644 --- a/public/index.html +++ b/public/index.html @@ -1084,9 +1084,20 @@

Power User Options

+ -
diff --git a/public/notes/message_sound.html b/public/notes/message_sound.html new file mode 100644 index 000000000..2bb1a89fc --- /dev/null +++ b/public/notes/message_sound.html @@ -0,0 +1,30 @@ + + + + Message Sound + + + + + + + + + +
+
+

Message Sound

+

To play your own custom sound on receiving a new message from bot, replace the following MP3 file in your TavernAI folder:

+ + public/sounds/message.mp3 + + + Plays at 80% volume. + +
+
+ + + \ No newline at end of file diff --git a/public/script.js b/public/script.js index 54c6768bf..8e86ac76d 100644 --- a/public/script.js +++ b/public/script.js @@ -41,6 +41,7 @@ import { import { collapseNewlines, loadPowerUserSettings, + playMessageSound, power_user, } from "./scripts/power-user.js"; @@ -1796,6 +1797,7 @@ async function Generate(type, automatic_trigger, force_name2) { //getMessage = getMessage.replace(/^\s+/g, ''); if (getMessage.length > 0) { ({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name)); + playMessageSound(); generate_loop_counter = 0; } else { ++generate_loop_counter; diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index d92e579a1..b95973ee5 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -3,6 +3,7 @@ import { saveSettingsDebounced } from "../script.js"; export { loadPowerUserSettings, collapseNewlines, + playMessageSound, power_user, }; @@ -35,6 +36,7 @@ let power_user = { avatar_style: avatar_styles.ROUND, chat_display: chat_styles.DEFAULT, sheld_width: sheld_width.DEFAULT, + play_message_sound: false, }; const storage_keys = { @@ -53,6 +55,18 @@ const storage_keys = { sheld_width: "TavernAI_sheld_width" }; +function playMessageSound() { + if (!power_user.play_message_sound) { + return; + } + + const audio = document.getElementById('audio_message_sound'); + audio.volume = 0.8; + audio.pause(); + audio.currentTime = 0; + audio.play(); +} + function collapseNewlines(x) { return x.replaceAll(/\n+/g, "\n"); } @@ -129,6 +143,7 @@ function loadPowerUserSettings(settings) { $("#custom_chat_separator").val(power_user.custom_chat_separator); $("#fast_ui_mode").prop("checked", power_user.fast_ui_mode); $("#multigen").prop("checked", power_user.multigen); + $("#play_message_sound").prop("checked", power_user.play_message_sound); $(`input[name="avatar_style"][value="${power_user.avatar_style}"]`).prop("checked", true); $(`input[name="chat_display"][value="${power_user.chat_display}"]`).prop("checked", true); $(`input[name="sheld_width"][value="${power_user.sheld_width}"]`).prop("checked", true); @@ -199,10 +214,16 @@ $(document).ready(() => { localStorage.setItem(storage_keys.chat_display, power_user.chat_display); applyChatDisplay(); }); + $(`input[name="sheld_width"]`).on('input', function (e) { power_user.sheld_width = Number(e.target.value); localStorage.setItem(storage_keys.sheld_width, power_user.sheld_width); console.log("sheld width changing now"); applySheldWidth(); }); + + $("#play_message_sound").on('input', function () { + power_user.play_message_sound = !!$(this).prop('checked'); + saveSettingsDebounced(); + }); }); \ No newline at end of file diff --git a/public/sounds/message.mp3 b/public/sounds/message.mp3 new file mode 100644 index 000000000..e7c1af321 Binary files /dev/null and b/public/sounds/message.mp3 differ