Spaces:
Runtime error
Runtime error
Commit
·
2bdf56e
1
Parent(s):
17caa3d
add basic file
Browse files
app.py
CHANGED
@@ -1,4 +1,26 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
3 |
+
from datasets import load_dataset
|
4 |
+
import torch
|
5 |
+
import soundfile as sf
|
6 |
+
from datasets import load_dataset
|
7 |
|
8 |
+
st.title('Dummy Text To Speech')
|
9 |
+
text = st.text_input(
|
10 |
+
label="Enter the text you want to convert to speech",
|
11 |
+
vlue = "Hi, Welcome to theserverfault.com"
|
12 |
+
)
|
13 |
+
|
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 |
+
|
18 |
+
|
19 |
+
inputs = processor(text=text, return_tensors="pt")
|
20 |
+
|
21 |
+
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
|
22 |
+
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
|
23 |
+
|
24 |
+
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
|
25 |
+
|
26 |
+
sf.write("speech.wav", speech.numpy(), samplerate=16000)
|