Spaces:
Sleeping
Sleeping
jwphantom
commited on
Commit
•
dfc6a42
1
Parent(s):
ebf94f7
fisrt commit
Browse files- .gitignore +4 -0
- app.py +47 -0
- requirements.txt +67 -0
.gitignore
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.venv/
|
2 |
+
__pycache__/
|
3 |
+
.env
|
4 |
+
.DS_Store
|
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
2 |
+
from datasets import load_dataset
|
3 |
+
import torch
|
4 |
+
import soundfile as sf
|
5 |
+
import numpy as np
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
# Charger les modèles et les embeddings du locuteur une seule fois pour éviter de les recharger à chaque appel
|
9 |
+
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
10 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
11 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
12 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
13 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
14 |
+
|
15 |
+
|
16 |
+
def text_to_speech(text):
|
17 |
+
# Prétraiter le texte
|
18 |
+
inputs = processor(text=text, return_tensors="pt")
|
19 |
+
|
20 |
+
# Générer la parole
|
21 |
+
speech = model.generate_speech(
|
22 |
+
inputs["input_ids"], speaker_embeddings, vocoder=vocoder
|
23 |
+
)
|
24 |
+
|
25 |
+
# Enregistrer le fichier audio
|
26 |
+
output_filename = "speech.wav"
|
27 |
+
sf.write(output_filename, speech.numpy(), samplerate=16000)
|
28 |
+
|
29 |
+
# Lire le fichier audio
|
30 |
+
with open(output_filename, "rb") as file:
|
31 |
+
audio_bytes = file.read()
|
32 |
+
|
33 |
+
return audio_bytes
|
34 |
+
|
35 |
+
|
36 |
+
# Créer l'interface Gradio
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=text_to_speech,
|
39 |
+
inputs="text",
|
40 |
+
outputs=gr.Audio(label="Processed Audio"),
|
41 |
+
title="Application du type Text to speech",
|
42 |
+
description="Entrez un texte en anglais et l'application va la traduire",
|
43 |
+
)
|
44 |
+
|
45 |
+
# Lancer l'interface Gradio
|
46 |
+
if __name__ == "__main__":
|
47 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
altair==5.2.0
|
3 |
+
annotated-types==0.6.0
|
4 |
+
anyio==4.3.0
|
5 |
+
attrs==23.2.0
|
6 |
+
certifi==2024.2.2
|
7 |
+
charset-normalizer==3.3.2
|
8 |
+
click==8.1.7
|
9 |
+
colorama==0.4.6
|
10 |
+
contourpy==1.2.0
|
11 |
+
cycler==0.12.1
|
12 |
+
fastapi==0.110.0
|
13 |
+
ffmpy==0.3.2
|
14 |
+
filelock==3.13.1
|
15 |
+
fonttools==4.49.0
|
16 |
+
fsspec==2024.2.0
|
17 |
+
gradio==4.19.2
|
18 |
+
gradio_client==0.10.1
|
19 |
+
h11==0.14.0
|
20 |
+
httpcore==1.0.4
|
21 |
+
httpx==0.27.0
|
22 |
+
huggingface-hub==0.21.3
|
23 |
+
idna==3.6
|
24 |
+
importlib_resources==6.1.2
|
25 |
+
Jinja2==3.1.3
|
26 |
+
jsonschema==4.21.1
|
27 |
+
jsonschema-specifications==2023.12.1
|
28 |
+
kiwisolver==1.4.5
|
29 |
+
markdown-it-py==3.0.0
|
30 |
+
MarkupSafe==2.1.5
|
31 |
+
matplotlib==3.8.3
|
32 |
+
mdurl==0.1.2
|
33 |
+
numpy==1.26.4
|
34 |
+
orjson==3.9.15
|
35 |
+
packaging==23.2
|
36 |
+
pandas==2.2.1
|
37 |
+
pillow==10.2.0
|
38 |
+
pydantic==2.6.3
|
39 |
+
pydantic_core==2.16.3
|
40 |
+
pydub==0.25.1
|
41 |
+
Pygments==2.17.2
|
42 |
+
pyparsing==3.1.1
|
43 |
+
python-dateutil==2.9.0.post0
|
44 |
+
python-multipart==0.0.9
|
45 |
+
pytz==2024.1
|
46 |
+
PyYAML==6.0.1
|
47 |
+
referencing==0.33.0
|
48 |
+
requests==2.31.0
|
49 |
+
rich==13.7.1
|
50 |
+
rpds-py==0.18.0
|
51 |
+
ruff==0.3.0
|
52 |
+
semantic-version==2.10.0
|
53 |
+
shellingham==1.5.4
|
54 |
+
six==1.16.0
|
55 |
+
sniffio==1.3.1
|
56 |
+
starlette==0.36.3
|
57 |
+
tomlkit==0.12.0
|
58 |
+
toolz==0.12.1
|
59 |
+
tqdm==4.66.2
|
60 |
+
typer==0.9.0
|
61 |
+
typing_extensions==4.10.0
|
62 |
+
tzdata==2024.1
|
63 |
+
urllib3==2.2.1
|
64 |
+
uvicorn==0.27.1
|
65 |
+
websockets==11.0.3
|
66 |
+
transformers==4.38.2
|
67 |
+
torch==2.2.1
|