sanchit-gandhi
commited on
Commit
·
2be1dd4
1
Parent(s):
ce071f3
Update Transformers code example
Browse filescc
@reach-vb
README.md
CHANGED
@@ -104,16 +104,17 @@ audio_values = model.generate(**inputs, max_new_tokens=256)
|
|
104 |
from IPython.display import Audio
|
105 |
|
106 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
107 |
-
Audio(audio_values[0].numpy(), rate=sampling_rate)
|
108 |
```
|
109 |
|
110 |
-
Or save them as a `.wav` file using a third-party library, e.g. `
|
111 |
|
112 |
```python
|
113 |
-
import
|
114 |
|
115 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
116 |
-
|
|
|
117 |
```
|
118 |
|
119 |
For more details on using the MusicGen model for inference using the 🤗 Transformers library, refer to the [MusicGen docs](https://huggingface.co/docs/transformers/model_doc/musicgen).
|
|
|
104 |
from IPython.display import Audio
|
105 |
|
106 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
107 |
+
Audio(audio_values[0].cpu().numpy(), rate=sampling_rate)
|
108 |
```
|
109 |
|
110 |
+
Or save them as a `.wav` file using a third-party library, e.g. `soundfile`:
|
111 |
|
112 |
```python
|
113 |
+
import soundfile as sf
|
114 |
|
115 |
sampling_rate = model.config.audio_encoder.sampling_rate
|
116 |
+
audio_values = audio_values.cpu().numpy()
|
117 |
+
sf.write("musicgen_out.wav", audio_values[0].T, sampling_rate)
|
118 |
```
|
119 |
|
120 |
For more details on using the MusicGen model for inference using the 🤗 Transformers library, refer to the [MusicGen docs](https://huggingface.co/docs/transformers/model_doc/musicgen).
|