- 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() {
extension_settings.audio.enabled = $('#audio_enabled').is(':checked');
if (extension_settings.audio.enabled) {
$("#audio_character_bgm").play();
$("#audio_ambient").play();
$("#audio_character_bgm")[0].play();
$("#audio_ambient")[0].play();
} else {
$("#audio_character_bgm").pause();
$("#audio_ambient").pause();
$("#audio_character_bgm")[0].pause();
$("#audio_ambient")[0].pause();
}
saveSettingsDebounced();
}
@ -239,12 +239,12 @@ async function moduleWorker() {
let newBackground = $("#bg1").css("background-image");
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") {
currentBackground = newBackground;
console.debug(DEBUG_PREFIX,"Changing ambient audio");
//console.debug(DEBUG_PREFIX,"Changing ambient audio");
updateAmbient();
}
@ -290,7 +290,7 @@ async function moduleWorker() {
// HACK: use sprite file name as expression detection
const spriteFile = $("#expression-image").attr("src");
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)) {
console.debug(DEBUG_PREFIX,"Not a valid expression, ignored");
@ -312,14 +312,15 @@ async function moduleWorker() {
async function updateBGM() {
const audio_files = characterMusics[currentCharacter][currentExpression];
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)
.then(response => {
if (!response.ok) {
console.log("<MUSIC module> File not found!")
console.log(DEBUG_PREFIX,"File not found!")
}
else {
console.log("<MUSIC module> Playing emotion",currentExpression)
console.log(DEBUG_PREFIX,"Switching BGM to ",currentExpression)
const audio = $("#audio_character_bgm");
audio.animate({volume: 0.0}, 2000, function() {
@ -334,14 +335,15 @@ async function updateBGM() {
async function updateAmbient() {
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)
.then(response => {
if (!response.ok) {
console.log("<MUSIC module> File not found!")
console.log(DEBUG_PREFIX,"File not found!")
}
else {
console.log("<MUSIC module> Changing ambient audio for",currentBackground)
console.log(DEBUG_PREFIX,"Switching ambient to ",currentBackground)
const audio = $("#audio_ambient");
audio.animate({volume: 0.0}, 2000, function() {

View File

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

View File

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