mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-03-02 10:57:45 +01:00
Chunkify NovelAI TTS
This commit is contained in:
parent
58462d96d2
commit
b315778e32
@ -463,13 +463,25 @@ function saveLastValues() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function tts(text, voiceId, char) {
|
async function tts(text, voiceId, char) {
|
||||||
|
async function processResponse(response) {
|
||||||
|
// RVC injection
|
||||||
|
if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function')
|
||||||
|
response = await window['rvcVoiceConversion'](response, char, text);
|
||||||
|
|
||||||
|
await addAudioJob(response);
|
||||||
|
}
|
||||||
|
|
||||||
let response = await ttsProvider.generateTts(text, voiceId);
|
let response = await ttsProvider.generateTts(text, voiceId);
|
||||||
|
|
||||||
// RVC injection
|
// If async generator, process every chunk as it comes in
|
||||||
if (extension_settings.rvc.enabled && typeof window['rvcVoiceConversion'] === 'function')
|
if (typeof response[Symbol.asyncIterator] === 'function') {
|
||||||
response = await window['rvcVoiceConversion'](response, char, text);
|
for await (const chunk of response) {
|
||||||
|
await processResponse(chunk);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await processResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
addAudioJob(response);
|
|
||||||
completeTtsJob();
|
completeTtsJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { getRequestHeaders, callPopup } from '../../../script.js';
|
import { getRequestHeaders, callPopup } from '../../../script.js';
|
||||||
|
import { splitRecursive } from '../../utils.js';
|
||||||
import { getPreviewString, saveTtsProviderSettings } from './index.js';
|
import { getPreviewString, saveTtsProviderSettings } from './index.js';
|
||||||
import { initVoiceMap } from './index.js';
|
import { initVoiceMap } from './index.js';
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class NovelTtsProvider {
|
|||||||
|
|
||||||
|
|
||||||
// Add a new Novel custom voice to provider
|
// Add a new Novel custom voice to provider
|
||||||
async addCustomVoice(){
|
async addCustomVoice() {
|
||||||
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input');
|
const voiceName = await callPopup('<h3>Custom Voice name:</h3>', 'input');
|
||||||
this.settings.customVoices.push(voiceName);
|
this.settings.customVoices.push(voiceName);
|
||||||
this.populateCustomVoices();
|
this.populateCustomVoices();
|
||||||
@ -74,7 +75,7 @@ class NovelTtsProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the UI dropdown list of voices in provider
|
// Create the UI dropdown list of voices in provider
|
||||||
populateCustomVoices(){
|
populateCustomVoices() {
|
||||||
let voiceSelect = $('#tts-novel-custom-voices-select');
|
let voiceSelect = $('#tts-novel-custom-voices-select');
|
||||||
voiceSelect.empty();
|
voiceSelect.empty();
|
||||||
this.settings.customVoices.forEach(voice => {
|
this.settings.customVoices.forEach(voice => {
|
||||||
@ -88,7 +89,7 @@ class NovelTtsProvider {
|
|||||||
console.info('Using default TTS Provider settings');
|
console.info('Using default TTS Provider settings');
|
||||||
}
|
}
|
||||||
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()));
|
$('#tts-novel-custom-voices-add').on('click', () => (this.addCustomVoice()));
|
||||||
$('#tts-novel-custom-voices-delete').on('click',() => (this.deleteCustomVoice()));
|
$('#tts-novel-custom-voices-delete').on('click', () => (this.deleteCustomVoice()));
|
||||||
|
|
||||||
// Only accept keys defined in defaultSettings
|
// Only accept keys defined in defaultSettings
|
||||||
this.settings = this.defaultSettings;
|
this.settings = this.defaultSettings;
|
||||||
@ -108,7 +109,7 @@ class NovelTtsProvider {
|
|||||||
|
|
||||||
// Perform a simple readiness check by trying to fetch voiceIds
|
// Perform a simple readiness check by trying to fetch voiceIds
|
||||||
// Doesnt really do much for Novel, not seeing a good way to test this at the moment.
|
// Doesnt really do much for Novel, not seeing a good way to test this at the moment.
|
||||||
async checkReady(){
|
async checkReady() {
|
||||||
await this.fetchTtsVoiceObjects();
|
await this.fetchTtsVoiceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,22 +180,26 @@ class NovelTtsProvider {
|
|||||||
this.audioElement.play();
|
this.audioElement.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchTtsGeneration(inputText, voiceId) {
|
async* fetchTtsGeneration(inputText, voiceId) {
|
||||||
|
const MAX_LENGTH = 1000;
|
||||||
console.info(`Generating new TTS for voice_id ${voiceId}`);
|
console.info(`Generating new TTS for voice_id ${voiceId}`);
|
||||||
const response = await fetch('/api/novelai/generate-voice',
|
const chunks = splitRecursive(inputText, MAX_LENGTH);
|
||||||
{
|
for (const chunk of chunks) {
|
||||||
method: 'POST',
|
const response = await fetch('/api/novelai/generate-voice',
|
||||||
headers: getRequestHeaders(),
|
{
|
||||||
body: JSON.stringify({
|
method: 'POST',
|
||||||
'text': inputText,
|
headers: getRequestHeaders(),
|
||||||
'voice': voiceId,
|
body: JSON.stringify({
|
||||||
}),
|
'text': chunk,
|
||||||
},
|
'voice': voiceId,
|
||||||
);
|
}),
|
||||||
if (!response.ok) {
|
},
|
||||||
toastr.error(response.statusText, 'TTS Generation Failed');
|
);
|
||||||
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
if (!response.ok) {
|
||||||
|
toastr.error(response.statusText, 'TTS Generation Failed');
|
||||||
|
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
||||||
|
}
|
||||||
|
yield response;
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,7 +342,9 @@ router.post('/generate-voice', jsonParser, async (request, response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
return response.sendStatus(result.status);
|
const errorText = await result.text();
|
||||||
|
console.log('NovelAI returned an error.', result.statusText, errorText);
|
||||||
|
return response.sendStatus(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
const chunks = await readAllChunks(result.body);
|
const chunks = await readAllChunks(result.body);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user