- Added user to character list for mapping
    - Audio
        - Corrected initialization of extension settings
        - reduce debug logs
    - Coqui:
        - Added user to character list for mapping
This commit is contained in:
Tony Ribeiro 2023-08-20 20:46:53 +02:00
parent a57a3d6188
commit 5acb764caf
3 changed files with 87 additions and 79 deletions

View File

@ -78,11 +78,11 @@ function loadSettings() {
async function onEnabledClick() { async function onEnabledClick() {
extension_settings.audio.enabled = $('#audio_enabled').is(':checked'); extension_settings.audio.enabled = $('#audio_enabled').is(':checked');
if (extension_settings.audio.enabled) { if (extension_settings.audio.enabled) {
$("#audio_character_bgm").play(); $("#audio_character_bgm")[0].play();
$("#audio_ambient").play(); $("#audio_ambient")[0].play();
} else { } else {
$("#audio_character_bgm").pause(); $("#audio_character_bgm")[0].pause();
$("#audio_ambient").pause(); $("#audio_ambient")[0].pause();
} }
saveSettingsDebounced(); saveSettingsDebounced();
} }
@ -239,12 +239,12 @@ async function moduleWorker() {
let newBackground = $("#bg1").css("background-image"); let newBackground = $("#bg1").css("background-image");
newBackground = newBackground.substring(newBackground.lastIndexOf("/")+1).replace(/\.[^/.]+$/, ""); newBackground = newBackground.substring(newBackground.lastIndexOf("/")+1).replace(/\.[^/.]+$/, "");
console.debug(DEBUG_PREFIX,"Current backgroung:",newBackground); //console.debug(DEBUG_PREFIX,"Current backgroung:",newBackground);
if (currentBackground !== newBackground & newBackground != "none") { if (currentBackground !== newBackground & newBackground != "none") {
currentBackground = newBackground; currentBackground = newBackground;
console.debug(DEBUG_PREFIX,"Changing ambient audio"); //console.debug(DEBUG_PREFIX,"Changing ambient audio");
updateAmbient(); updateAmbient();
} }
@ -290,7 +290,7 @@ async function moduleWorker() {
// HACK: use sprite file name as expression detection // HACK: use sprite file name as expression detection
const spriteFile = $("#expression-image").attr("src"); const spriteFile = $("#expression-image").attr("src");
newExpression = spriteFile.substring(spriteFile.lastIndexOf("/")+1).replace(/\.[^/.]+$/, ""); newExpression = spriteFile.substring(spriteFile.lastIndexOf("/")+1).replace(/\.[^/.]+$/, "");
console.debug(DEBUG_PREFIX,"Current expression",newExpression); //console.debug(DEBUG_PREFIX,"Current expression",newExpression);
if (!EXPRESSIONS_LIST.includes(newExpression)) { if (!EXPRESSIONS_LIST.includes(newExpression)) {
console.debug(DEBUG_PREFIX,"Not a valid expression, ignored"); console.debug(DEBUG_PREFIX,"Not a valid expression, ignored");
@ -312,14 +312,15 @@ async function moduleWorker() {
async function updateBGM() { async function updateBGM() {
const audio_files = characterMusics[currentCharacter][currentExpression]; const audio_files = characterMusics[currentCharacter][currentExpression];
const audio_file_path = audio_files[Math.floor(Math.random() * audio_files.length)]; // random pick const audio_file_path = audio_files[Math.floor(Math.random() * audio_files.length)]; // random pick
console.log("<MUSIC module> Checking audio file",audio_file_path) console.log(DEBUG_PREFIX,"Updating BGM");
console.log(DEBUG_PREFIX,"Checking file",audio_file_path);
fetch(audio_file_path) fetch(audio_file_path)
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
console.log("<MUSIC module> File not found!") console.log(DEBUG_PREFIX,"File not found!")
} }
else { else {
console.log("<MUSIC module> Playing emotion",currentExpression) console.log(DEBUG_PREFIX,"Switching BGM to ",currentExpression)
const audio = $("#audio_character_bgm"); const audio = $("#audio_character_bgm");
audio.animate({volume: 0.0}, 2000, function() { audio.animate({volume: 0.0}, 2000, function() {
@ -334,14 +335,15 @@ async function updateBGM() {
async function updateAmbient() { async function updateAmbient() {
const audio_file_path = AMBIENT_FOLDER+currentBackground+".mp3"; const audio_file_path = AMBIENT_FOLDER+currentBackground+".mp3";
console.log("<MUSIC module> Changing ambient audio for",audio_file_path) console.log(DEBUG_PREFIX,"Updating ambient");
console.log(DEBUG_PREFIX,"Checking file",audio_file_path)
fetch(audio_file_path) fetch(audio_file_path)
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
console.log("<MUSIC module> File not found!") console.log(DEBUG_PREFIX,"File not found!")
} }
else { else {
console.log("<MUSIC module> Changing ambient audio for",currentBackground) console.log(DEBUG_PREFIX,"Switching ambient to ",currentBackground)
const audio = $("#audio_ambient"); const audio = $("#audio_ambient");
audio.animate({volume: 0.0}, 2000, function() { audio.animate({volume: 0.0}, 2000, function() {

View File

@ -55,6 +55,9 @@ const defaultSettings = {
} }
function loadSettings() { function loadSettings() {
if (extension_settings.rvc === undefined)
extension_settings.rvc = {};
if (Object.keys(extension_settings.rvc).length === 0) { if (Object.keys(extension_settings.rvc).length === 0) {
Object.assign(extension_settings.rvc, defaultSettings) Object.assign(extension_settings.rvc, defaultSettings)
} }
@ -459,11 +462,13 @@ async function moduleWorker() {
function updateCharactersList() { function updateCharactersList() {
let currentcharacters = new Set(); let currentcharacters = new Set();
for (const i of getContext().characters) { const context = getContext();
for (const i of context.characters) {
currentcharacters.add(i.name); currentcharacters.add(i.name);
} }
currentcharacters = Array.from(currentcharacters) currentcharacters = Array.from(currentcharacters);
currentcharacters.unshift(context.name1);
if (JSON.stringify(charactersList) !== JSON.stringify(currentcharacters)) { if (JSON.stringify(charactersList) !== JSON.stringify(currentcharacters)) {
charactersList = currentcharacters charactersList = currentcharacters

View File

@ -40,6 +40,12 @@ const languageLabels = {
"ja": "Japanese" "ja": "Japanese"
} }
const defaultSettings = {
voiceMap: "",
voiceMapDict: {}
}
function throwIfModuleMissing() { function throwIfModuleMissing() {
if (!modules.includes('coqui-tts')) { if (!modules.includes('coqui-tts')) {
toastr.error(`Add coqui-tts to enable-modules and restart the Extras API.`, "Coqui TTS module not loaded.", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Add coqui-tts to enable-modules and restart the Extras API.`, "Coqui TTS module not loaded.", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
@ -54,11 +60,13 @@ function resetModelSettings() {
function updateCharactersList() { function updateCharactersList() {
let currentcharacters = new Set(); let currentcharacters = new Set();
for (const i of getContext().characters) { const context = getContext();
for (const i of context.characters) {
currentcharacters.add(i.name); currentcharacters.add(i.name);
} }
currentcharacters = Array.from(currentcharacters) currentcharacters = Array.from(currentcharacters);
currentcharacters.unshift(context.name1);
if (JSON.stringify(charactersList) !== JSON.stringify(currentcharacters)) { if (JSON.stringify(charactersList) !== JSON.stringify(currentcharacters)) {
charactersList = currentcharacters charactersList = currentcharacters
@ -83,11 +91,13 @@ class CoquiTtsProvider {
// Extension UI and Settings // // Extension UI and Settings //
//#############################// //#############################//
settings static instance;
settings = {};
defaultSettings = { // Singleton to allow acces to instance in event functions
voiceMap: "", constructor() {
voiceMapDict: {} if (CoquiTtsProvider.instance === undefined)
CoquiTtsProvider.instance = this;
} }
get settingsHtml() { get settingsHtml() {
@ -145,8 +155,12 @@ class CoquiTtsProvider {
} }
loadSettings(settings) { loadSettings(settings) {
if (Object.keys(this.settings).length === 0) {
Object.assign(this.settings, defaultSettings)
}
// Only accept keys defined in defaultSettings // Only accept keys defined in defaultSettings
this.settings = this.defaultSettings this.settings = defaultSettings;
for (const key in settings) { for (const key in settings) {
if (key in this.settings) { if (key in this.settings) {
@ -156,7 +170,7 @@ class CoquiTtsProvider {
} }
} }
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
$("#coqui_api_model_div").hide(); $("#coqui_api_model_div").hide();
$("#coqui_local_model_div").hide(); $("#coqui_local_model_div").hide();
@ -167,24 +181,12 @@ class CoquiTtsProvider {
$("#coqui_api_model_install_status").hide(); $("#coqui_api_model_install_status").hide();
$("#coqui_api_model_install_button").hide(); $("#coqui_api_model_install_button").hide();
let that = this $("#coqui_model_origin").on("change", CoquiTtsProvider.onModelOriginChange);
$("#coqui_model_origin").on("change", function () { that.onModelOriginChange() }); $("#coqui_api_language").on("change", CoquiTtsProvider.onModelLanguageChange);
$("#coqui_api_language").on("change", function () { that.onModelLanguageChange() }); $("#coqui_api_model_name").on("change", CoquiTtsProvider.onModelNameChange);
$("#coqui_api_model_name").on("change", function () { that.onModelNameChange() }); $("#coqui_remove_char_mapping").on("click", CoquiTtsProvider.onRemoveClick);
$("#coqui_remove_char_mapping").on("click", function () { that.onRemoveClick() }); updateCharactersList();
// Load characters list
$('#coqui_character_select')
.find('option')
.remove()
.end()
.append('<option value="none">Select Character</option>')
.val('none')
for (const charName of charactersList) {
$("#coqui_character_select").append(new Option(charName, charName));
}
// Load coqui-api settings from json file // Load coqui-api settings from json file
fetch("/scripts/extensions/tts/coqui_api_models_settings.json") fetch("/scripts/extensions/tts/coqui_api_models_settings.json")
@ -227,34 +229,30 @@ class CoquiTtsProvider {
}); });
} }
updateVoiceMap() { static updateVoiceMap() {
this.settings.voiceMap = ""; CoquiTtsProvider.instance.settings.voiceMap = "";
for (let i in this.settings.voiceMapDict) { for (let i in CoquiTtsProvider.instance.settings.voiceMapDict) {
const voice_settings = this.settings.voiceMapDict[i]; const voice_settings = CoquiTtsProvider.instance.settings.voiceMapDict[i];
this.settings.voiceMap += i + ":" + voice_settings["model_id"]; CoquiTtsProvider.instance.settings.voiceMap += i + ":" + voice_settings["model_id"];
if (voice_settings["model_language"] != null) if (voice_settings["model_language"] != null)
this.settings.voiceMap += "[" + voice_settings["model_language"] + "]"; CoquiTtsProvider.instance.settings.voiceMap += "[" + voice_settings["model_language"] + "]";
if (voice_settings["model_speaker"] != null) if (voice_settings["model_speaker"] != null)
this.settings.voiceMap += "[" + voice_settings["model_speaker"] + "]"; CoquiTtsProvider.instance.settings.voiceMap += "[" + voice_settings["model_speaker"] + "]";
this.settings.voiceMap += ","; CoquiTtsProvider.instance.settings.voiceMap += ",";
} }
$("#tts_voice_map").val(this.settings.voiceMap); $("#tts_voice_map").val(CoquiTtsProvider.instance.settings.voiceMap);
extension_settings.tts.Coqui = this.settings; //extension_settings.tts.Coqui = extension_settings.tts.Coqui;
} }
onSettingsChange() { onSettingsChange() {
console.debug(DEBUG_PREFIX, "Settings changes", this.settings); //console.debug(DEBUG_PREFIX, "Settings changes", CoquiTtsProvider.instance.settings);
extension_settings.tts.Coqui = this.settings; CoquiTtsProvider.updateVoiceMap();
} }
async onApplyClick() { async onApplyClick() {
if (inApiCall) {
return; // TOdo block dropdown
}
const character = $("#coqui_character_select").val(); const character = $("#coqui_character_select").val();
const model_origin = $("#coqui_model_origin").val(); const model_origin = $("#coqui_model_origin").val();
const model_language = $("#coqui_api_language").val(); const model_language = $("#coqui_api_language").val();
@ -262,16 +260,15 @@ class CoquiTtsProvider {
let model_setting_language = $("#coqui_api_model_settings_language").val(); let model_setting_language = $("#coqui_api_model_settings_language").val();
let model_setting_speaker = $("#coqui_api_model_settings_speaker").val(); let model_setting_speaker = $("#coqui_api_model_settings_speaker").val();
if (character === "none") { if (character === "none") {
toastr.error(`Character not selected, please select one.`, DEBUG_PREFIX + " voice mapping character", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Character not selected, please select one.`, DEBUG_PREFIX + " voice mapping character", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
if (model_origin == "none") { if (model_origin == "none") {
toastr.error(`Origin not selected, please select one.`, DEBUG_PREFIX + " voice mapping origin", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Origin not selected, please select one.`, DEBUG_PREFIX + " voice mapping origin", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
@ -280,25 +277,25 @@ class CoquiTtsProvider {
if (model_name == "none") { if (model_name == "none") {
toastr.error(`Model not selected, please select one.`, DEBUG_PREFIX + " voice mapping model", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Model not selected, please select one.`, DEBUG_PREFIX + " voice mapping model", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
this.settings.voiceMapDict[character] = { model_type: "local", model_id: "local/" + model_id }; CoquiTtsProvider.instance.settings.voiceMapDict[character] = { model_type: "local", model_id: "local/" + model_id };
console.debug(DEBUG_PREFIX, "Registered new voice map: ", character, ":", this.settings.voiceMapDict[character]); console.debug(DEBUG_PREFIX, "Registered new voice map: ", character, ":", CoquiTtsProvider.instance.settings.voiceMapDict[character]);
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
if (model_language == "none") { if (model_language == "none") {
toastr.error(`Language not selected, please select one.`, DEBUG_PREFIX + " voice mapping language", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Language not selected, please select one.`, DEBUG_PREFIX + " voice mapping language", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
if (model_name == "none") { if (model_name == "none") {
toastr.error(`Model not selected, please select one.`, DEBUG_PREFIX + " voice mapping model", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Model not selected, please select one.`, DEBUG_PREFIX + " voice mapping model", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
this.updateVoiceMap(); // Overide any manual modification CoquiTtsProvider.updateVoiceMap(); // Overide any manual modification
return; return;
} }
@ -327,13 +324,13 @@ class CoquiTtsProvider {
return; return;
} }
console.debug(DEBUG_PREFIX, "Current voice map: ", this.settings.voiceMap); console.debug(DEBUG_PREFIX, "Current voice map: ", CoquiTtsProvider.instance.settings.voiceMap);
this.settings.voiceMapDict[character] = { model_type: "coqui-api", model_id: model_id, model_language: model_setting_language, model_speaker: model_setting_speaker }; CoquiTtsProvider.instance.settings.voiceMapDict[character] = { model_type: "coqui-api", model_id: model_id, model_language: model_setting_language, model_speaker: model_setting_speaker };
console.debug(DEBUG_PREFIX, "Registered new voice map: ", character, ":", this.settings.voiceMapDict[character]); console.debug(DEBUG_PREFIX, "Registered new voice map: ", character, ":", CoquiTtsProvider.instance.settings.voiceMapDict[character]);
this.updateVoiceMap(); CoquiTtsProvider.updateVoiceMap();
let successMsg = character + ":" + model_id; let successMsg = character + ":" + model_id;
if (model_setting_language != null) if (model_setting_language != null)
@ -352,7 +349,7 @@ class CoquiTtsProvider {
return output; return output;
} }
async onRemoveClick() { static async onRemoveClick() {
const character = $("#coqui_character_select").val(); const character = $("#coqui_character_select").val();
if (character === "none") { if (character === "none") {
@ -361,11 +358,11 @@ class CoquiTtsProvider {
} }
// Todo erase from voicemap // Todo erase from voicemap
delete (this.settings.voiceMapDict[character]); delete (CoquiTtsProvider.instance.settings.voiceMapDict[character]);
this.updateVoiceMap(); // TODO CoquiTtsProvider.updateVoiceMap(); // TODO
} }
async onModelOriginChange() { static async onModelOriginChange() {
throwIfModuleMissing() throwIfModuleMissing()
resetModelSettings(); resetModelSettings();
const model_origin = $('#coqui_model_origin').val(); const model_origin = $('#coqui_model_origin').val();
@ -378,6 +375,9 @@ class CoquiTtsProvider {
// show coqui model selected list (SAFE) // show coqui model selected list (SAFE)
if (model_origin == "coqui-api") { if (model_origin == "coqui-api") {
$("#coqui_local_model_div").hide(); $("#coqui_local_model_div").hide();
$("#coqui_api_model_div").hide();
$("#coqui_api_model_name").hide();
$("#coqui_api_model_settings").hide();
$('#coqui_api_language') $('#coqui_api_language')
.find('option') .find('option')
@ -400,6 +400,9 @@ class CoquiTtsProvider {
// show coqui model full list (UNSAFE) // show coqui model full list (UNSAFE)
if (model_origin == "coqui-api-full") { if (model_origin == "coqui-api-full") {
$("#coqui_local_model_div").hide(); $("#coqui_local_model_div").hide();
$("#coqui_api_model_div").hide();
$("#coqui_api_model_name").hide();
$("#coqui_api_model_settings").hide();
$('#coqui_api_language') $('#coqui_api_language')
.find('option') .find('option')
@ -427,7 +430,7 @@ class CoquiTtsProvider {
} }
} }
async onModelLanguageChange() { static async onModelLanguageChange() {
throwIfModuleMissing(); throwIfModuleMissing();
resetModelSettings(); resetModelSettings();
$("#coqui_api_model_settings").hide(); $("#coqui_api_model_settings").hide();
@ -460,7 +463,7 @@ class CoquiTtsProvider {
} }
} }
async onModelNameChange() { static async onModelNameChange() {
throwIfModuleMissing(); throwIfModuleMissing();
resetModelSettings(); resetModelSettings();
$("#coqui_api_model_settings").hide(); $("#coqui_api_model_settings").hide();
@ -551,8 +554,6 @@ class CoquiTtsProvider {
$("#coqui_api_model_install_status").text("Model not found on extras server"); $("#coqui_api_model_install_status").text("Model not found on extras server");
} }
const onModelNameChange_pointer = this.onModelNameChange;
$("#coqui_api_model_install_button").off("click").on("click", async function () { $("#coqui_api_model_install_button").off("click").on("click", async function () {
try { try {
$("#coqui_api_model_install_status").text("Downloading model..."); $("#coqui_api_model_install_status").text("Downloading model...");
@ -566,7 +567,7 @@ class CoquiTtsProvider {
if (apiResult["status"] == "done") { if (apiResult["status"] == "done") {
$("#coqui_api_model_install_status").text("Model installed and ready to use!"); $("#coqui_api_model_install_status").text("Model installed and ready to use!");
$("#coqui_api_model_install_button").hide(); $("#coqui_api_model_install_button").hide();
onModelNameChange_pointer(); // TODO: error ? CoquiTtsProvider.onModelNameChange();
} }
if (apiResult["status"] == "downloading") { if (apiResult["status"] == "downloading") {
@ -577,7 +578,7 @@ class CoquiTtsProvider {
} catch (error) { } catch (error) {
console.error(error) console.error(error)
toastr.error(error, DEBUG_PREFIX + " error with model download", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(error, DEBUG_PREFIX + " error with model download", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
onModelNameChange_pointer(); CoquiTtsProvider.onModelNameChange();
} }
// will refresh model status // will refresh model status
}); });