Spaces:
Runtime error
Runtime error
File size: 737 Bytes
03ac98a fdd9c78 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a c97a4f3 03ac98a fdd9c78 03ac98a fdd9c78 03ac98a fdd9c78 03ac98a fdd9c78 03ac98a fdd9c78 03ac98a fdd9c78 03ac98a c97a4f3 fdd9c78 | 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 35 36 37 38 39 | import torch
import soundfile as sf
import tempfile
from transformers import AutoTokenizer
from transformers import AutoModelForSeq2SeqLM
model = None
tokenizer = None
def load_model():
global model, tokenizer
if model is None:
model_name = "sarvamai/sarvam-tts"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def generate_voice(text):
load_model()
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
audio = model.generate(**inputs)
audio_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
sf.write(audio_file.name, audio.numpy(), 22050)
return audio_file.name |