๐Ÿ“ฆ PeDro0210 / Glados-AI

๐Ÿ“„ tools.py ยท 12 lines
1
2
3
4
5
6
7
8
9
10
11
12import torch

from gladosTTS.utils.text.cleaners import Cleaner
from gladosTTS.utils.text.tokenizer import Tokenizer

def prepare_text(text: str)->str:
    if not ((text[-1] == '.') or (text[-1] == '?') or (text[-1] == '!')):
        text = text + '.'
    cleaner = Cleaner('english_cleaners', True, 'en-us')
    tokenizer = Tokenizer()
    return torch.as_tensor(tokenizer(cleaner(text)), dtype=torch.long, device='cpu').unsqueeze(0)