mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
* feature: 'kokoro-js' supports TTS #3412 * Linting, add credits for kokoro library * Fix voice preview * Fix display languages on previews * Fix settings restoration. Debounce model init on settings change * Fix engine sorting * Move TTS processing to a web worker. Remove unused gain setting * Speaking rate fix * Update status when recreating a worker * Pass voices list from TTS engine * Call dispose function on provider change * Extend worker init timeout to 10 minutes --------- Co-authored-by: ryan <1014670860@qq.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
@ -436,6 +436,33 @@ export function debounce(func, timeout = debounce_timeout.standard) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.
|
||||
* @param {Function} func The function to debounce.
|
||||
* @param {Number} [timeout=300] The timeout in milliseconds.
|
||||
* @returns {Function} The debounced function.
|
||||
*/
|
||||
export function debounceAsync(func, timeout = debounce_timeout.standard) {
|
||||
let timer;
|
||||
/**@type {Promise}*/
|
||||
let debouncePromise;
|
||||
/**@type {Function}*/
|
||||
let debounceResolver;
|
||||
return (...args) => {
|
||||
clearTimeout(timer);
|
||||
if (!debouncePromise) {
|
||||
debouncePromise = new Promise(resolve => {
|
||||
debounceResolver = resolve;
|
||||
});
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
debounceResolver(func.apply(this, args));
|
||||
debouncePromise = null;
|
||||
}, timeout);
|
||||
return debouncePromise;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels a scheduled debounced function.
|
||||
* Does nothing if the function is not debounced or not scheduled.
|
||||
|
Reference in New Issue
Block a user