Sandiago21 commited on
Commit
2f9b252
1 Parent(s): 5267427

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +3 -9
  2. app.py +48 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Text To Speech French
3
- emoji: 👁
4
- colorFrom: indigo
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 3.36.1
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: text-to-speech-french
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 3.36.0
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from datasets import load_dataset
4
+ from transformers import pipeline, SpeechT5Processor, SpeechT5HifiGan, SpeechT5ForTextToSpeech
5
+
6
+ model_id = "Sandiago21/speecht5_finetuned_facebook_voxpopuli_french" # update with your model id
7
+ # pipe = pipeline("automatic-speech-recognition", model=model_id)
8
+ model = SpeechT5ForTextToSpeech.from_pretrained(model_id)
9
+ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
10
+ embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
11
+ speaker_embeddings = torch.tensor(embeddings_dataset[7440]["xvector"]).unsqueeze(0)
12
+
13
+ # checkpoint = "microsoft/speecht5_tts"
14
+ processor = SpeechT5Processor.from_pretrained(model_id)
15
+
16
+ replacements = [
17
+ ("à", "a"),
18
+ ("â", "a"),
19
+ ("ç", "c"),
20
+ ("è", "e"),
21
+ ("ë", "e"),
22
+ ("î", "i"),
23
+ ("ï", "i"),
24
+ ("ô", "o"),
25
+ ("ù", "u"),
26
+ ("û", "u"),
27
+ ("ü", "u"),
28
+ ]
29
+
30
+
31
+ def cleanup_text(text):
32
+ for src, dst in replacements:
33
+ text = text.replace(src, dst)
34
+ return text
35
+
36
+ def synthesize_speech(text):
37
+ text = cleanup_text(text)
38
+ inputs = processor(text=text, return_tensors="pt")
39
+
40
+ speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
41
+
42
+ return gr.Audio.update(value=(16000, speech.cpu().numpy()))
43
+
44
+ syntesize_speech_gradio = gr.Interface(
45
+ synthesize_speech,
46
+ inputs = gr.Textbox(label="Text", placeholder="Type something here..."),
47
+ outputs=gr.Audio(),
48
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ datasets
4
+ torchaudio
5
+ sentencepiece==0.1.99
6
+