Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
112a0a40
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
大约 1 年 前同步成功
通知
207
Star
8425
Fork
1598
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
245
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DeepSpeech
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
245
Issue
245
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
112a0a40
编写于
8月 19, 2022
作者:
小湉湉
提交者:
GitHub
8月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2272 from lym0302/develop
[tts] fix point bug
上级
4a59702d
677e0961
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
74 addition
and
13 deletion
+74
-13
paddlespeech/t2s/frontend/mix_frontend.py
paddlespeech/t2s/frontend/mix_frontend.py
+74
-13
未找到文件。
paddlespeech/t2s/frontend/mix_frontend.py
浏览文件 @
112a0a40
...
...
@@ -60,9 +60,16 @@ class MixFrontend():
else
:
return
False
def
_split
(
self
,
text
:
str
)
->
List
[
str
]:
text
=
re
.
sub
(
r
'[《》【】<=>{}()()#&@“”^_|…\\]'
,
''
,
text
)
# 替换英文句子的句号 "." --> "。" 用于后续分句
def
is_end
(
self
,
before_char
,
after_char
)
->
bool
:
if
((
self
.
is_alphabet
(
before_char
)
or
before_char
==
" "
)
and
(
self
.
is_alphabet
(
after_char
)
or
after_char
==
" "
)):
return
True
else
:
return
False
def
_replace
(
self
,
text
:
str
)
->
str
:
new_text
=
""
# get "." indexs
point
=
"."
point_indexs
=
[]
index
=
-
1
...
...
@@ -70,23 +77,77 @@ class MixFrontend():
index
=
text
.
find
(
"."
,
index
+
1
,
len
(
text
))
point_indexs
.
append
(
index
)
print
(
point_indexs
)
# replace "." -> "。" when English sentence ending
if
len
(
point_indexs
)
==
0
:
new_text
=
text
for
point_index
in
point_indexs
:
# 如果点在最开始或者最末尾的位置,不处理
elif
len
(
point_indexs
)
==
1
:
point_index
=
point_indexs
[
0
]
if
point_index
==
0
or
point_index
==
len
(
text
)
-
1
:
pass
new_text
=
text
else
:
if
((
self
.
is_alphabet
(
text
[
point_index
-
1
])
or
text
[
point_index
-
1
]
==
" "
)
and
(
self
.
is_alphabet
(
text
[
point_index
+
1
])
or
text
[
point_index
+
1
]
==
" "
)):
text
=
text
.
replace
(
text
[
point_index
],
"。"
)
if
not
self
.
is_end
(
text
[
point_index
-
1
],
text
[
point_index
+
1
]):
new_text
=
text
else
:
new_text
=
text
[:
point_index
]
+
"。"
+
text
[
point_index
+
1
:]
elif
len
(
point_indexs
)
==
2
:
first_index
=
point_indexs
[
0
]
end_index
=
point_indexs
[
1
]
# first
if
first_index
!=
0
:
if
not
self
.
is_end
(
text
[
first_index
-
1
],
text
[
first_index
+
1
]):
new_text
+=
(
text
[:
first_index
]
+
"."
)
else
:
new_text
+=
(
text
[:
first_index
]
+
"。"
)
else
:
new_text
+=
"."
# last
if
end_index
!=
len
(
text
)
-
1
:
if
not
self
.
is_end
(
text
[
end_index
-
1
],
text
[
end_index
+
1
]):
new_text
+=
text
[
point_indexs
[
-
2
]
+
1
:
]
else
:
new_text
+=
(
text
[
point_indexs
[
-
2
]
+
1
:
end_index
]
+
"。"
+
text
[
end_index
+
1
:
])
else
:
new_text
+=
"."
else
:
first_index
=
point_indexs
[
0
]
end_index
=
point_indexs
[
-
1
]
# first
if
first_index
!=
0
:
if
not
self
.
is_end
(
text
[
first_index
-
1
],
text
[
first_index
+
1
]):
new_text
+=
(
text
[:
first_index
]
+
"."
)
else
:
new_text
+=
(
text
[:
first_index
]
+
"。"
)
else
:
new_text
+=
"."
# middle
for
j
in
range
(
1
,
len
(
point_indexs
)
-
1
):
point_index
=
point_indexs
[
j
]
if
not
self
.
is_end
(
text
[
point_index
-
1
],
text
[
point_index
+
1
]):
new_text
+=
(
text
[
point_indexs
[
j
-
1
]
+
1
:
point_index
]
+
"."
)
else
:
new_text
+=
(
text
[
point_indexs
[
j
-
1
]
+
1
:
point_index
]
+
"。"
)
# last
if
end_index
!=
len
(
text
)
-
1
:
if
not
self
.
is_end
(
text
[
end_index
-
1
],
text
[
end_index
+
1
]):
new_text
+=
text
[
point_indexs
[
-
2
]
+
1
:
]
else
:
new_text
+=
(
text
[
point_indexs
[
-
2
]
+
1
:
end_index
]
+
"。"
+
text
[
end_index
+
1
:
])
else
:
new_text
+=
"."
return
new_text
def
_split
(
self
,
text
:
str
)
->
List
[
str
]:
text
=
re
.
sub
(
r
'[《》【】<=>{}()()#&@“”^_|…\\]'
,
''
,
text
)
# 替换英文句子的句号 "." --> "。" 用于后续分句
text
=
self
.
_replace
(
text
)
text
=
self
.
SENTENCE_SPLITOR
.
sub
(
r
'\1\n'
,
text
)
text
=
text
.
strip
()
sentences
=
[
sentence
.
strip
()
for
sentence
in
re
.
split
(
r
'\n+'
,
text
)]
return
sentences
def
_distinguish
(
self
,
text
:
str
)
->
List
[
str
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录