Reformat rvc/tts plugins

This commit is contained in:
Cohee
2023-08-17 12:05:17 +03:00
parent c4700b38fe
commit 50005b5617
2 changed files with 162 additions and 163 deletions

View File

@ -6,7 +6,7 @@ TODO:
import { saveSettingsDebounced } from "../../../script.js"; import { saveSettingsDebounced } from "../../../script.js";
import { getContext, getApiUrl, extension_settings, doExtrasFetch, ModuleWorkerWrapper, modules } from "../../extensions.js"; import { getContext, getApiUrl, extension_settings, doExtrasFetch, ModuleWorkerWrapper, modules } from "../../extensions.js";
export { MODULE_NAME, rvcVoiceConversion}; export { MODULE_NAME, rvcVoiceConversion };
const MODULE_NAME = 'RVC'; const MODULE_NAME = 'RVC';
const DEBUG_PREFIX = "<RVC module> " const DEBUG_PREFIX = "<RVC module> "
@ -16,9 +16,9 @@ let charactersList = [] // Updated with module worker
let rvcModelsList = [] // Initialized only once let rvcModelsList = [] // Initialized only once
let rvcModelsReceived = false; let rvcModelsReceived = false;
function updateVoiceMapText(){ function updateVoiceMapText() {
let voiceMapText = "" let voiceMapText = ""
for(let i in extension_settings.rvc.voiceMap) { for (let i in extension_settings.rvc.voiceMap) {
const voice_settings = extension_settings.rvc.voiceMap[i]; const voice_settings = extension_settings.rvc.voiceMap[i];
voiceMapText += i + ":" voiceMapText += i + ":"
+ voice_settings["modelName"] + "(" + voice_settings["modelName"] + "("
@ -34,7 +34,7 @@ function updateVoiceMapText(){
extension_settings.rvc.voiceMapText = voiceMapText; extension_settings.rvc.voiceMapText = voiceMapText;
$('#rvc_voice_map').val(voiceMapText); $('#rvc_voice_map').val(voiceMapText);
console.debug(DEBUG_PREFIX,"Updated voice map debug text to\n",voiceMapText) console.debug(DEBUG_PREFIX, "Updated voice map debug text to\n", voiceMapText)
} }
//#############################// //#############################//
@ -43,13 +43,13 @@ function updateVoiceMapText(){
const defaultSettings = { const defaultSettings = {
enabled: false, enabled: false,
model:"", model: "",
pitchOffset:0, pitchOffset: 0,
pitchExtraction:"dio", pitchExtraction: "dio",
indexRate:0.88, indexRate: 0.88,
filterRadius:3, filterRadius: 3,
rmsMixRate:1, rmsMixRate: 1,
protect:0.33, protect: 0.33,
voicMapText: "", voicMapText: "",
voiceMap: {} voiceMap: {}
} }
@ -58,7 +58,7 @@ function loadSettings() {
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)
} }
$('#rvc_enabled').prop('checked',extension_settings.rvc.enabled); $('#rvc_enabled').prop('checked', extension_settings.rvc.enabled);
$('#rvc_model').val(extension_settings.rvc.model); $('#rvc_model').val(extension_settings.rvc.model);
$('#rvc_pitch_extraction').val(extension_settings.rvc.pitchExtraction); $('#rvc_pitch_extraction').val(extension_settings.rvc.pitchExtraction);
@ -135,12 +135,12 @@ async function onApplyClick() {
const protect = $("#rvc_protect").val(); const protect = $("#rvc_protect").val();
if (character === "none") { if (character === "none") {
toastr.error("Character not selected.", DEBUG_PREFIX+" voice mapping apply", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error("Character not selected.", DEBUG_PREFIX + " voice mapping apply", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return; return;
} }
if (model_name == "none") { if (model_name == "none") {
toastr.error("Model not selected.", DEBUG_PREFIX+" voice mapping apply", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error("Model not selected.", DEBUG_PREFIX + " voice mapping apply", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return; return;
} }
@ -156,7 +156,7 @@ async function onApplyClick() {
updateVoiceMapText(); updateVoiceMapText();
console.debug(DEBUG_PREFIX,"Updated settings of ",character,":",extension_settings.rvc.voiceMap[character]) console.debug(DEBUG_PREFIX, "Updated settings of ", character, ":", extension_settings.rvc.voiceMap[character])
saveSettingsDebounced(); saveSettingsDebounced();
} }
@ -164,12 +164,12 @@ async function onDeleteClick() {
const character = $("#rvc_character_select").val(); const character = $("#rvc_character_select").val();
if (character === "none") { if (character === "none") {
toastr.error("Character not selected.", DEBUG_PREFIX+" voice mapping delete", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error("Character not selected.", DEBUG_PREFIX + " voice mapping delete", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return; return;
} }
delete extension_settings.rvc.voiceMap[character]; delete extension_settings.rvc.voiceMap[character];
console.debug(DEBUG_PREFIX,"Deleted settings of ",character); console.debug(DEBUG_PREFIX, "Deleted settings of ", character);
updateVoiceMapText(); updateVoiceMapText();
saveSettingsDebounced(); saveSettingsDebounced();
} }
@ -179,10 +179,10 @@ async function onClickUpload() {
const inputFiles = $("#rvc_model_upload_file").get(0).files; const inputFiles = $("#rvc_model_upload_file").get(0).files;
let formData = new FormData(); let formData = new FormData();
for(const file of inputFiles) for (const file of inputFiles)
formData.append(file.name, file); formData.append(file.name, file);
console.debug(DEBUG_PREFIX,"Sending files:",formData); console.debug(DEBUG_PREFIX, "Sending files:", formData);
url.pathname = '/api/voice-conversion/rvc/upload-models'; url.pathname = '/api/voice-conversion/rvc/upload-models';
const apiResult = await doExtrasFetch(url, { const apiResult = await doExtrasFetch(url, {
@ -191,7 +191,7 @@ async function onClickUpload() {
}); });
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Check extras console for errors log'); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' Check extras console for errors log');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -274,7 +274,7 @@ $(document).ready(function () {
`; `;
$('#extensions_settings').append(settingsHtml); $('#extensions_settings').append(settingsHtml);
$("#rvc_enabled").on("click", onEnabledClick); $("#rvc_enabled").on("click", onEnabledClick);
$("#rvc_voice_map").attr("disabled","disabled");; $("#rvc_voice_map").attr("disabled", "disabled");;
$('#rvc_pitch_extraction').on('change', onPitchExtractionChange); $('#rvc_pitch_extraction').on('change', onPitchExtractionChange);
$('#rvc_index_rate').on('input', onIndexRateChange); $('#rvc_index_rate').on('input', onIndexRateChange);
$('#rvc_filter_radius').on('input', onFilterRadiusChange); $('#rvc_filter_radius').on('input', onFilterRadiusChange);
@ -313,7 +313,7 @@ async function get_models_list(model_id) {
}); });
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Check model state request failed'); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' Check model state request failed');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -329,7 +329,7 @@ async function rvcVoiceConversion(response, character) {
// Check voice map // Check voice map
if (extension_settings.rvc.voiceMap[character] === undefined) { if (extension_settings.rvc.voiceMap[character] === undefined) {
//toastr.error("No model is assigned to character '"+character+"', check RVC voice map in the extension menu.", DEBUG_PREFIX+'RVC Voice map error', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); //toastr.error("No model is assigned to character '"+character+"', check RVC voice map in the extension menu.", DEBUG_PREFIX+'RVC Voice map error', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
console.info(DEBUG_PREFIX,"No RVC model assign in voice map for current character "+character); console.info(DEBUG_PREFIX, "No RVC model assign in voice map for current character " + character);
return response; return response;
} }
@ -337,7 +337,7 @@ async function rvcVoiceConversion(response, character) {
if (!audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm']) { if (!audioData.type in ['audio/mpeg', 'audio/wav', 'audio/x-wav', 'audio/wave', 'audio/webm']) {
throw `TTS received HTTP response with invalid data format. Expecting audio/mpeg, got ${audioData.type}` throw `TTS received HTTP response with invalid data format. Expecting audio/mpeg, got ${audioData.type}`
} }
console.log("Audio type received:",audioData.type) console.log("Audio type received:", audioData.type)
const voice_settings = extension_settings.rvc.voiceMap[character]; const voice_settings = extension_settings.rvc.voiceMap[character];
@ -364,7 +364,7 @@ async function rvcVoiceConversion(response, character) {
}); });
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' RVC Voice Conversion Failed', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' RVC Voice Conversion Failed', { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -387,12 +387,12 @@ async function refreshVoiceList() {
.append('<option value="none">Select Voice</option>') .append('<option value="none">Select Voice</option>')
.val('none') .val('none')
for(const modelName of rvcModelsList) { for (const modelName of rvcModelsList) {
$("#rvc_model_select").append(new Option(modelName,modelName)); $("#rvc_model_select").append(new Option(modelName, modelName));
} }
rvcModelsReceived = true rvcModelsReceived = true
console.debug(DEBUG_PREFIX,"Updated model list to:", rvcModelsList); console.debug(DEBUG_PREFIX, "Updated model list to:", rvcModelsList);
} }
async function moduleWorker() { async function moduleWorker() {
@ -421,10 +421,10 @@ function updateCharactersList() {
.append('<option value="none">Select Character</option>') .append('<option value="none">Select Character</option>')
.val('none') .val('none')
for(const charName of charactersList) { for (const charName of charactersList) {
$("#rvc_character_select").append(new Option(charName,charName)); $("#rvc_character_select").append(new Option(charName, charName));
} }
console.debug(DEBUG_PREFIX,"Updated character list to:", charactersList); console.debug(DEBUG_PREFIX, "Updated character list to:", charactersList);
} }
} }

View File

@ -4,7 +4,6 @@ TODO:
- Delete useless call - Delete useless call
*/ */
import { saveSettingsDebounced } from "../../../script.js"
import { doExtrasFetch, extension_settings, getApiUrl, getContext, modules, ModuleWorkerWrapper } from "../../extensions.js" import { doExtrasFetch, extension_settings, getApiUrl, getContext, modules, ModuleWorkerWrapper } from "../../extensions.js"
export { CoquiTtsProvider } export { CoquiTtsProvider }
@ -34,16 +33,16 @@ coquiApiModels format [language][dataset][name]:coqui-api-model-id, example:
*/ */
const languageLabels = { const languageLabels = {
"multilingual": "Multilingual", "multilingual": "Multilingual",
"en" : "English", "en": "English",
"fr" : "French", "fr": "French",
"es" : "Spanish", "es": "Spanish",
"ja" : "Japanese" "ja": "Japanese"
} }
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 });
throw new Error(DEBUG_PREFIX,`Coqui TTS module not loaded.`); throw new Error(DEBUG_PREFIX, `Coqui TTS module not loaded.`);
} }
} }
@ -70,11 +69,11 @@ function updateCharactersList() {
.append('<option value="none">Select Character</option>') .append('<option value="none">Select Character</option>')
.val('none') .val('none')
for(const charName of charactersList) { for (const charName of charactersList) {
$("#coqui_character_select").append(new Option(charName,charName)); $("#coqui_character_select").append(new Option(charName, charName));
} }
console.debug(DEBUG_PREFIX,"Updated character list to:", charactersList); console.debug(DEBUG_PREFIX, "Updated character list to:", charactersList);
} }
} }
@ -87,7 +86,7 @@ class CoquiTtsProvider {
defaultSettings = { defaultSettings = {
voiceMap: "", voiceMap: "",
voiceMapDict : {} voiceMapDict: {}
} }
get settingsHtml() { get settingsHtml() {
@ -148,11 +147,11 @@ class CoquiTtsProvider {
// Only accept keys defined in defaultSettings // Only accept keys defined in defaultSettings
this.settings = this.defaultSettings this.settings = this.defaultSettings
for (const key in settings){ for (const key in settings) {
if (key in this.settings){ if (key in this.settings) {
this.settings[key] = settings[key] this.settings[key] = settings[key]
} else { } else {
throw DEBUG_PREFIX+`Invalid setting passed to extension: ${key}` throw DEBUG_PREFIX + `Invalid setting passed to extension: ${key}`
} }
} }
@ -168,11 +167,11 @@ class CoquiTtsProvider {
$("#coqui_api_model_install_button").hide(); $("#coqui_api_model_install_button").hide();
let that = this let that = this
$("#coqui_model_origin").on("change",function(){that.onModelOriginChange()}); $("#coqui_model_origin").on("change", function () { that.onModelOriginChange() });
$("#coqui_api_language").on("change",function(){that.onModelLanguageChange()}); $("#coqui_api_language").on("change", function () { that.onModelLanguageChange() });
$("#coqui_api_model_name").on("change",function(){that.onModelNameChange()}); $("#coqui_api_model_name").on("change", function () { that.onModelNameChange() });
$("#coqui_remove_char_mapping").on("click", function(){that.onRemoveClick()}); $("#coqui_remove_char_mapping").on("click", function () { that.onRemoveClick() });
// Load characters list // Load characters list
$('#coqui_character_select') $('#coqui_character_select')
@ -182,8 +181,8 @@ class CoquiTtsProvider {
.append('<option value="none">Select Character</option>') .append('<option value="none">Select Character</option>')
.val('none') .val('none')
for(const charName of charactersList) { for (const charName of charactersList) {
$("#coqui_character_select").append(new Option(charName,charName)); $("#coqui_character_select").append(new Option(charName, charName));
} }
// Load coqui-api settings from json file // Load coqui-api settings from json file
@ -191,7 +190,7 @@ class CoquiTtsProvider {
.then(response => response.json()) .then(response => response.json())
.then(json => { .then(json => {
coquiApiModels = json; coquiApiModels = json;
console.debug(DEBUG_PREFIX,"initialized coqui-api model list to", coquiApiModels); console.debug(DEBUG_PREFIX, "initialized coqui-api model list to", coquiApiModels);
$('#coqui_api_language') $('#coqui_api_language')
.find('option') .find('option')
@ -200,16 +199,16 @@ class CoquiTtsProvider {
.append('<option value="none">Select model language</option>') .append('<option value="none">Select model language</option>')
.val('none'); .val('none');
for(let language in coquiApiModels) { for (let language in coquiApiModels) {
$("#coqui_api_language").append(new Option(languageLabels[language],language)); $("#coqui_api_language").append(new Option(languageLabels[language], language));
console.log(DEBUG_PREFIX,"added language",language); console.log(DEBUG_PREFIX, "added language", language);
} }
}); });
} }
updateVoiceMap(){ updateVoiceMap() {
this.settings.voiceMap = ""; this.settings.voiceMap = "";
for(let i in this.settings.voiceMapDict) { for (let i in this.settings.voiceMapDict) {
const voice_settings = this.settings.voiceMapDict[i]; const voice_settings = this.settings.voiceMapDict[i];
this.settings.voiceMap += i + ":" + voice_settings["model_id"]; this.settings.voiceMap += i + ":" + voice_settings["model_id"];
@ -226,7 +225,7 @@ class CoquiTtsProvider {
} }
onSettingsChange() { onSettingsChange() {
console.debug(DEBUG_PREFIX,"Settings changes",this.settings); console.debug(DEBUG_PREFIX, "Settings changes", this.settings);
extension_settings.tts.Coqui = this.settings; extension_settings.tts.Coqui = this.settings;
} }
@ -244,13 +243,13 @@ class CoquiTtsProvider {
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 this.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 this.updateVoiceMap(); // Overide any manual modification
return; return;
} }
@ -259,25 +258,25 @@ class CoquiTtsProvider {
const model_id = $("#coqui_local_model_name").val(); const model_id = $("#coqui_local_model_name").val();
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 this.updateVoiceMap(); // Overide any manual modification
return; return;
} }
this.settings.voiceMapDict[character] = {model_type: "local", model_id: "local/"+model_id}; 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]); console.debug(DEBUG_PREFIX, "Registered new voice map: ", character, ":", this.settings.voiceMapDict[character]);
this.updateVoiceMap(); // Overide any manual modification this.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 this.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 this.updateVoiceMap(); // Overide any manual modification
return; return;
} }
@ -294,37 +293,37 @@ class CoquiTtsProvider {
const model_id = "tts_models/" + model_language + "/" + model_dataset + "/" + model_label const model_id = "tts_models/" + model_language + "/" + model_dataset + "/" + model_label
if (model_setting_language == null & "languages" in coquiApiModels[model_language][model_dataset][model_label]) { if (model_setting_language == null & "languages" in coquiApiModels[model_language][model_dataset][model_label]) {
toastr.error(`Model language not selected, please select one.`, DEBUG_PREFIX+" voice mapping model language", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Model language not selected, please select one.`, DEBUG_PREFIX + " voice mapping model language", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return; return;
} }
if (model_setting_speaker == null & "speakers" in coquiApiModels[model_language][model_dataset][model_label]) { if (model_setting_speaker == null & "speakers" in coquiApiModels[model_language][model_dataset][model_label]) {
toastr.error(`Model speaker not selected, please select one.`, DEBUG_PREFIX+" voice mapping model speaker", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error(`Model speaker not selected, please select one.`, DEBUG_PREFIX + " voice mapping model speaker", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return; return;
} }
console.debug(DEBUG_PREFIX,"Current voice map: ",this.settings.voiceMap); console.debug(DEBUG_PREFIX, "Current voice map: ", this.settings.voiceMap);
this.settings.voiceMapDict[character] = {model_type: "coqui-api", model_id: model_id, model_language:model_setting_language, model_speaker:model_setting_speaker}; this.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, ":", this.settings.voiceMapDict[character]);
this.updateVoiceMap(); this.updateVoiceMap();
let successMsg = character+":"+model_id; let successMsg = character + ":" + model_id;
if (model_setting_language != null) if (model_setting_language != null)
successMsg += "[" + model_setting_language + "]"; successMsg += "[" + model_setting_language + "]";
if (model_setting_speaker != null) if (model_setting_speaker != null)
successMsg += "[" + model_setting_speaker + "]"; successMsg += "[" + model_setting_speaker + "]";
toastr.info(successMsg, DEBUG_PREFIX+" voice map updated", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.info(successMsg, DEBUG_PREFIX + " voice map updated", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return return
} }
// DBG: assume voiceName is correct // DBG: assume voiceName is correct
// TODO: check voice is correct // TODO: check voice is correct
async getVoice(voiceName) { async getVoice(voiceName) {
console.log(DEBUG_PREFIX,"getVoice",voiceName); console.log(DEBUG_PREFIX, "getVoice", voiceName);
const output = {voice_id: voiceName}; const output = { voice_id: voiceName };
return output; return output;
} }
@ -332,12 +331,12 @@ class CoquiTtsProvider {
const character = $("#coqui_character_select").val(); const character = $("#coqui_character_select").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 });
return; return;
} }
// Todo erase from voicemap // Todo erase from voicemap
delete(this.settings.voiceMapDict[character]); delete (this.settings.voiceMapDict[character]);
this.updateVoiceMap(); // TODO this.updateVoiceMap(); // TODO
} }
@ -386,11 +385,11 @@ class CoquiTtsProvider {
.append('<option value="none">Select model</option>') .append('<option value="none">Select model</option>')
.val('none'); .val('none');
for(let model_dataset in coquiApiModels[model_language]) for (let model_dataset in coquiApiModels[model_language])
for(let model_name in coquiApiModels[model_language][model_dataset]) { for (let model_name in coquiApiModels[model_language][model_dataset]) {
const model_id = model_dataset + "/" + model_name const model_id = model_dataset + "/" + model_name
const model_label = model_name + " ("+model_dataset+" dataset)" const model_label = model_name + " (" + model_dataset + " dataset)"
$("#coqui_api_model_name").append(new Option(model_label,model_id)); $("#coqui_api_model_name").append(new Option(model_label, model_id));
} }
} }
@ -424,9 +423,9 @@ class CoquiTtsProvider {
.append('<option value="none">Select language</option>') .append('<option value="none">Select language</option>')
.val('none'); .val('none');
for(var i = 0; i < model_settings["languages"].length; i++) { for (var i = 0; i < model_settings["languages"].length; i++) {
const language_label = JSON.stringify(model_settings["languages"][i]).replaceAll("\"",""); const language_label = JSON.stringify(model_settings["languages"][i]).replaceAll("\"", "");
$("#coqui_api_model_settings_language").append(new Option(language_label,i)); $("#coqui_api_model_settings_language").append(new Option(language_label, i));
} }
} }
else { else {
@ -443,9 +442,9 @@ class CoquiTtsProvider {
.append('<option value="none">Select speaker</option>') .append('<option value="none">Select speaker</option>')
.val('none'); .val('none');
for(var i = 0; i < model_settings["speakers"].length;i++) { for (var i = 0; i < model_settings["speakers"].length; i++) {
const speaker_label = JSON.stringify(model_settings["speakers"][i]).replaceAll("\"",""); const speaker_label = JSON.stringify(model_settings["speakers"][i]).replaceAll("\"", "");
$("#coqui_api_model_settings_speaker").append(new Option(speaker_label,i)); $("#coqui_api_model_settings_speaker").append(new Option(speaker_label, i));
} }
} }
else { else {
@ -457,12 +456,12 @@ class CoquiTtsProvider {
// Check if already installed and propose to do it otherwise // Check if already installed and propose to do it otherwise
const model_id = coquiApiModels[model_language][model_dataset][model_name]["id"] const model_id = coquiApiModels[model_language][model_dataset][model_name]["id"]
console.debug(DEBUG_PREFIX,"Check if model is already installed",model_id); console.debug(DEBUG_PREFIX, "Check if model is already installed", model_id);
let result = await CoquiTtsProvider.checkmodel_state(model_id); let result = await CoquiTtsProvider.checkmodel_state(model_id);
result = await result.json(); result = await result.json();
const model_state = result["model_state"]; const model_state = result["model_state"];
console.debug(DEBUG_PREFIX," Model state:", model_state) console.debug(DEBUG_PREFIX, " Model state:", model_state)
if (model_state == "installed") { if (model_state == "installed") {
$("#coqui_api_model_install_status").text("Model already installed on extras server"); $("#coqui_api_model_install_status").text("Model already installed on extras server");
@ -476,13 +475,13 @@ class CoquiTtsProvider {
$("#coqui_api_model_install_status").text("Model found but incomplete try install again (maybe still downloading)"); // (remove and download again) $("#coqui_api_model_install_status").text("Model found but incomplete try install again (maybe still downloading)"); // (remove and download again)
} }
else { else {
toastr.info("Click download button to install the model "+$("#coqui_api_model_name").find(":selected").text(), DEBUG_PREFIX+" model not installed", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.info("Click download button to install the model " + $("#coqui_api_model_name").find(":selected").text(), DEBUG_PREFIX + " model not installed", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
$("#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; 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...");
$("#coqui_api_model_install_button").hide(); $("#coqui_api_model_install_button").hide();
@ -490,7 +489,7 @@ class CoquiTtsProvider {
let apiResult = await CoquiTtsProvider.installModel(model_id, action); let apiResult = await CoquiTtsProvider.installModel(model_id, action);
apiResult = await apiResult.json(); apiResult = await apiResult.json();
console.debug(DEBUG_PREFIX,"Response:",apiResult); console.debug(DEBUG_PREFIX, "Response:", apiResult);
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!");
@ -499,13 +498,13 @@ class CoquiTtsProvider {
} }
if (apiResult["status"] == "downloading") { if (apiResult["status"] == "downloading") {
toastr.error("Check extras console for progress", DEBUG_PREFIX+" already downloading", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true }); toastr.error("Check extras console for progress", DEBUG_PREFIX + " already downloading", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
$("#coqui_api_model_install_status").text("Already downloading a model, check extras console!"); $("#coqui_api_model_install_status").text("Already downloading a model, check extras console!");
$("#coqui_api_model_install_button").show(); $("#coqui_api_model_install_button").show();
} }
} 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(); onModelNameChange_pointer();
} }
// will refresh model status // will refresh model status
@ -542,7 +541,7 @@ class CoquiTtsProvider {
}); });
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Check model state request failed'); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' Check model state request failed');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -567,7 +566,7 @@ class CoquiTtsProvider {
}); });
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Install model '+model_id+' request failed'); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' Install model ' + model_id + ' request failed');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -595,7 +594,7 @@ class CoquiTtsProvider {
}) })
if (!apiResult.ok) { if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Get local model list request failed'); toastr.error(apiResult.statusText, DEBUG_PREFIX + ' Get local model list request failed');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`); throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
} }
@ -614,10 +613,10 @@ class CoquiTtsProvider {
let language = "none" let language = "none"
let speaker = "none" let speaker = "none"
const tokens = voiceId.replaceAll("]","").replaceAll("\"","").split("["); const tokens = voiceId.replaceAll("]", "").replaceAll("\"", "").split("[");
const model_id = tokens[0] const model_id = tokens[0]
console.debug(DEBUG_PREFIX,"Preparing TTS request for",tokens) console.debug(DEBUG_PREFIX, "Preparing TTS request for", tokens)
// First option // First option
if (tokens.length > 1) { if (tokens.length > 1) {
@ -657,7 +656,7 @@ class CoquiTtsProvider {
// Dirty hack to say not implemented // Dirty hack to say not implemented
async fetchTtsVoiceIds() { async fetchTtsVoiceIds() {
return [{name:"Voice samples not implemented for coqui TTS yet, search for the model samples online", voice_id:"",lang:"",}] return [{ name: "Voice samples not implemented for coqui TTS yet, search for the model samples online", voice_id: "", lang: "", }]
} }
// Do nothing // Do nothing
@ -681,7 +680,7 @@ async function moduleWorker() {
return return
// Initialized local model once // Initialized local model once
if (!coquiLocalModelsReceived){ if (!coquiLocalModelsReceived) {
let result = await CoquiTtsProvider.getLocalModelList(); let result = await CoquiTtsProvider.getLocalModelList();
result = await result.json(); result = await result.json();
@ -695,8 +694,8 @@ async function moduleWorker() {
.append('<option value="none">Select model</option>') .append('<option value="none">Select model</option>')
.val('none'); .val('none');
for(const model_dataset of coquiLocalModels) for (const model_dataset of coquiLocalModels)
$("#coqui_local_model_name").append(new Option(model_dataset,model_dataset)); $("#coqui_local_model_name").append(new Option(model_dataset, model_dataset));
coquiLocalModelsReceived = true; coquiLocalModelsReceived = true;
} }