mirror of
				https://github.com/SillyTavern/SillyTavern.git
				synced 2025-06-05 21:59:27 +02:00 
			
		
		
		
	Add message sound option
This commit is contained in:
		| @@ -1084,9 +1084,20 @@ | |||||||
|                 <div id="power-user-options-block"> |                 <div id="power-user-options-block"> | ||||||
|                     <h3>Power User Options</h3> |                     <h3>Power User Options</h3> | ||||||
|                     <div id="power-user-option-checkboxes"> |                     <div id="power-user-option-checkboxes"> | ||||||
|  |                         <label for="swipes-checkbox"> | ||||||
|  |                             <input id="swipes-checkbox" type="checkbox" /> | ||||||
|  |                             Swipes | ||||||
|  |                         </label> | ||||||
|  |  | ||||||
|                         <label for="auto-load-chat-checkbox"><input id="auto-load-chat-checkbox" type="checkbox" /> |                         <label for="play_message_sound" class="checkbox_label"> | ||||||
|                             Auto-load Last Chat |                             <input id="play_message_sound" type="checkbox" /> | ||||||
|  |                             <audio id="audio_message_sound" src="sounds/message.mp3" hidden></audio> | ||||||
|  |                             <span> | ||||||
|  |                                 Play a sound on new message  | ||||||
|  |                                 <a href="/notes/message_sound" class="notes-link" target="_blank"> | ||||||
|  |                                     <span class="note-link-span">?</span> | ||||||
|  |                                 </a> | ||||||
|  |                             </span> | ||||||
|                         </label> |                         </label> | ||||||
|  |  | ||||||
|                         <label for="fast_ui_mode" class="checkbox_label" title="Blur can cause browser lag, especially in Bubble Chat mode. To fix: Turn on your browser's Hardware Acceleration, and restart your browser or simply disable the blur effect with this toggle."> |                         <label for="fast_ui_mode" class="checkbox_label" title="Blur can cause browser lag, especially in Bubble Chat mode. To fix: Turn on your browser's Hardware Acceleration, and restart your browser or simply disable the blur effect with this toggle."> | ||||||
| @@ -1094,8 +1105,8 @@ | |||||||
|                             No Blur Effect |                             No Blur Effect | ||||||
|                         </label> |                         </label> | ||||||
|  |  | ||||||
|                         <label for="swipes-checkbox"><input id="swipes-checkbox" type="checkbox" /> |                         <label for="auto-load-chat-checkbox"><input id="auto-load-chat-checkbox" type="checkbox" /> | ||||||
|                             Swipes |                             Auto-load Last Chat | ||||||
|                         </label> |                         </label> | ||||||
|                     </div> |                     </div> | ||||||
|                 </div> |                 </div> | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								public/notes/message_sound.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								public/notes/message_sound.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | <html> | ||||||
|  |  | ||||||
|  | <head> | ||||||
|  |     <title>Message Sound</title> | ||||||
|  |     <link rel="stylesheet" href="/css/notes.css"> | ||||||
|  |     <meta charset="UTF-8"> | ||||||
|  |     <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||||||
|  |     <link rel="preconnect" href="https://fonts.googleapis.com"> | ||||||
|  |     <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin=""> | ||||||
|  |     <link | ||||||
|  |         href="https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" | ||||||
|  |         rel="stylesheet"> | ||||||
|  | </head> | ||||||
|  |  | ||||||
|  | <body> | ||||||
|  |     <div id="main"> | ||||||
|  |         <div id="content"> | ||||||
|  |             <h2>Message Sound</h2> | ||||||
|  |             <p>To play your own custom sound on receiving a new message from bot, replace the following MP3 file in your TavernAI folder:</p> | ||||||
|  |             <code> | ||||||
|  |                 public/sounds/message.mp3 | ||||||
|  |             </code> | ||||||
|  |             <small> | ||||||
|  |                 Plays at 80% volume. | ||||||
|  |             </small> | ||||||
|  |         </div> | ||||||
|  |     </div> | ||||||
|  | </body> | ||||||
|  |  | ||||||
|  | </html> | ||||||
| @@ -41,6 +41,7 @@ import { | |||||||
| import { | import { | ||||||
|     collapseNewlines, |     collapseNewlines, | ||||||
|     loadPowerUserSettings, |     loadPowerUserSettings, | ||||||
|  |     playMessageSound, | ||||||
|     power_user, |     power_user, | ||||||
| } from "./scripts/power-user.js"; | } from "./scripts/power-user.js"; | ||||||
|  |  | ||||||
| @@ -1796,6 +1797,7 @@ async function Generate(type, automatic_trigger, force_name2) { | |||||||
|                     //getMessage = getMessage.replace(/^\s+/g, ''); |                     //getMessage = getMessage.replace(/^\s+/g, ''); | ||||||
|                     if (getMessage.length > 0) { |                     if (getMessage.length > 0) { | ||||||
|                         ({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name)); |                         ({ type, getMessage } = saveReply(type, getMessage, this_mes_is_name)); | ||||||
|  |                         playMessageSound(); | ||||||
|                         generate_loop_counter = 0; |                         generate_loop_counter = 0; | ||||||
|                     } else { |                     } else { | ||||||
|                         ++generate_loop_counter; |                         ++generate_loop_counter; | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ import { saveSettingsDebounced } from "../script.js"; | |||||||
| export { | export { | ||||||
|     loadPowerUserSettings, |     loadPowerUserSettings, | ||||||
|     collapseNewlines, |     collapseNewlines, | ||||||
|  |     playMessageSound, | ||||||
|     power_user, |     power_user, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| @@ -35,6 +36,7 @@ let power_user = { | |||||||
|     avatar_style: avatar_styles.ROUND, |     avatar_style: avatar_styles.ROUND, | ||||||
|     chat_display: chat_styles.DEFAULT, |     chat_display: chat_styles.DEFAULT, | ||||||
|     sheld_width: sheld_width.DEFAULT, |     sheld_width: sheld_width.DEFAULT, | ||||||
|  |     play_message_sound: false, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const storage_keys = { | const storage_keys = { | ||||||
| @@ -53,6 +55,18 @@ const storage_keys = { | |||||||
|     sheld_width: "TavernAI_sheld_width" |     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) { | function collapseNewlines(x) { | ||||||
|     return x.replaceAll(/\n+/g, "\n"); |     return x.replaceAll(/\n+/g, "\n"); | ||||||
| } | } | ||||||
| @@ -129,6 +143,7 @@ function loadPowerUserSettings(settings) { | |||||||
|     $("#custom_chat_separator").val(power_user.custom_chat_separator); |     $("#custom_chat_separator").val(power_user.custom_chat_separator); | ||||||
|     $("#fast_ui_mode").prop("checked", power_user.fast_ui_mode); |     $("#fast_ui_mode").prop("checked", power_user.fast_ui_mode); | ||||||
|     $("#multigen").prop("checked", power_user.multigen); |     $("#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="avatar_style"][value="${power_user.avatar_style}"]`).prop("checked", true); | ||||||
|     $(`input[name="chat_display"][value="${power_user.chat_display}"]`).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); |     $(`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); |         localStorage.setItem(storage_keys.chat_display, power_user.chat_display); | ||||||
|         applyChatDisplay(); |         applyChatDisplay(); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|     $(`input[name="sheld_width"]`).on('input', function (e) { |     $(`input[name="sheld_width"]`).on('input', function (e) { | ||||||
|         power_user.sheld_width = Number(e.target.value); |         power_user.sheld_width = Number(e.target.value); | ||||||
|         localStorage.setItem(storage_keys.sheld_width, power_user.sheld_width); |         localStorage.setItem(storage_keys.sheld_width, power_user.sheld_width); | ||||||
|         console.log("sheld width changing now"); |         console.log("sheld width changing now"); | ||||||
|         applySheldWidth(); |         applySheldWidth(); | ||||||
|     }); |     }); | ||||||
|  |  | ||||||
|  |     $("#play_message_sound").on('input', function () { | ||||||
|  |         power_user.play_message_sound = !!$(this).prop('checked'); | ||||||
|  |         saveSettingsDebounced(); | ||||||
|  |     }); | ||||||
| }); | }); | ||||||
							
								
								
									
										
											BIN
										
									
								
								public/sounds/message.mp3
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								public/sounds/message.mp3
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user