GPT-TTS-demo / app.py
Anton Forsman
Updated imports
13279cf
raw
history blame contribute delete
898 Bytes
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")