From 09e5d8a4ac03f29c2ce6511e1a3c39136cd3e29b Mon Sep 17 00:00:00 2001 From: Mattheliu Date: Wed, 5 Jun 2024 10:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90Fix=20Speech=20Issue=20No.8=E3=80=91is?= =?UTF-8?q?sue=203652=20merge=5Fyi=20function=20has=20a=20bug=20(#3786)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 【Fix Speech Issue No.8】issue 3652 merge_yi function has a bug * 【Fix Speech Issue No.8】issue 3652 merge_yi function has a bug --- paddlespeech/t2s/frontend/tone_sandhi.py | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/paddlespeech/t2s/frontend/tone_sandhi.py b/paddlespeech/t2s/frontend/tone_sandhi.py index 690f69aa254..3558064cd69 100644 --- a/paddlespeech/t2s/frontend/tone_sandhi.py +++ b/paddlespeech/t2s/frontend/tone_sandhi.py @@ -237,30 +237,25 @@ def _merge_bu(self, seg: List[Tuple[str, str]]) -> List[Tuple[str, str]]: # output seg: [['听一听', 'v']] def _merge_yi(self, seg: List[Tuple[str, str]]) -> List[Tuple[str, str]]: new_seg = [] + skip_next = False # function 1 for i, (word, pos) in enumerate(seg): - if i - 1 >= 0 and word == "一" and i + 1 < len(seg) and seg[i - 1][ - 0] == seg[i + 1][0] and seg[i - 1][1] == "v": - if i - 1 < len(new_seg): - new_seg[i - - 1][0] = new_seg[i - 1][0] + "一" + new_seg[i - 1][0] - else: - new_seg.append([word, pos]) - new_seg.append([seg[i + 1][0], pos]) + if skip_next: + skip_next = False + continue + if i - 1 >= 0 and word == "一" and i + 1 < len(seg) and seg[i - 1][0] == seg[i + 1][0] and seg[i - 1][1] == "v": + new_seg[-1] = (new_seg[-1][0] + "一" + seg[i + 1][0], new_seg[-1][1]) + skip_next = True else: - if i - 2 >= 0 and seg[i - 1][0] == "一" and seg[i - 2][ - 0] == word and pos == "v": - continue - else: - new_seg.append([word, pos]) + new_seg.append((word, pos)) seg = new_seg new_seg = [] # function 2 for i, (word, pos) in enumerate(seg): if new_seg and new_seg[-1][0] == "一": - new_seg[-1][0] = new_seg[-1][0] + word + new_seg[-1] = (new_seg[-1][0] + word, new_seg[-1][1]) else: - new_seg.append([word, pos]) + new_seg.append((word, pos)) return new_seg # the first and the second words are all_tone_three