Matthijs Hollemans commited on
Commit
ae71d4b
1 Parent(s): acc1831

add application

Browse files
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ *.pyc
2
+ __pycache__/
3
+ .DS_Store
4
+
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Speecht5 Tts Demo
3
- emoji:
4
- colorFrom: blue
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.17.0
1
  ---
2
+ title: SpeechT5 Speech Synthesis Demo
3
+ emoji: 👩‍🎤
4
+ colorFrom: yellow
5
  colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.17.0
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import librosa
3
+ import numpy as np
4
+ import torch
5
+
6
+ from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
7
+
8
+
9
+ checkpoint = "Matthijs/speecht5_tts"
10
+ processor = SpeechT5Processor.from_pretrained(checkpoint)
11
+ model = SpeechT5ForTextToSpeech.from_pretrained(checkpoint)
12
+ vocoder = SpeechT5HifiGan.from_pretrained("Matthijs/speecht5_hifigan")
13
+
14
+
15
+ speaker_embeddings = {
16
+ "BDL": "spkemb/cmu_us_bdl_arctic-wav-arctic_a0009.npy",
17
+ "CLB": "spkemb/cmu_us_clb_arctic-wav-arctic_a0144.npy",
18
+ "RMS": "spkemb/cmu_us_rms_arctic-wav-arctic_b0353.npy",
19
+ "SLT": "spkemb/cmu_us_slt_arctic-wav-arctic_a0508.npy",
20
+ }
21
+
22
+
23
+ def predict(text, speaker):
24
+ if len(text.strip()) == 0:
25
+ return (16000, np.zeros(0).astype(np.int16))
26
+
27
+ inputs = processor(text=text, return_tensors="pt")
28
+
29
+ speaker_embedding = np.load(speaker_embeddings[speaker[:3]])
30
+ speaker_embedding = torch.tensor(speaker_embedding).unsqueeze(0)
31
+
32
+ speech = model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
33
+
34
+ speech = (speech.numpy() * 32767).astype(np.int16)
35
+ return (16000, speech)
36
+
37
+
38
+ title = "SpeechT5: Speech Synthesis"
39
+
40
+ description = """
41
+ The <b>SpeechT5</b> model is pre-trained on text as well as speech inputs, with targets that are also a mix of text and speech.
42
+ By pre-training on text and speech at the same time, it learns unified representations for both, resulting in improved modeling capabilities.
43
+
44
+ SpeechT5 can be fine-tuned for different speech tasks. This space demonstrates the <b>text-to-speech</b> (TTS) checkpoint for the English language.
45
+
46
+ See also the <a href="https://huggingface.co/spaces/Matthijs/speecht5-asr-demo">speech recognition (ASR) demo</a>
47
+ and the <a href="https://huggingface.co/spaces/Matthijs/speecht5-vc-demo">voice conversion demo</a>.
48
+
49
+ <b>How to use:</b> Enter some English text and choose a speaker. The output is a mel spectrogram, which is converted to a mono 16 kHz waveform by the
50
+ HiFi-GAN vocoder. Because the model always applies random dropout, each attempt will give slightly different results.
51
+ """
52
+
53
+ article = """
54
+ <div style='margin:20px auto;'>
55
+
56
+ <p>References: <a href="https://arxiv.org/abs/2110.07205">SpeechT5 paper</a> |
57
+ <a href="https://github.com/microsoft/SpeechT5/">original GitHub</a> |
58
+ <a href="https://huggingface.co/mechanicalsea/speecht5-tts">original weights</a></p>
59
+
60
+ <pre>
61
+ @article{Ao2021SpeechT5,
62
+ title = {SpeechT5: Unified-Modal Encoder-Decoder Pre-training for Spoken Language Processing},
63
+ author = {Junyi Ao and Rui Wang and Long Zhou and Chengyi Wang and Shuo Ren and Yu Wu and Shujie Liu and Tom Ko and Qing Li and Yu Zhang and Zhihua Wei and Yao Qian and Jinyu Li and Furu Wei},
64
+ eprint={2110.07205},
65
+ archivePrefix={arXiv},
66
+ primaryClass={eess.AS},
67
+ year={2021}
68
+ }
69
+ </pre>
70
+
71
+ <p>Speaker embeddings were generated from <a href="http://www.festvox.org/cmu_arctic/">CMU ARCTIC</a> using <a href="https://huggingface.co/mechanicalsea/speecht5-vc/blob/main/manifest/utils/prep_cmu_arctic_spkemb.py">this script</a>.</p>
72
+
73
+ </div>
74
+ """
75
+
76
+ examples = [
77
+ ["It is not in the stars to hold our destiny but in ourselves."],
78
+ ["The octopus and Oliver went to the opera in October."],
79
+ ["She sells seashells by the seashore. I saw a kitten eating chicken in the kitchen."],
80
+ ["Brisk brave brigadiers brandished broad bright blades, blunderbusses, and bludgeons—balancing them badly."],
81
+ ["A synonym for cinnamon is a cinnamon synonym."],
82
+ ["How much wood would a woodchuck chuck if a woodchuck could chuck wood? He would chuck, he would, as much as he could, and chuck as much wood as a woodchuck would if a woodchuck could chuck wood."],
83
+ ]
84
+
85
+ gr.Interface(
86
+ fn=predict,
87
+ inputs=[
88
+ gr.Text(label="Input Text"),
89
+ gr.Radio(label="Speaker", choices=["BDL (male)", "CLB (female)", "RMS (male)", "SLT (female)"], value="BDL (male)"),
90
+ ],
91
+ outputs=[
92
+ gr.Audio(label="Generated Speech", type="numpy"),
93
+ ],
94
+ title=title,
95
+ description=description,
96
+ article=article,
97
+ examples=examples,
98
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ git+https://github.com/hollance/transformers.git@speecht5
2
+ torch
3
+ torchaudio
4
+ soundfile
5
+ librosa
6
+ samplerate
7
+ resampy
spkemb/cmu_us_bdl_arctic-wav-arctic_a0009.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:215326eae3a428af8934c385fbe043b36c72849ca17d1d013adeb189e6bd6962
3
+ size 2176
spkemb/cmu_us_clb_arctic-wav-arctic_a0144.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf67b36c47edfb1851466a1dff081b436bc6809b5ebc12811d9df0c0d0f28d0e
3
+ size 2176
spkemb/cmu_us_rms_arctic-wav-arctic_b0353.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a49dac3e9c3a71a4dbca4c364233c7915ae6e0cb71b2ceaed97296231b95cb50
3
+ size 2176
spkemb/cmu_us_slt_arctic-wav-arctic_a0508.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f71ffadda3f3a4de079740a0b34963824dc644d9d5442283bd0a2b0d4f44ff0b
3
+ size 2176