Skip to content

Commit b42c209

Browse files
committed
add a simple tn
1 parent 3b0421f commit b42c209

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

tensorflow_tts/processor/baker.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import os
2-
import re
32
import numpy as np
43
import librosa
54
import soundfile as sf
5+
from pypinyin.style._utils import get_finals, get_initials
6+
from g2pM import G2pM
67

78

89
_pad = ['_']
@@ -60,6 +61,8 @@ def __init__(self, data_dir, target_rate=24000, cleaner_names=None):
6061
items.append([' '.join(phonemes), wav_path, self.speaker_name, utt_id])
6162
self.items = items
6263

64+
self.g2pm = G2pM()
65+
6366
@staticmethod
6467
def deal_r(phonemes):
6568
result = []
@@ -71,20 +74,26 @@ def deal_r(phonemes):
7174
result.append(p)
7275
return result
7376

74-
# @staticmethod
75-
# def get_initials_and_finals(text):
76-
# result = []
77-
# for x in text.split():
78-
# initials = get_initials(x.strip(), False)
79-
# finals = get_finals(x.strip(), False)
80-
# if initials != "":
81-
# result.append(initials)
82-
# if finals != "":
83-
# # we replace ar4 to a4 er5
84-
# if finals[-2] == 'r' and finals[:2] != 'er':
85-
# finals = finals[:-2] + finals[-1] + ' er5'
86-
# result.append(finals)
87-
# return ' '.join(result)
77+
@staticmethod
78+
def get_initials_and_finals(text):
79+
result = []
80+
for x in text:
81+
initials = get_initials(x.strip(), False)
82+
finals = get_finals(x.strip(), False)
83+
if initials != "":
84+
# for y and w, we do not have initials
85+
if initials == 'w' or initials == 'y':
86+
pass
87+
else:
88+
result.append(initials)
89+
if finals != "":
90+
# we replace ar4 to a4 er5
91+
if finals[-1].isdigit() and finals[-2] == 'r' and finals[:2] != 'er':
92+
result.append(finals[:-2] + finals[-1])
93+
result.append('er5')
94+
else:
95+
result.append(finals)
96+
return ' '.join(result)
8897

8998
def get_one_sample(self, item):
9099
text, wav_file, speaker_name, utt_id = item
@@ -115,10 +124,14 @@ def get_one_sample(self, item):
115124

116125
return sample
117126

118-
@staticmethod
119-
def text_to_sequence(text):
127+
def text_to_sequence(self, text, inference=False):
120128
global _symbol_to_id
121129

130+
if inference:
131+
text = self.g2pm(text)
132+
text = self.get_initials_and_finals(text)
133+
print(text)
134+
122135
sequence = []
123136
for symbol in text.split():
124137
idx = _symbol_to_id[symbol]

0 commit comments

Comments
 (0)