Spaces:
Runtime error
Runtime error
File size: 898 Bytes
9078865 13279cf 9078865 d4c3b55 9078865 d4c3b55 9078865 |
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 31 32 33 34 |
import io
import transformers
import numpy as np
import streamlit as st
from GPTTTS import GPTTTSTokenizer, GPTTTS
import torch
import torchaudio
import tempfile
# Load your GPTTTSTokenizer
tokenizer = GPTTTSTokenizer()
# Load the GPT-TTS model
model = GPTTTS()
st.title("GPT-TTS Demo")
user_text = st.text_input("Enter text:")
if user_text:
# Tokenize the input text
inputs = tokenizer(user_text)["input_ids"]
with st.spinner("Generating audio..."):
# Generate the audio tensor
with torch.no_grad():
audio = model(inputs)
# Save the audio tensor to a temporary file
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_wav:
torchaudio.save(tmp_wav.name, audio, sample_rate=model.sample_rate)
# Load the temporary file and play the audio
st.audio(tmp_wav.read(), format="audio/wav")
|