Add/update the quantized ONNX model files and README.md for Transformers.js v3
#1
by
whitphx
HF Staff
- opened
README.md
CHANGED
|
@@ -5,17 +5,16 @@ library_name: transformers.js
|
|
| 5 |
|
| 6 |
https://huggingface.co/microsoft/speecht5_hifigan with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
| 8 |
-
|
| 9 |
## Usage (Transformers.js)
|
| 10 |
|
| 11 |
-
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@
|
| 12 |
```bash
|
| 13 |
-
npm i @
|
| 14 |
```
|
| 15 |
|
| 16 |
**Example:** Generate speech from text.
|
| 17 |
```js
|
| 18 |
-
import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@
|
| 19 |
|
| 20 |
// Load the tokenizer and processor
|
| 21 |
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/speecht5_tts');
|
|
@@ -23,8 +22,8 @@ const processor = await AutoProcessor.from_pretrained('Xenova/speecht5_tts');
|
|
| 23 |
|
| 24 |
// Load the models
|
| 25 |
// NOTE: We use the unquantized versions as they are more accurate
|
| 26 |
-
const model = await SpeechT5ForTextToSpeech.from_pretrained('Xenova/speecht5_tts', {
|
| 27 |
-
const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', {
|
| 28 |
|
| 29 |
// Load speaker embeddings from URL
|
| 30 |
const speaker_embeddings_data = new Float32Array(
|
|
@@ -41,7 +40,7 @@ const { input_ids } = tokenizer('Hello, my dog is cute');
|
|
| 41 |
|
| 42 |
// Generate waveform
|
| 43 |
const { waveform } = await model.generate_speech(input_ids, speaker_embeddings, { vocoder });
|
| 44 |
-
console.log(waveform)
|
| 45 |
// Tensor {
|
| 46 |
// dims: [ 26112 ],
|
| 47 |
// type: 'float32',
|
|
|
|
| 5 |
|
| 6 |
https://huggingface.co/microsoft/speecht5_hifigan with ONNX weights to be compatible with Transformers.js.
|
| 7 |
|
|
|
|
| 8 |
## Usage (Transformers.js)
|
| 9 |
|
| 10 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
| 11 |
```bash
|
| 12 |
+
npm i @huggingface/transformers
|
| 13 |
```
|
| 14 |
|
| 15 |
**Example:** Generate speech from text.
|
| 16 |
```js
|
| 17 |
+
import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@huggingface/transformers';
|
| 18 |
|
| 19 |
// Load the tokenizer and processor
|
| 20 |
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/speecht5_tts');
|
|
|
|
| 22 |
|
| 23 |
// Load the models
|
| 24 |
// NOTE: We use the unquantized versions as they are more accurate
|
| 25 |
+
const model = await SpeechT5ForTextToSpeech.from_pretrained('Xenova/speecht5_tts', { dtype: "fp32" }); // Options: "fp32", "fp16", "q8", "q4"
|
| 26 |
+
const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { dtype: "fp32" }); // Options: "fp32", "fp16", "q8", "q4"
|
| 27 |
|
| 28 |
// Load speaker embeddings from URL
|
| 29 |
const speaker_embeddings_data = new Float32Array(
|
|
|
|
| 40 |
|
| 41 |
// Generate waveform
|
| 42 |
const { waveform } = await model.generate_speech(input_ids, speaker_embeddings, { vocoder });
|
| 43 |
+
console.log(waveform);
|
| 44 |
// Tensor {
|
| 45 |
// dims: [ 26112 ],
|
| 46 |
// type: 'float32',
|