mirror of https://github.com/coqui-ai/TTS.git
phonem updates
This commit is contained in:
parent
da30c3c9b3
commit
421787277f
|
@ -6,7 +6,7 @@ import torch
|
||||||
import random
|
import random
|
||||||
from torch.utils.data import Dataset
|
from torch.utils.data import Dataset
|
||||||
|
|
||||||
from utils.text import text_to_sequence, phoneme_to_sequence
|
from utils.text import text_to_sequence, phonem_to_sequence
|
||||||
from utils.data import (prepare_data, pad_per_step, prepare_tensor,
|
from utils.data import (prepare_data, pad_per_step, prepare_tensor,
|
||||||
prepare_stop_target)
|
prepare_stop_target)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import re
|
import re
|
||||||
from utils.text import cleaners
|
from utils.text import cleaners
|
||||||
from utils.text.symbols import symbols, phonemes
|
from utils.text.symbols import symbols, phonemes
|
||||||
|
from utils.text.cmudict import text2phone
|
||||||
|
|
||||||
# Mappings from symbol to numeric ID and vice versa:
|
# Mappings from symbol to numeric ID and vice versa:
|
||||||
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
|
_symbol_to_id = {s: i for i, s in enumerate(symbols)}
|
||||||
|
@ -15,9 +16,18 @@ _id_to_phonemes = {i: s for i, s in enumerate(phonemes)}
|
||||||
_curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
_curly_re = re.compile(r'(.*?)\{(.+?)\}(.*)')
|
||||||
|
|
||||||
|
|
||||||
def phoneme_to_sequence(text, cleaner_names):
|
def phonem_to_sequence(text, cleaner_names):
|
||||||
|
'''
|
||||||
|
TODO: This ignores punctuations
|
||||||
|
'''
|
||||||
sequence = []
|
sequence = []
|
||||||
sequence += _phonem_to_sequence(_clean_text(text, cleaner_names))
|
clean_text = _clean_text(text, cleaner_names)
|
||||||
|
for word in clean_text.split():
|
||||||
|
phonems_text = text2phone(word)
|
||||||
|
if phonems_text == None:
|
||||||
|
continue
|
||||||
|
sequence += _phonem_to_sequence(phonems_text)
|
||||||
|
sequence.append(_phonemes_to_id[' '])
|
||||||
sequence.append(_phonemes_to_id['~'])
|
sequence.append(_phonemes_to_id['~'])
|
||||||
return sequence
|
return sequence
|
||||||
|
|
||||||
|
@ -66,6 +76,17 @@ def sequence_to_text(sequence):
|
||||||
return result.replace('}{', ' ')
|
return result.replace('}{', ' ')
|
||||||
|
|
||||||
|
|
||||||
|
def sequence_to_phonem(sequence):
|
||||||
|
'''Converts a sequence of IDs back to a string'''
|
||||||
|
result = ''
|
||||||
|
for symbol_id in sequence:
|
||||||
|
if symbol_id in _id_to_phonemes:
|
||||||
|
s = _id_to_phonemes[symbol_id]
|
||||||
|
print(s)
|
||||||
|
result += s
|
||||||
|
return result.replace('}{', ' ')
|
||||||
|
|
||||||
|
|
||||||
def _clean_text(text, cleaner_names):
|
def _clean_text(text, cleaner_names):
|
||||||
for name in cleaner_names:
|
for name in cleaner_names:
|
||||||
cleaner = getattr(cleaners, name)
|
cleaner = getattr(cleaners, name)
|
||||||
|
@ -80,7 +101,7 @@ def _symbols_to_sequence(symbols):
|
||||||
|
|
||||||
|
|
||||||
def _phonem_to_sequence(phonemes):
|
def _phonem_to_sequence(phonemes):
|
||||||
return [_phonemes_to_id[s] for s in phonemes if _should_keep_phonem(s)]
|
return [_phonemes_to_id[s] for s in phonemes.split(" ") if _should_keep_phonem(s)]
|
||||||
|
|
||||||
|
|
||||||
def _arpabet_to_sequence(text):
|
def _arpabet_to_sequence(text):
|
||||||
|
|
|
@ -64,12 +64,11 @@ _phonemes = set(_phonemes)
|
||||||
|
|
||||||
def text2phone(text):
|
def text2phone(text):
|
||||||
seperator = phonemizer.separator.Separator('', '', ' ')
|
seperator = phonemizer.separator.Separator('', '', ' ')
|
||||||
ph = phonemizer.phonemize(text, separator=seperator)
|
try:
|
||||||
ph = ph.split(' ')
|
ph = phonemizer.phonemize(text, separator=seperator)
|
||||||
ph.remove('')
|
except:
|
||||||
|
ph = None
|
||||||
result = [char2code[p] for p in ph]
|
return ph
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
class CMUDict:
|
class CMUDict:
|
||||||
|
@ -95,6 +94,20 @@ class CMUDict:
|
||||||
'''Returns list of ARPAbet pronunciations of the given word.'''
|
'''Returns list of ARPAbet pronunciations of the given word.'''
|
||||||
return self._entries.get(word.upper())
|
return self._entries.get(word.upper())
|
||||||
|
|
||||||
|
def get_arpabet(self, word, cmudict, punctuation_symbols):
|
||||||
|
first_symbol, last_symbol = '', ''
|
||||||
|
if len(word) > 0 and word[0] in punctuation_symbols:
|
||||||
|
first_symbol = word[0]
|
||||||
|
word = word[1:]
|
||||||
|
if len(word) > 0 and word[-1] in punctuation_symbols:
|
||||||
|
last_symbol = word[-1]
|
||||||
|
word = word[:-1]
|
||||||
|
arpabet = cmudict.lookup(word)
|
||||||
|
if arpabet is not None:
|
||||||
|
return first_symbol + '{%s}' % arpabet[0] + last_symbol
|
||||||
|
else:
|
||||||
|
return first_symbol + word + last_symbol
|
||||||
|
|
||||||
|
|
||||||
_alt_re = re.compile(r'\([0-9]+\)')
|
_alt_re = re.compile(r'\([0-9]+\)')
|
||||||
|
|
||||||
|
|
|
@ -10,13 +10,15 @@ from utils.text import cmudict
|
||||||
_pad = '_'
|
_pad = '_'
|
||||||
_eos = '~'
|
_eos = '~'
|
||||||
_characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\'(),-.:;? '
|
_characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\'(),-.:;? '
|
||||||
|
_punctuations = '!\'(),-.:;? '
|
||||||
|
|
||||||
# Prepend "@" to ARPAbet symbols to ensure uniqueness (some are the same as uppercase letters):
|
# Prepend "@" to ARPAbet symbols to ensure uniqueness (some are the same as uppercase letters):
|
||||||
_arpabet = ['@' + s for s in cmudict._phonemes]
|
_arpabet = ['@' + s for s in cmudict._phonemes]
|
||||||
|
|
||||||
# Export all symbols:
|
# Export all symbols:
|
||||||
symbols = [_pad, _eos] + list(_characters) + _arpabet
|
symbols = [_pad, _eos] + list(_characters) + _arpabet
|
||||||
phonemes = [_pad, _eos] + cmudict._phonemes + list('!\'(),-.:;?')
|
phonemes = [_pad, _eos] + list(cmudict._phonemes) + list(_punctuations)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(symbols)
|
print(symbols)
|
||||||
|
print(phonemes)
|
||||||
|
|
Loading…
Reference in New Issue