Update index.html
Browse files- index.html +10 -6
index.html
CHANGED
|
@@ -18,18 +18,22 @@ import scipy.io.wavfile as wavfile
|
|
| 18 |
|
| 19 |
speaker_embeddings = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin';
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
|
|
|
| 28 |
out = await synthesizer(text, { "speaker_embeddings": speaker_embeddings });
|
| 29 |
audio_data_memory_view = out["audio"]
|
| 30 |
sampling_rate = out["sampling_rate"]
|
| 31 |
|
| 32 |
audio_data = np.frombuffer(audio_data_memory_view, dtype=np.float32)
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
wavfile.write('output.wav', sampling_rate, audio_data)
|
| 35 |
return "output.wav"
|
|
|
|
| 18 |
|
| 19 |
speaker_embeddings = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin';
|
| 20 |
|
| 21 |
+
synthesizer = await pipeline(
|
| 22 |
+
'text-to-speech',
|
| 23 |
+
'Xenova/speecht5_tts',
|
| 24 |
+
{ "quantized": False }
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
|
| 28 |
+
async def synthesize(text):
|
| 29 |
out = await synthesizer(text, { "speaker_embeddings": speaker_embeddings });
|
| 30 |
audio_data_memory_view = out["audio"]
|
| 31 |
sampling_rate = out["sampling_rate"]
|
| 32 |
|
| 33 |
audio_data = np.frombuffer(audio_data_memory_view, dtype=np.float32)
|
| 34 |
+
audio_data_16bit = (audio_data * 32767).astype(np.int16)
|
| 35 |
+
|
| 36 |
+
return sampling_rate, audio_data_16bit
|
| 37 |
|
| 38 |
wavfile.write('output.wav', sampling_rate, audio_data)
|
| 39 |
return "output.wav"
|