Public
Edited
Apr 7
Insert cell
Insert cell
viewof text = Inputs.text({submit: true, value: "This is a text to speech demonstration"})
Insert cell
{
const out = await synthesizer(text, {
speaker_embeddings
});
const wav = new wavefile.WaveFile();
wav.fromScratch(1, out.sampling_rate, "32f", out.audio);

// Example usage
const buffer = await wav.toBuffer();
const blob = createBlobFromBuffer(buffer);

// To use the blob (e.g., for downloading)
const url = URL.createObjectURL(blob);

const audio = new Audio();
audio.src = url;
audio.controls = true;

yield audio;
audio.play();

invalidation.then(() => URL.revokeObjectURL(url));
}
Insert cell
synthesizer = await transformersJS.pipeline(
"text-to-speech",
"Xenova/speecht5_tts",
{
quantized: false,
// device: "webgpu"
}
)
Insert cell
speaker_embeddings = "https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin"
Insert cell
function createBlobFromBuffer(buffer, mimeType = "application/octet-stream") {
// Convert Buffer to Blob
const blob = new Blob([buffer], { type: mimeType });
return blob;
}
Insert cell
wavefile = require("wavefile")
Insert cell
transformersJS = import('https://unpkg.com/@huggingface/transformers@3.4.2/dist/transformers.min.js?module')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more