Spaces:
Runtime error
Runtime error
File size: 1,163 Bytes
17caa3d 2bdf56e 17caa3d 2bdf56e 3dca3ac 2bdf56e c2e31de 2bdf56e c2e31de 2bdf56e c2e31de 2bdf56e c2e31de 2bdf56e c2e31de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import streamlit as st
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
from datasets import load_dataset
import torch
import soundfile as sf
st.title('Dummy Text To Speech')
text = st.text_input(
label="Enter the text you want to convert to speech",
value = "Hi, Welcome to theserverfault.com"
)
def generate_speech():
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
inputs = processor(text=text, return_tensors="pt")
embeddings_dataset = load_dataset("Matthijs/cmu-arctic-xvectors", split="validation")
speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze(0)
speech = model.generate_speech(inputs["input_ids"], speaker_embeddings, vocoder=vocoder)
sf.write("speech.wav", speech.numpy(), samplerate=16000)
if st.button("Generate"):
generate_speech()
audio_file = open("speech.wav", 'rb')
audio_bytes = audio_file.read()
st.audio(audio_bytes, format="audio/wav") |