Update src/tts.ts
Browse files- src/tts.ts +15 -5
src/tts.ts
CHANGED
|
@@ -8,11 +8,21 @@ let pipelinePromise: Promise<TextToAudioPipeline> | null = null;
|
|
| 8 |
let embeddingsPromise: Promise<Record<string, Float32Array>> | null = null;
|
| 9 |
|
| 10 |
export async function loadPipeline(progressCallback: (info: any) => void) {
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
export async function loadEmbeddings() {
|
|
|
|
| 8 |
let embeddingsPromise: Promise<Record<string, Float32Array>> | null = null;
|
| 9 |
|
| 10 |
export async function loadPipeline(progressCallback: (info: any) => void) {
|
| 11 |
+
return pipelinePromise ??= (async () => {
|
| 12 |
+
const tts = (await pipeline("text-to-speech", MODEL_ID, {
|
| 13 |
+
device: "webgpu",
|
| 14 |
+
progress_callback: progressCallback,
|
| 15 |
+
})) as TextToAudioPipeline;
|
| 16 |
+
|
| 17 |
+
// Warm up the model to compile shaders
|
| 18 |
+
await tts("Hello", {
|
| 19 |
+
speaker_embeddings: new Float32Array(1 * 101 * 128), // Dummy embedding
|
| 20 |
+
num_inference_steps: 1,
|
| 21 |
+
speed: 1.0,
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
return tts;
|
| 25 |
+
})();
|
| 26 |
}
|
| 27 |
|
| 28 |
export async function loadEmbeddings() {
|