-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1676 from SmileGoat/add_aishell_eg
[speechx]add aishell test script & json parser & no db norm linear feature & json2kaldi type cmvn
- Loading branch information
Showing
18 changed files
with
43,192 additions
and
10 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bash | ||
|
||
data=$1 | ||
feat_scp=$2 | ||
split_feat_name=$3 | ||
numsplit=$4 | ||
|
||
|
||
if ! [ "$numsplit" -gt 0 ]; then | ||
echo "Invalid num-split argument"; | ||
exit 1; | ||
fi | ||
|
||
directories=$(for n in `seq $numsplit`; do echo $data/split${numsplit}/$n; done) | ||
feat_split_scp=$(for n in `seq $numsplit`; do echo $data/split${numsplit}/$n/${split_feat_name}; done) | ||
echo $feat_split_scp | ||
# if this mkdir fails due to argument-list being too long, iterate. | ||
if ! mkdir -p $directories >&/dev/null; then | ||
for n in `seq $numsplit`; do | ||
mkdir -p $data/split${numsplit}/$n | ||
done | ||
fi | ||
|
||
utils/split_scp.pl $feat_scp $feat_split_scp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# This contains the locations of binarys build required for running the examples. | ||
|
||
SPEECHX_ROOT=$PWD/../.. | ||
SPEECHX_EXAMPLES=$SPEECHX_ROOT/build/examples | ||
|
||
SPEECHX_TOOLS=$SPEECHX_ROOT/tools | ||
TOOLS_BIN=$SPEECHX_TOOLS/valgrind/install/bin | ||
|
||
[ -d $SPEECHX_EXAMPLES ] || { echo "Error: 'build/examples' directory not found. please ensure that the project build successfully"; } | ||
|
||
export LC_AL=C | ||
|
||
SPEECHX_BIN=$SPEECHX_EXAMPLES/decoder:$SPEECHX_EXAMPLES/feat | ||
export PATH=$PATH:$SPEECHX_BIN:$TOOLS_BIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
set +x | ||
set -e | ||
|
||
. path.sh | ||
|
||
# 1. compile | ||
if [ ! -d ${SPEECHX_EXAMPLES} ]; then | ||
pushd ${SPEECHX_ROOT} | ||
bash build.sh | ||
popd | ||
fi | ||
|
||
|
||
# 2. download model | ||
if [ ! -d ../paddle_asr_model ]; then | ||
wget -c https://paddlespeech.bj.bcebos.com/s2t/paddle_asr_online/paddle_asr_model.tar.gz | ||
tar xzfv paddle_asr_model.tar.gz | ||
mv ./paddle_asr_model ../ | ||
# produce wav scp | ||
echo "utt1 " $PWD/../paddle_asr_model/BAC009S0764W0290.wav > ../paddle_asr_model/wav.scp | ||
fi | ||
|
||
mkdir -p data | ||
data=$PWD/data | ||
aishell_wav_scp=aishell_test.scp | ||
if [ ! -d $data/test ]; then | ||
wget -c https://paddlespeech.bj.bcebos.com/s2t/paddle_asr_online/aishell_test.zip | ||
unzip -d $data aishell_test.zip | ||
realpath $data/test/*/*.wav > $data/wavlist | ||
awk -F '/' '{ print $(NF) }' $data/wavlist | awk -F '.' '{ print $1 }' > $data/utt_id | ||
paste $data/utt_id $data/wavlist > $data/$aishell_wav_scp | ||
fi | ||
|
||
model_dir=$PWD/aishell_ds2_online_model | ||
if [ ! -d $model_dir ]; then | ||
mkdir -p $model_dir | ||
wget -P $model_dir -c https://paddlespeech.bj.bcebos.com/s2t/aishell/asr0/asr0_deepspeech2_online_aishell_ckpt_0.2.0.model.tar.gz | ||
tar xzfv $model_dir/asr0_deepspeech2_online_aishell_ckpt_0.2.0.model.tar.gz -C $model_dir | ||
fi | ||
|
||
# 3. make feature | ||
aishell_online_model=$model_dir/exp/deepspeech2_online/checkpoints | ||
lm_model_dir=../paddle_asr_model | ||
label_file=./aishell_result | ||
wer=./aishell_wer | ||
|
||
nj=40 | ||
export GLOG_logtostderr=1 | ||
|
||
./local/split_data.sh $data $data/$aishell_wav_scp $aishell_wav_scp $nj | ||
|
||
data=$PWD/data | ||
# 3. gen linear feat | ||
cmvn=$PWD/cmvn.ark | ||
cmvn_json2binary_main --json_file=$model_dir/data/mean_std.json --cmvn_write_path=$cmvn | ||
|
||
utils/run.pl JOB=1:$nj $data/split${nj}/JOB/feat_log \ | ||
linear_spectrogram_without_db_norm_main \ | ||
--wav_rspecifier=scp:$data/split${nj}/JOB/${aishell_wav_scp} \ | ||
--feature_wspecifier=ark,scp:$data/split${nj}/JOB/feat.ark,$data/split${nj}/JOB/feat.scp \ | ||
--cmvn_file=$cmvn \ | ||
--streaming_chunk=0.36 | ||
|
||
text=$data/test/text | ||
|
||
# 4. recognizer | ||
utils/run.pl JOB=1:$nj $data/split${nj}/JOB/log \ | ||
offline_decoder_sliding_chunk_main \ | ||
--feature_rspecifier=scp:$data/split${nj}/JOB/feat.scp \ | ||
--model_path=$aishell_online_model/avg_1.jit.pdmodel \ | ||
--param_path=$aishell_online_model/avg_1.jit.pdiparams \ | ||
--model_output_names=softmax_0.tmp_0,tmp_5,concat_0.tmp_0,concat_1.tmp_0 \ | ||
--dict_file=$lm_model_dir/vocab.txt \ | ||
--lm_path=$lm_model_dir/avg_1.jit.klm \ | ||
--result_wspecifier=ark,t:$data/split${nj}/JOB/result | ||
|
||
cat $data/split${nj}/*/result > $label_file | ||
|
||
local/compute-wer.py --char=1 --v=1 $label_file $text > $wer | ||
tail $wer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "base/flags.h" | ||
#include "base/log.h" | ||
#include "kaldi/matrix/kaldi-matrix.h" | ||
#include "kaldi/util/kaldi-io.h" | ||
#include "utils/file_utils.h" | ||
#include "utils/simdjson.h" | ||
|
||
DEFINE_string(json_file, "", "cmvn json file"); | ||
DEFINE_string(cmvn_write_path, "./cmvn.ark", "write cmvn"); | ||
DEFINE_bool(binary, true, "write cmvn in binary (true) or text(false)"); | ||
|
||
using namespace simdjson; | ||
|
||
int main(int argc, char* argv[]) { | ||
gflags::ParseCommandLineFlags(&argc, &argv, false); | ||
google::InitGoogleLogging(argv[0]); | ||
|
||
ondemand::parser parser; | ||
padded_string json = padded_string::load(FLAGS_json_file); | ||
ondemand::document val = parser.iterate(json); | ||
ondemand::object doc = val; | ||
kaldi::int32 frame_num = uint64_t(doc["frame_num"]); | ||
auto mean_stat = doc["mean_stat"]; | ||
std::vector<kaldi::BaseFloat> mean_stat_vec; | ||
for (double x : mean_stat) { | ||
mean_stat_vec.push_back(x); | ||
} | ||
auto var_stat = doc["var_stat"]; | ||
std::vector<kaldi::BaseFloat> var_stat_vec; | ||
for (double x : var_stat) { | ||
var_stat_vec.push_back(x); | ||
} | ||
|
||
size_t mean_size = mean_stat_vec.size(); | ||
kaldi::Matrix<double> cmvn_stats(2, mean_size + 1); | ||
for (size_t idx = 0; idx < mean_size; ++idx) { | ||
cmvn_stats(0, idx) = mean_stat_vec[idx]; | ||
cmvn_stats(1, idx) = var_stat_vec[idx]; | ||
} | ||
cmvn_stats(0, mean_size) = frame_num; | ||
kaldi::WriteKaldiObject(cmvn_stats, FLAGS_cmvn_write_path, FLAGS_binary); | ||
LOG(INFO) << "the json file have write into " << FLAGS_cmvn_write_path; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.