Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
DeepSpeech
提交
2c75c923
D
DeepSpeech
项目概览
PaddlePaddle
/
DeepSpeech
接近 2 年 前同步成功
通知
209
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看板
提交
2c75c923
编写于
8月 23, 2021
作者:
小湉湉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix_mfa
上级
9ac6d65a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
79 addition
and
48 deletion
+79
-48
deepspeech/decoders/swig/setup.py
deepspeech/decoders/swig/setup.py
+3
-2
examples/aishell/s0/conf/augmentation.json
examples/aishell/s0/conf/augmentation.json
+1
-1
examples/thchs30/a0/local/data.sh
examples/thchs30/a0/local/data.sh
+22
-16
examples/thchs30/a0/local/gen_word2phone.py
examples/thchs30/a0/local/gen_word2phone.py
+38
-18
examples/thchs30/a0/local/reorganize_thchs30.py
examples/thchs30/a0/local/reorganize_thchs30.py
+5
-4
examples/thchs30/a0/run.sh
examples/thchs30/a0/run.sh
+9
-6
tools/extras/install_mfa.sh
tools/extras/install_mfa.sh
+1
-1
未找到文件。
deepspeech/decoders/swig/setup.py
浏览文件 @
2c75c923
...
...
@@ -84,8 +84,9 @@ FILES = glob.glob('kenlm/util/*.cc') \
FILES
+=
glob
.
glob
(
'openfst-1.6.3/src/lib/*.cc'
)
FILES
=
[
fn
for
fn
in
FILES
if
not
(
fn
.
endswith
(
'main.cc'
)
or
fn
.
endswith
(
'test.cc'
)
or
fn
.
endswith
(
'unittest.cc'
))
fn
for
fn
in
FILES
if
not
(
fn
.
endswith
(
'main.cc'
)
or
fn
.
endswith
(
'test.cc'
)
or
fn
.
endswith
(
'unittest.cc'
))
]
LIBS
=
[
'stdc++'
]
...
...
examples/aishell/s0/conf/augmentation.json
浏览文件 @
2c75c923
...
...
@@ -33,4 +33,4 @@
},
"prob"
:
1.0
}
]
\ No newline at end of file
]
examples/thchs30/a0/local/data.sh
浏览文件 @
2c75c923
...
...
@@ -20,27 +20,33 @@ if [ ${stage} -le -1 ] && [ ${stop_stage} -ge -1 ]; then
echo
"Prepare THCHS-30 failed. Terminated."
exit
1
fi
fi
# dump manifest to data/
python3
${
MAIN_ROOT
}
/utils/dump_manifest.py
--manifest-path
=
data/manifest.train
--output-dir
=
data
# copy files to data/dict to gen word.lexicon
cp
${
TARGET_DIR
}
/thchs30/data_thchs30/lm_word/lexicon.txt data/dict/lm_word_lexicon_1
cp
${
TARGET_DIR
}
/thchs30/resource/dict/lexicon.txt data/dict/lm_word_lexicon_2
if
[
${
stage
}
-le
0
]
&&
[
${
stop_stage
}
-ge
0
]
;
then
# dump manifest to data/
python3
${
MAIN_ROOT
}
/utils/dump_manifest.py
--manifest-path
=
data/manifest.train
--output-dir
=
data
fi
# copy phone.lexicon to data/dict
cp
${
TARGET_DIR
}
/thchs30/data_thchs30/lm_phone/lexicon.txt data/dict/phone.lexicon
if
[
${
stage
}
-le
1
]
&&
[
${
stop_stage
}
-ge
1
]
;
then
# copy files to data/dict to gen word.lexicon
cp
${
TARGET_DIR
}
/thchs30/data_thchs30/lm_word/lexicon.txt data/dict/lm_word_lexicon_1
cp
${
TARGET_DIR
}
/thchs30/resource/dict/lexicon.txt data/dict/lm_word_lexicon_2
# copy phone.lexicon to data/dict
cp
${
TARGET_DIR
}
/thchs30/data_thchs30/lm_phone/lexicon.txt data/dict/phone.lexicon
fi
# gen word.lexicon
python
local
/gen_word2phone.py
--root-dir
=
data/dict
--output-dir
=
data/dict
if
[
${
stage
}
-le
2
]
&&
[
${
stop_stage
}
-ge
2
]
;
then
# gen word.lexicon
python
local
/gen_word2phone.py
--lexicon-files
=
"data/dict/lm_word_lexicon_1 data/dict/lm_word_lexicon_2"
--output-path
=
data/dict/word.lexicon
fi
# reorganize dataset for MFA
if
[
!
-d
$EXP_DIR
/thchs30_corpus
]
;
then
echo
"reorganizing thchs30 corpus..."
python
local
/reorganize_thchs30.py
--root-dir
=
data
--output-dir
=
data/thchs30_corpus
--script-type
=
$LEXICON_NAME
echo
"reorganization done."
if
[
${
stage
}
-le
3
]
&&
[
${
stop_stage
}
-ge
3
]
;
then
# reorganize dataset for MFA
if
[
!
-d
$EXP_DIR
/thchs30_corpus
]
;
then
echo
"reorganizing thchs30 corpus..."
python
local
/reorganize_thchs30.py
--root-dir
=
data
--output-dir
=
data/thchs30_corpus
--script-type
=
$LEXICON_NAME
echo
"reorganization done."
fi
fi
echo
"THCHS-30 data preparation done."
...
...
examples/thchs30/a0/local/gen_word2phone.py
浏览文件 @
2c75c923
...
...
@@ -18,6 +18,7 @@ file2: THCHS-30/resource/dict/lexicon.txt
import
argparse
from
collections
import
defaultdict
from
pathlib
import
Path
from
typing
import
List
from
typing
import
Union
# key: (cn, ('ee', 'er4')),value: count
...
...
@@ -34,7 +35,7 @@ def is_Chinese(ch):
return
False
def
proc_line
(
line
):
def
proc_line
(
line
:
str
):
line
=
line
.
strip
()
if
is_Chinese
(
line
[
0
]):
line_list
=
line
.
split
()
...
...
@@ -49,20 +50,25 @@ def proc_line(line):
cn_phones_counter
[(
cn
,
phones
)]
+=
1
def
gen_lexicon
(
root_dir
:
Union
[
str
,
Path
],
output_dir
:
Union
[
str
,
Path
]):
root_dir
=
Path
(
root_dir
).
expanduser
()
output_dir
=
Path
(
output_dir
).
expanduser
()
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
file1
=
root_dir
/
"lm_word_lexicon_1"
file2
=
root_dir
/
"lm_word_lexicon_2"
write_file
=
output_dir
/
"word.lexicon"
"""
example lines of output
the first column is a Chinese character
the second is the probability of this pronunciation
and the rest are the phones of this pronunciation
一 0.22 ii i1↩
一 0.45 ii i4↩
一 0.32 ii i2↩
一 0.01 ii i5
"""
def
gen_lexicon
(
lexicon_files
:
List
[
Union
[
str
,
Path
]],
output_path
:
Union
[
str
,
Path
]):
for
file_path
in
lexicon_files
:
with
open
(
file_path
,
"r"
)
as
f1
:
for
line
in
f1
:
proc_line
(
line
)
with
open
(
file1
,
"r"
)
as
f1
:
for
line
in
f1
:
proc_line
(
line
)
with
open
(
file2
,
"r"
)
as
f2
:
for
line
in
f2
:
proc_line
(
line
)
for
key
in
cn_phones_counter
:
cn
=
key
[
0
]
cn_counter
[
cn
].
append
((
key
[
1
],
cn_phones_counter
[
key
]))
...
...
@@ -75,7 +81,8 @@ def gen_lexicon(root_dir: Union[str, Path], output_dir: Union[str, Path]):
p
=
round
(
p
,
2
)
if
p
>
0
:
cn_counter_p
[
key
].
append
((
item
[
0
],
p
))
with
open
(
write_file
,
"w"
)
as
wf
:
with
open
(
output_path
,
"w"
)
as
wf
:
for
key
in
cn_counter_p
:
phone_p_list
=
cn_counter_p
[
key
]
for
item
in
phone_p_list
:
...
...
@@ -87,8 +94,21 @@ if __name__ == "__main__":
parser
=
argparse
.
ArgumentParser
(
description
=
"Gen Chinese characters to phone lexicon for THCHS-30 dataset"
)
# A line of word_lexicon:
# 一丁点 ii i4 d ing1 d ian3
# the first is word, and the rest are the phones of the word, and the len of phones is twice of the word's len
parser
.
add_argument
(
"--lexicon-files"
,
type
=
str
,
default
=
"data/dict/lm_word_lexicon_1 data/dict/lm_word_lexicon_2"
,
help
=
"lm_word_lexicon files"
)
parser
.
add_argument
(
"--root-dir"
,
type
=
str
,
help
=
"dir to thchs30 lm_word_lexicons"
)
parser
.
add_argument
(
"--output-dir"
,
type
=
str
,
help
=
"path to save outputs"
)
"--output-path"
,
type
=
str
,
default
=
"data/dict/word.lexicon"
,
help
=
"path to save output word2phone lexicon"
)
args
=
parser
.
parse_args
()
gen_lexicon
(
args
.
root_dir
,
args
.
output_dir
)
lexicon_files
=
args
.
lexicon_files
.
split
(
" "
)
output_path
=
Path
(
args
.
output_path
).
expanduser
()
gen_lexicon
(
lexicon_files
,
output_path
)
examples/thchs30/a0/local/reorganize_thchs30.py
浏览文件 @
2c75c923
...
...
@@ -58,8 +58,6 @@ def write_lab(root_dir: Union[str, Path],
def
reorganize_thchs30
(
root_dir
:
Union
[
str
,
Path
],
output_dir
:
Union
[
str
,
Path
]
=
None
,
script_type
=
'phone'
):
root_dir
=
Path
(
root_dir
).
expanduser
()
output_dir
=
Path
(
output_dir
).
expanduser
()
output_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
link_wav
(
root_dir
,
output_dir
)
write_lab
(
root_dir
,
output_dir
,
script_type
)
...
...
@@ -72,12 +70,15 @@ if __name__ == "__main__":
parser
.
add_argument
(
"--output-dir"
,
type
=
str
,
help
=
"path to save outputs(audio and transcriptions)"
)
help
=
"path to save outputs
(audio and transcriptions)"
)
parser
.
add_argument
(
"--script-type"
,
type
=
str
,
default
=
"phone"
,
help
=
"type of lab ('word'/'syllable'/'phone')"
)
args
=
parser
.
parse_args
()
reorganize_thchs30
(
args
.
root_dir
,
args
.
output_dir
,
args
.
script_type
)
root_dir
=
Path
(
args
.
root_dir
).
expanduser
()
output_dir
=
Path
(
args
.
output_dir
).
expanduser
()
reorganize_thchs30
(
root_dir
,
output_dir
,
args
.
script_type
)
examples/thchs30/a0/run.sh
浏览文件 @
2c75c923
...
...
@@ -14,14 +14,17 @@ source ${MAIN_ROOT}/utils/parse_options.sh || exit 1;
# gen lexicon relink gen dump
if
[
${
stage
}
-le
0
]
&&
[
${
stop_stage
}
-ge
0
]
;
then
# prepare data
bash ./local/data.sh
$LEXICON_NAME
||
exit
-1
echo
"Start prepare thchs30 data for MFA ..."
bash ./local/data.sh
$LEXICON_NAME
||
exit
-1
fi
# run MFA
if
[
!
-d
"
$EXP_DIR
/thchs30_alignment"
]
;
then
echo
"Start MFA training..."
mfa_train_and_align data/thchs30_corpus data/dict/
$LEXICON_NAME
.lexicon
$EXP_DIR
/thchs30_alignment
-o
$EXP_DIR
/thchs30_model
--clean
--verbose
--temp_directory
exp/.mfa_train_and_align
--num_jobs
$NUM_JOBS
echo
"training done!
\n
results:
$EXP_DIR
/thchs30_alignment
\n
model:
$EXP_DIR
/thchs30_model
\n
"
if
[
${
stage
}
-le
1
]
&&
[
${
stop_stage
}
-ge
1
]
;
then
# run MFA
if
[
!
-d
"
$EXP_DIR
/thchs30_alignment"
]
;
then
echo
"Start MFA training ..."
mfa_train_and_align data/thchs30_corpus data/dict/
$LEXICON_NAME
.lexicon
$EXP_DIR
/thchs30_alignment
-o
$EXP_DIR
/thchs30_model
--clean
--verbose
--temp_directory
exp/.mfa_train_and_align
--num_jobs
$NUM_JOBS
echo
"MFA training done!
\n
results:
$EXP_DIR
/thchs30_alignment
\n
model:
$EXP_DIR
/thchs30_model
\n
"
fi
fi
...
...
tools/extras/install_mfa.sh
浏览文件 @
2c75c923
...
...
@@ -4,7 +4,7 @@
test
-d
Montreal-Forced-Aligner
||
git clone https://github.com/MontrealCorpusTools/Montreal-Forced-Aligner.git
pushd
Montreal-Forced-Aligner
&&
git checkout v2.0.0a7
&&
python setup.py
install
pushd
Montreal-Forced-Aligner
&&
python setup.py
install
&&
popd
test
-d
kaldi
||
{
echo
"need install kaldi first"
;
exit
1
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录