Spaces:
Runtime error
Runtime error
Commit
·
c2e31de
1
Parent(s):
cd03ad0
feat(generator): bundle as function and generate on button click
Browse files
app.py
CHANGED
@@ -10,16 +10,21 @@ text = st.text_input(
|
|
10 |
value = "Hi, Welcome to theserverfault.com"
|
11 |
)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
10 |
value = "Hi, Welcome to theserverfault.com"
|
11 |
)
|
12 |
|
13 |
+
def generate_speech():
|
14 |
+
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
|
15 |
+
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
|
16 |
+
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
|
17 |
+
inputs = processor(text=text, return_tensors="pt")
|
18 |
|
19 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
20 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
21 |
|
22 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
23 |
|
24 |
+
sf.write("speech.wav", speech.numpy(), samplerate=16000)
|
|
|
25 |
|
26 |
+
if st.button("Generate"):
|
27 |
+
generate_speech()
|
28 |
+
audio_file = open("speech.wav", 'rb')
|
29 |
+
audio_bytes = audio_file.read()
|
30 |
+
st.audio(audio_bytes, format="audio/wav")
|