Sandiago21 commited on
Commit
1b3eb5e
1 Parent(s): 9127e6d

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +3 -9
  2. app.py +107 -0
  3. requirements.txt +6 -0
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Text To Speech German
3
- emoji: 🌍
4
- colorFrom: purple
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 3.38.0
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-german
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 3.36.0
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_mozilla_foundation_common_voice_13_german" # update with your model id
7
+ model = SpeechT5ForTextToSpeech.from_pretrained(model_id)
8
+ vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
9
+ embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
10
+ speaker_embeddings = torch.tensor(embeddings_dataset[7440]["xvector"]).unsqueeze(0)
11
+
12
+ processor = SpeechT5Processor.from_pretrained(model_id)
13
+
14
+ replacements = [
15
+ ("Ä", "E"),
16
+ ("Æ", "E"),
17
+ ("Ç", "C"),
18
+ ("É", "E"),
19
+ ("Í", "I"),
20
+ ("Ó", "O"),
21
+ ("Ö", "E"),
22
+ ("Ü", "Y"),
23
+ ("ß", "S"),
24
+ ("à", "a"),
25
+ ("á", "a"),
26
+ ("ã", "a"),
27
+ ("ä", "e"),
28
+ ("å", "a"),
29
+ ("ë", "e"),
30
+ ("í", "i"),
31
+ ("ï", "i"),
32
+ ("ð", "o"),
33
+ ("ñ", "n"),
34
+ ("ò", "o"),
35
+ ("ó", "o"),
36
+ ("ô", "o"),
37
+ ("ö", "u"),
38
+ ("ú", "u"),
39
+ ("ü", "y"),
40
+ ("ý", "y"),
41
+ ("Ā", "A"),
42
+ ("ā", "a"),
43
+ ("ă", "a"),
44
+ ("ą", "a"),
45
+ ("ć", "c"),
46
+ ("Č", "C"),
47
+ ("č", "c"),
48
+ ("ď", "d"),
49
+ ("Đ", "D"),
50
+ ("ę", "e"),
51
+ ("ě", "e"),
52
+ ("ğ", "g"),
53
+ ("İ", "I"),
54
+ ("О", "O"),
55
+ ("Ł", "L"),
56
+ ("ń", "n"),
57
+ ("ň", "n"),
58
+ ("Ō", "O"),
59
+ ("ō", "o"),
60
+ ("ő", "o"),
61
+ ("ř", "r"),
62
+ ("Ś", "S"),
63
+ ("ś", "s"),
64
+ ("Ş", "S"),
65
+ ("ş", "s"),
66
+ ("Š", "S"),
67
+ ("š", "s"),
68
+ ("ū", "u"),
69
+ ("ź", "z"),
70
+ ("Ż", "Z"),
71
+ ("Ž", "Z"),
72
+ ("ǐ", "i"),
73
+ ("ǐ", "i"),
74
+ ("ș", "s"),
75
+ ("ț", "t"),
76
+ ]
77
+
78
+
79
+ title = "Text-to-Speech"
80
+ description = """
81
+ Demo for text-to-speech translation in German. Demo uses [Sandiago21/speecht5_finetuned_mozilla_foundation_common_voice_13_german](https://huggingface.co/Sandiago21/speecht5_finetuned_mozilla_foundation_common_voice_13_german) checkpoint, which is based on Microsoft's
82
+ [SpeechT5 TTS](https://huggingface.co/microsoft/speecht5_tts) model and is fine-tuned in German Audio dataset
83
+ ![Text-to-Speech (TTS)"](https://geekflare.com/wp-content/uploads/2021/07/texttospeech-1200x385.png "Diagram of Text-to-Speech (TTS)")
84
+ """
85
+
86
+
87
+ def cleanup_text(text):
88
+ for src, dst in replacements:
89
+ text = text.replace(src, dst)
90
+ return text
91
+
92
+ def synthesize_speech(text):
93
+ text = cleanup_text(text)
94
+ inputs = processor(text=text, return_tensors="pt")
95
+
96
+ speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
97
+
98
+ return gr.Audio.update(value=(16000, speech.cpu().numpy()))
99
+
100
+ syntesize_speech_gradio = gr.Interface(
101
+ synthesize_speech,
102
+ inputs = gr.Textbox(label="Text", placeholder="Type something here..."),
103
+ outputs=gr.Audio(),
104
+ examples=["Daher wird die Reform der Europäischen Sozialfondsverordnung, die wir morgen beschließen, auch umgehend in Kraft treten."],
105
+ title=title,
106
+ description=description,
107
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ datasets
4
+ torchaudio
5
+ sentencepiece==0.1.99
6
+