diff --git a/public/script.js b/public/script.js index ffd25d483..8ef9ec9a5 100644 --- a/public/script.js +++ b/public/script.js @@ -1910,7 +1910,7 @@ function sendSystemMessage(type, text, extra = {}) { return; } - const newMessage = { ...systemMessage, send_date: humanizedDateTime() }; + const newMessage = { ...systemMessage, send_date: getMessageTimeStamp() }; if (text) { newMessage.mes = text; diff --git a/public/scripts/extensions/caption/index.js b/public/scripts/extensions/caption/index.js index 89214a5ef..6e12684eb 100644 --- a/public/scripts/extensions/caption/index.js +++ b/public/scripts/extensions/caption/index.js @@ -1,6 +1,7 @@ import { getBase64Async } from "../../utils.js"; import { getContext, getApiUrl, doExtrasFetch, extension_settings } from "../../extensions.js"; import { callPopup, saveSettingsDebounced } from "../../../script.js"; +import { getMessageTimeStamp } from "../../RossAscends-mods.js"; export { MODULE_NAME }; const MODULE_NAME = 'caption'; @@ -52,7 +53,7 @@ async function sendCaptionedMessage(caption, image) { name: context.name1, is_user: true, is_name: true, - send_date: Date.now(), + send_date: getMessageTimeStamp(), mes: messageText, extra: { image: image, diff --git a/public/scripts/extensions/speech-recognition/index.js b/public/scripts/extensions/speech-recognition/index.js index e5b0ae116..8678b6bcd 100644 --- a/public/scripts/extensions/speech-recognition/index.js +++ b/public/scripts/extensions/speech-recognition/index.js @@ -4,11 +4,12 @@ TODO: */ import { saveSettingsDebounced } from "../../../script.js"; -import { getContext, getApiUrl, modules, extension_settings, ModuleWorkerWrapper, doExtrasFetch } from "../../extensions.js"; +import { getContext, extension_settings, ModuleWorkerWrapper } from "../../extensions.js"; import { VoskSttProvider } from './vosk.js' import { WhisperSttProvider } from './whisper.js' import { BrowserSttProvider } from './browser.js' import { StreamingSttProvider } from './streaming.js' +import { getMessageTimeStamp } from "../../RossAscends-mods.js"; export { MODULE_NAME }; const MODULE_NAME = 'Speech Recognition'; @@ -61,10 +62,10 @@ async function moduleWorker() { let messageStart = -1; if (extension_settings.speech_recognition.Streaming.triggerWordsEnabled) { - + for (const triggerWord of extension_settings.speech_recognition.Streaming.triggerWords) { const triggerPos = userMessageRaw.indexOf(triggerWord.toLowerCase()); - + // Trigger word not found or not starting message and just a substring if (triggerPos == -1){ // | (triggerPos > 0 & userMessageFormatted[triggerPos-1] != " ")) { console.debug(DEBUG_PREFIX+"trigger word not found: ", triggerWord); @@ -152,12 +153,12 @@ async function processTranscript(transcript) { name: context.name1, is_user: true, is_name: true, - send_date: Date.now(), + send_date: getMessageTimeStamp(), mes: messageText, }; context.chat.push(message); context.addOneMessage(message); - + await context.generate(); $('#debug_output').text(": message sent: \""+ transcriptFormatted +"\""); @@ -191,10 +192,10 @@ async function processTranscript(transcript) { function loadNavigatorAudioRecording() { if (navigator.mediaDevices.getUserMedia) { console.debug(DEBUG_PREFIX+' getUserMedia supported by browser.'); - + let onSuccess = function(stream) { const mediaRecorder = new MediaRecorder(stream); - + $("#microphone_button").off('click').on("click", function() { if (!audioRecording) { mediaRecorder.start(); @@ -211,30 +212,30 @@ function loadNavigatorAudioRecording() { $("#microphone_button").toggleClass('fa-microphone fa-microphone-slash'); } }); - + mediaRecorder.onstop = async function() { console.debug(DEBUG_PREFIX+"data available after MediaRecorder.stop() called: ", audioChunks.length, " chunks"); const audioBlob = new Blob(audioChunks, { type: "audio/wav; codecs=0" }); audioChunks = []; - + const transcript = await sttProvider.processAudio(audioBlob); - + // TODO: lock and release recording while processing? console.debug(DEBUG_PREFIX+"received transcript:", transcript); processTranscript(transcript); } - + mediaRecorder.ondataavailable = function(e) { audioChunks.push(e.data); } } - + let onError = function(err) { console.debug(DEBUG_PREFIX+"The following error occured: " + err); } - + navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError); - + } else { console.debug(DEBUG_PREFIX+"getUserMedia not supported on your browser!"); toastr.error("getUserMedia not supported", DEBUG_PREFIX+"not supported for your browser.", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); @@ -257,7 +258,7 @@ function loadSttProvider(provider) { console.warn(`Provider ${sttProviderName} not in Extension Settings, initiatilizing provider in settings`); extension_settings.speech_recognition[sttProviderName] = {}; } - + $('#speech_recognition_provider').val(sttProviderName); if (sttProviderName == "None") { @@ -287,13 +288,13 @@ function loadSttProvider(provider) { loadNavigatorAudioRecording(); $("#microphone_button").show(); } - + if (sttProviderName == "Streaming") { sttProvider.loadSettings(extension_settings.speech_recognition[sttProviderName]); $("#microphone_button").off('click'); $("#microphone_button").hide(); } - + } function onSttProviderChange() { @@ -365,7 +366,7 @@ async function onMessageMappingChange() { console.debug(DEBUG_PREFIX+"Wrong syntax for message mapping, no '=' found in:", text); } } - + $("#speech_recognition_message_mapping_status").text("Message mapping updated to: "+JSON.stringify(extension_settings.speech_recognition.messageMapping)) console.debug(DEBUG_PREFIX+"Updated message mapping", extension_settings.speech_recognition.messageMapping); extension_settings.speech_recognition.messageMappingText = $('#speech_recognition_message_mapping').val() @@ -425,7 +426,7 @@ $(document).ready(function () { $('#speech_recognition_message_mode').on('change', onMessageModeChange); $('#speech_recognition_message_mapping').on('change', onMessageMappingChange); $('#speech_recognition_message_mapping_enabled').on('click', onMessageMappingEnabledClick); - + const $button = $('
'); $('#send_but_sheld').prepend($button); diff --git a/public/scripts/group-chats.js b/public/scripts/group-chats.js index ab6a1e0fd..589809df1 100644 --- a/public/scripts/group-chats.js +++ b/public/scripts/group-chats.js @@ -9,7 +9,7 @@ import { saveBase64AsFile, PAGINATION_TEMPLATE, } from './utils.js'; -import { RA_CountCharTokens, humanizedDateTime, dragElement, favsToHotswap } from "./RossAscends-mods.js"; +import { RA_CountCharTokens, humanizedDateTime, dragElement, favsToHotswap, getMessageTimeStamp } from "./RossAscends-mods.js"; import { loadMovingUIState, sortEntitiesList } from './power-user.js'; import { @@ -202,7 +202,7 @@ function getFirstCharacterMessage(character) { mes["is_system"] = false; mes["name"] = character.name; mes["is_name"] = true; - mes["send_date"] = humanizedDateTime(); + mes["send_date"] = getMessageTimeStamp(); mes["original_avatar"] = character.avatar; mes["extra"] = { "gen_id": Date.now() * Math.random() * 1000000 }; mes["mes"] = messageText diff --git a/public/scripts/slash-commands.js b/public/scripts/slash-commands.js index 73aa98e25..eb2c2e15d 100644 --- a/public/scripts/slash-commands.js +++ b/public/scripts/slash-commands.js @@ -22,7 +22,7 @@ import { reloadCurrentChat, sendMessageAsUser, } from "../script.js"; -import { humanizedDateTime } from "./RossAscends-mods.js"; +import { getMessageTimeStamp } from "./RossAscends-mods.js"; import { resetSelectedGroup } from "./group-chats.js"; import { getRegexedString, regex_placement } from "./extensions/regex/engine.js"; import { chat_styles, power_user } from "./power-user.js"; @@ -327,7 +327,7 @@ async function sendMessageAs(_, text) { is_user: false, is_name: true, is_system: isSystem, - send_date: humanizedDateTime(), + send_date: getMessageTimeStamp(), mes: substituteParams(mesText), force_avatar: force_avatar, original_avatar: original_avatar, @@ -358,7 +358,7 @@ async function sendNarratorMessage(_, text) { is_user: false, is_name: false, is_system: isSystem, - send_date: humanizedDateTime(), + send_date: getMessageTimeStamp(), mes: substituteParams(text.trim()), force_avatar: system_avatar, extra: { @@ -384,7 +384,7 @@ async function sendCommentMessage(_, text) { is_user: false, is_name: true, is_system: true, - send_date: humanizedDateTime(), + send_date: getMessageTimeStamp(), mes: substituteParams(text.trim()), force_avatar: comment_avatar, extra: {