Phonemes WIP

This commit is contained in:
Brandon Thomas
2022-06-28 03:25:02 -04:00
parent 6a43c8d7ca
commit b20ac5ff89
4 changed files with 45 additions and 0 deletions
View File
+16
View File
@@ -0,0 +1,16 @@
"""
Base class for Arpabet Sequence Transformers.
"""
class ArpabetTransformer:
def transform_text(self, text):
"""
Input: String text sequence
Output: 2-dimensional tensor sequence
"""
pass
+29
View File
@@ -0,0 +1,29 @@
import torch
import numpy as np
from base import ArpabetTransformer
class EnglishMixedArpabetTransformerV1(ArpabetTransformer):
def transform_text(self, text):
pre_sequence = self._handle_multi_lines(text)
return self._convert_to_sequence(pre_sequence)
def _handle_multi_lines(self, text):
# NB: This code is adapted from vanilla Tacotron. It's not very graceful.
pre_sequence = ''
for line in text.split("\n"):
if len(line) < 1:
continue
if line[-1] != ";":
line = line + ";"
pre_sequence += line
return pre_sequence
def _convert_to_sequence(self, pre_sequence_text):
with torch.no_grad():
# save VRAM by not including gradients
sequence = np.array(text_to_sequence(pre_sequence_text, ['english_cleaners']))[None, :]
sequence = torch.autograd.Variable(torch.from_numpy(sequence)).cuda().long()
return sequence
View File