File size: 354 Bytes
caf2559
02c9b64
caf2559
 
 
02c9b64
caf2559
 
02c9b64
caf2559
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gc
from os import getenv
from transformers import pipeline
from utils import spaces_gpu


@spaces_gpu
def text_to_speech(text: str) -> tuple[int, bytes]:
    narrator = pipeline("text-to-speech", getenv("TEXT_TO_SPEECH_MODEL"))
    del narrator
    gc.collect()
    result = narrator(text)
    return (result["sampling_rate"], result["audio"][0])