Merge pull request #954 from Tony-sama/staging

Coqui TTS add remove character voice map button + RVC upload features
This commit is contained in:
Cohee 2023-08-17 12:03:03 +03:00 committed by GitHub
commit c4700b38fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 16 deletions

View File

@ -14,6 +14,7 @@ const UPDATE_INTERVAL = 1000
let charactersList = [] // Updated with module worker
let rvcModelsList = [] // Initialized only once
let rvcModelsReceived = false;
function updateVoiceMapText(){
let voiceMapText = ""
@ -173,6 +174,30 @@ async function onDeleteClick() {
saveSettingsDebounced();
}
async function onClickUpload() {
const url = new URL(getApiUrl());
const inputFiles = $("#rvc_model_upload_file").get(0).files;
let formData = new FormData();
for(const file of inputFiles)
formData.append(file.name, file);
console.debug(DEBUG_PREFIX,"Sending files:",formData);
url.pathname = '/api/voice-conversion/rvc/upload-models';
const apiResult = await doExtrasFetch(url, {
method: 'POST',
body: formData
});
if (!apiResult.ok) {
toastr.error(apiResult.statusText, DEBUG_PREFIX+' Check extras console for errors log');
throw new Error(`HTTP ${apiResult.status}: ${await apiResult.text()}`);
}
alert('The file has been uploaded successfully.');
}
$(document).ready(function () {
function addExtensionControls() {
const settingsHtml = `
@ -201,6 +226,15 @@ $(document).ready(function () {
<select id="rvc_model_select">
<!-- Populated by JS -->
</select>
<div>
<label for="rvc_model_upload_file">Select models to upload (zip files)</label>
<input
type="file"
id="rvc_model_upload_file"
accept=".zip,.rar,.7zip,.7z" multiple />
<button id="rvc_model_upload_button"> Upload </button>
<button id="rvc_model_refresh_button"> Refresh Voices </button>
</div>
<span>Select Pitch Extraction</span> </br>
<select id="rvc_pitch_extraction">
<option value="dio">dio</option>
@ -250,6 +284,10 @@ $(document).ready(function () {
$("#rvc_apply").on("click", onApplyClick);
$("#rvc_delete").on("click", onDeleteClick);
$("#rvc_model_upload_file").show();
$("#rvc_model_upload_button").on("click", onClickUpload);
$("#rvc_model_refresh_button").on("click", refreshVoiceList);
}
addExtensionControls(); // No init dependencies
loadSettings(); // Depends on Extension Controls
@ -337,11 +375,8 @@ async function rvcVoiceConversion(response, character) {
// Module Worker //
//#############################//
async function moduleWorker() {
updateCharactersList();
if (modules.includes('rvc') && rvcModelsList.length == 0) {
let result = await get_models_list();
async function refreshVoiceList() {
let result = await get_models_list();
result = await result.json();
rvcModelsList = result["models_list"]
@ -356,7 +391,15 @@ async function moduleWorker() {
$("#rvc_model_select").append(new Option(modelName,modelName));
}
rvcModelsReceived = true
console.debug(DEBUG_PREFIX,"Updated model list to:", rvcModelsList);
}
async function moduleWorker() {
updateCharactersList();
if (modules.includes('rvc') && !rvcModelsReceived) {
refreshVoiceList();
}
}

View File

@ -9,13 +9,14 @@ import { doExtrasFetch, extension_settings, getApiUrl, getContext, modules, Modu
export { CoquiTtsProvider }
const DEBUG_PREFIX = "<Coqui TTS module> "
const UPDATE_INTERVAL = 1000
const DEBUG_PREFIX = "<Coqui TTS module> ";
const UPDATE_INTERVAL = 1000;
let inApiCall = false
let charactersList = [] // Updated with module worker
let coquiApiModels = {} // Initialized only once
let coquiLocalModels = [] // Initialized only once
let inApiCall = false;
let charactersList = []; // Updated with module worker
let coquiApiModels = {}; // Initialized only once
let coquiLocalModels = []; // Initialized only once
let coquiLocalModelsReceived = false;
/*
coquiApiModels format [language][dataset][name]:coqui-api-model-id, example:
{
@ -98,6 +99,9 @@ class CoquiTtsProvider {
<select id="coqui_character_select">
<!-- Populated by JS -->
</select>
<input id="coqui_remove_char_mapping" class="menu_button" type="button" value="Remove from Voice Map" />
<label for="coqui_model_origin">Models:</label>
<select id="coqui_model_origin">gpu_mode
<option value="none">Select Origin</option>
@ -163,9 +167,12 @@ class CoquiTtsProvider {
$("#coqui_api_model_install_status").hide();
$("#coqui_api_model_install_button").hide();
$("#coqui_model_origin").on("change",this.onModelOriginChange);
$("#coqui_api_language").on("change",this.onModelLanguageChange);
$("#coqui_api_model_name").on("change",this.onModelNameChange);
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_remove_char_mapping").on("click", function(){that.onRemoveClick()});
// Load characters list
$('#coqui_character_select')
@ -321,11 +328,23 @@ class CoquiTtsProvider {
return output;
}
async onRemoveClick() {
const character = $("#coqui_character_select").val();
if (character === "none") {
toastr.error(`Character not selected, please select one.`, DEBUG_PREFIX+" voice mapping character", { timeOut: 10000, extendedTimeOut: 20000, preventDuplicates: true });
return;
}
// Todo erase from voicemap
delete(this.settings.voiceMapDict[character]);
this.updateVoiceMap(); // TODO
}
async onModelOriginChange() {
throwIfModuleMissing()
resetModelSettings();
const model_origin = $('#coqui_model_origin').val();
console.debug(model_origin);
if (model_origin == "none") {
$("#coqui_local_model_div").hide();
@ -662,7 +681,7 @@ async function moduleWorker() {
return
// Initialized local model once
if (coquiLocalModels.length == 0){
if (!coquiLocalModelsReceived){
let result = await CoquiTtsProvider.getLocalModelList();
result = await result.json();
@ -678,6 +697,8 @@ async function moduleWorker() {
for(const model_dataset of coquiLocalModels)
$("#coqui_local_model_name").append(new Option(model_dataset,model_dataset));
coquiLocalModelsReceived = true;
}
}