Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import VitsModel, AutoTokenizer
|
| 3 |
+
import numpy as np
|
| 4 |
+
import scipy.io.wavfile as wavfile
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
def yes(texte):
|
| 8 |
+
model = VitsModel.from_pretrained("facebook/mms-tts-eng")
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained("facebook/mms-tts-eng")
|
| 10 |
+
|
| 11 |
+
text = texte
|
| 12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 13 |
+
|
| 14 |
+
with torch.no_grad():
|
| 15 |
+
output = model(**inputs).waveform
|
| 16 |
+
|
| 17 |
+
# Normaliser les données audio dans la plage [-1, 1]
|
| 18 |
+
output_normalized = output / torch.max(torch.abs(output))
|
| 19 |
+
|
| 20 |
+
# Convertir en tableau numpy avec le bon type
|
| 21 |
+
audio_data = output_normalized.squeeze().cpu().numpy()
|
| 22 |
+
|
| 23 |
+
# Mettre à l'échelle dans la plage de valeurs acceptées par WAV
|
| 24 |
+
audio_data_scaled = np.int16(audio_data * 32767)
|
| 25 |
+
|
| 26 |
+
# Enregistrer les données audio dans un fichier WAV
|
| 27 |
+
wavfile.write("techno.wav", rate=model.config.sampling_rate, data=audio_data_scaled)
|
| 28 |
+
|
| 29 |
+
with open("techno.wav",'rb') as audio:
|
| 30 |
+
audio_data = audio.read()
|
| 31 |
+
|
| 32 |
+
return audio_data
|
| 33 |
+
|
| 34 |
+
text = gr.Interface(fn=yes, inputs='text', outputs='audio')
|
| 35 |
+
text.launch(debug=True)
|