Downloads · 30 days
1K
3% of all-time downloads
Xenova/speecht5_hifigan
speecht5_hifigan is a machine learning model from Xenova. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.js.
https://huggingface.co/microsoft/speecht5hifigan with ONNX weights to be compatible with Transformers.js.
Downloads · 30 days
1K
3% of all-time downloads
All-time downloads
29.9K
Public
Repo size
73.7 MB
Likes
1
Public
Click a slice to open those files.
.onnx73.7 MB · 100%
From the Hugging Face model README
https://huggingface.co/microsoft/speecht5_hifigan with ONNX weights to be compatible with Transformers.js.
If you haven't already, you can install the Transformers.js JavaScript library from NPM using:
npm i @huggingface/transformers
Example: Generate speech from text.
import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@huggingface/transformers';
// Load the tokenizer and processor
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/speecht5_tts');
const processor = await AutoProcessor.from_pretrained('Xenova/speecht5_tts');
// Load the models
// NOTE: We use the unquantized versions as they are more accurate
const model = await SpeechT5ForTextToSpeech.from_pretrained('Xenova/speecht5_tts', { dtype: "fp32" }); // Options: "fp32", "fp16", "q8", "q4"
const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { dtype: "fp32" }); // Options: "fp32", "fp16", "q8", "q4"
// Load speaker embeddings from URL
const speaker_embeddings_data = new Float32Array(
await (await fetch('https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin')).arrayBuffer()
);
const speaker_embeddings = new Tensor(
'float32',
speaker_embeddings_data,
[1, speaker_embeddings_data.length]
)
// Run tokenization
const { input_ids } = tokenizer('Hello, my dog is cute');
// Generate waveform
const { waveform } = await model.generate_speech(input_ids, speaker_embeddings, { vocoder });
console.log(waveform);
// Tensor {
// dims: [ 26112 ],
// type: 'float32',
// size: 26112,
// data: Float32Array(26112) [ -0.00043630177970044315, -0.00018082228780258447, ... ],
// }
Optionally, save the audio to a wav file (Node.js):
// Write to file (Node.js)
import wavefile from 'wavefile';
import fs from 'fs';
const wav = new wavefile.WaveFile();
wav.fromScratch(1, processor.feature_extractor.config.sampling_rate, '32f', waveform.data);
fs.writeFileSync('out.wav', wav.toBuffer());
<audio controls src="https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/on1ij9Y269ne9zlYN9mdb.wav"></audio>
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using 🤗 Optimum and structuring your repo like this one (with ONNX weights located in a subfolder named onnx).