forked from akai/readest
Preloading audio for Edge TTS and other fixes (#138)
* Blacklist some low-quality web tts voices * Dropdown layout tweaks * Handle no audio data received in Edge TTS * Preloading audio for Edge TTS
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
export class LRUCache<K, V> {
|
||||
private capacity: number;
|
||||
private map: Map<K, V>;
|
||||
|
||||
constructor(capacity: number) {
|
||||
if (capacity <= 0) {
|
||||
throw new Error('LRUCache capacity must be greater than 0');
|
||||
}
|
||||
this.capacity = capacity;
|
||||
this.map = new Map();
|
||||
}
|
||||
|
||||
get(key: K): V | undefined {
|
||||
if (!this.map.has(key)) {
|
||||
return undefined;
|
||||
}
|
||||
const value = this.map.get(key)!;
|
||||
this.map.delete(key);
|
||||
this.map.set(key, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
set(key: K, value: V): void {
|
||||
if (this.map.has(key)) {
|
||||
this.map.delete(key);
|
||||
} else if (this.map.size === this.capacity) {
|
||||
const oldestKey = this.map.keys().next().value;
|
||||
if (oldestKey) {
|
||||
this.map.delete(oldestKey);
|
||||
}
|
||||
}
|
||||
this.map.set(key, value);
|
||||
}
|
||||
|
||||
has(key: K): boolean {
|
||||
return this.map.has(key);
|
||||
}
|
||||
|
||||
delete(key: K): boolean {
|
||||
return this.map.delete(key);
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
this.map.clear();
|
||||
}
|
||||
|
||||
size(): number {
|
||||
return this.map.size;
|
||||
}
|
||||
|
||||
entries(): Array<[K, V]> {
|
||||
return Array.from(this.map).reverse();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,12 @@ export const parseSSMLMarks = (ssml: string) => {
|
||||
markTagEndIndex,
|
||||
nextMarkIndex !== -1 ? nextMarkIndex : ssml.length,
|
||||
);
|
||||
const cleanedChunk = nextChunk.replace(/<[^>]+>/g, '').trimStart();
|
||||
const cleanedChunk = nextChunk
|
||||
.replace(/<[^>]+>/g, '')
|
||||
.replace(/\r\n/g, ' ')
|
||||
.replace(/\r/g, ' ')
|
||||
.replace(/\n/g, ' ')
|
||||
.trimStart();
|
||||
plainText += cleanedChunk;
|
||||
|
||||
const offset = plainText.length - cleanedChunk.length;
|
||||
|
||||
Reference in New Issue
Block a user