Repository: huggingface/transformers.js (language: javascript)

Issue:
Add support for new Model, SpeechT5HifiGan
### Model description

I realize it needs audio-to-audio support from optimum to export to onnx, would be nice to have it added here when available

### Prerequisites

- [X] The model is supported in Transformers (i.e., listed [here](https://huggingface.co/docs/transformers/index#supported-models-and-frameworks))
- [ ] The model can be exported to ONNX with Optimum (i.e., listed [here](https://huggingface.co/docs/optimum/main/en/exporters/onnx/overview))

### Additional information

_No response_

### Your contribution

Once available in Optimum I would do what I could to integrate support for it


Discussion / hints:
Hi there 👋  Good news, `SpeechT5HifiGan` is already supported 🥳 Usually, it is used as part of the text-to-speech pipeline (see [docs](https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.TextToAudioPipeline)):
```js
import { pipeline } from '@xenova/transformers';
let speaker_embeddings = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/speaker_embeddings.bin';
let synthesizer = await pipeline('text-to-speech', 'Xenova/speecht5_tts', { quantized: false });
let out = await synthesizer('Hello, my dog is cute', { speaker_embeddings });
// {
//   audio: Float32Array(26112) [-0.00005657337896991521, 0.00020583874720614403, ...],
//   sampling_rate: 16000
// }
```

But if you'd like to break the pipeline apart, you can use the individual parts like this:
```js
import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@xenova/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', { quantized: false });
const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { quantized: false });

// 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 to file (Node.js):
```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());
```

---

I will update the model docs for these models too, to include this example code.
Oh hell yeah!

Apologies, I went all through your huggingface Models looking for it- I have no idea how I missed it

Fix patch:
diff --git a/src/models.js b/src/models.js
index 1c55d8877..48fab2f08 100644
--- a/src/models.js
+++ b/src/models.js
@@ -3859,6 +3859,43 @@ export class SpeechT5Model extends SpeechT5PreTrainedModel { };
 
 /**
  * SpeechT5 Model with a speech encoder and a text decoder.
+ * 
+ * **Example:** Generate speech from text with `SpeechT5ForSpeechToText`.
+ * ```javascript
+ * import { AutoTokenizer, AutoProcessor, SpeechT5ForTextToSpeech, SpeechT5HifiGan, Tensor } from '@xenova/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', { quantized: false });
+ * const vocoder = await SpeechT5HifiGan.from_pretrained('Xenova/speecht5_hifigan', { quantized: false });
+ * 
+ * // 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, ... ],
+ * // }
+ * ```
  */
 export class SpeechT5ForSpeechToText extends SpeechT5PreTrainedModel { }
 
@@ -3984,6 +4021,8 @@ export class SpeechT5ForTextToSpeech extends SpeechT5PreTrainedModel {
 
 /**
  * HiFi-GAN vocoder.
+ * 
+ * See [SpeechT5ForSpeechToText](./models#module_models.SpeechT5ForSpeechToText) for example usage.
  */
 export class SpeechT5HifiGan extends PreTrainedModel {
     main_input_name = 'spectrogram';


Test patch: