#!/bin/bash

# Copyright 2018 Jarvan Wang Apache 2.0.

# Copyright 2016 Xiaohui Zhang Apache 2.0.

 
 

# This srcipt operates on lattice directories, such as exp/tri4a_lats

# the output is a new lat dir which has lattices from all the input lattice dirs

 
 

# Begin configuration section.

cmd=run.pl

extra_files=

num_jobs=4

# End configuration section.

echo "$0 $@" # Print the command line for logging

 
 

if [ -f path.sh ]; then . ./path.sh; fi

. parse_options.sh || exit 1;

 
 

if [[ $# -lt 3 ]]; then

echo "Usage: $0 [options] <data> <dest-lat-dir> <src-lat-dir1> <src-lat-dir2> ..."

echo "e.g.: $0 --num-jobs 32 data/train exp/tri3_lat_combined exp/tri3_lat_1 exp_tri3_lat_2"

echo "Options:"

echo " --extra-files <file1 file2...> # specify addtional files in 'src-lat-dir1' to copy"

echo " --num-jobs <nj> # number of jobs used to split the data directory."

echo " Note, files that don't appear in the first source dir will not be added even if they appear in later ones."

echo " Other than lattices, only files from the first src lat dir are copied."

exit 1;

fi

 
 

data=$1;

shift;

dest=$1;

shift;

first_src=$1;

 
 

mkdir -p $dest;

rm $dest/{lat.*.gz,num_jobs} 2>/dev/null

 
 

cp $first_src/phones.txt $dest 2>/dev/null

 
 

export LC_ALL=C

 
 

for dir in $*; do

if [ ! -f $dir/lat.1.gz ]; then

echo "$0: check if lattices (lat.*.gz) are present in $dir."

exit 1;

fi

done

 
 

for dir in $*; do

for f in tree; do

diff $first_src/$f $dir/$f 1>/dev/null 2>&1

if [ $? -ne 0 ]; then

echo "$0: Cannot combine lattice directories with different $f files."

fi

done

done

 
 

for f in final.mdl tree cmvn_opts num_jobs $extra_files; do

if [ ! -f $first_src/$f ]; then

echo "combine_lat_dir.sh: no such file $first_src/$f"

exit 1;

fi

cp $first_src/$f $dest/

done

 
 

src_id=0

temp_dir=$dest/temp

[ -d $temp_dir ] && rm -r $temp_dir;

mkdir -p $temp_dir

echo "$0: dumping lattices in each source directory as single archive and index."

for dir in $*; do

src_id=$((src_id + 1))

cur_num_jobs=$(cat $dir/num_jobs) || exit 1;

lats=$(for n in $(seq $cur_num_jobs); do echo -n "$dir/lat.$n.gz "; done)

$cmd $dir/log/copy_lattices.log \

lattice-copy "ark:gunzip -c $lats|" \

ark,scp:$temp_dir/lat.$src_id.ark,$temp_dir/lat.$src_id.scp || exit 1;

done

sort -m $temp_dir/lat.*.scp > $temp_dir/lat.scp || exit 1;

 
 

echo "$0: splitting data to get reference utt2spk for individual lat.JOB.gz files."

utils/split_data.sh $data $num_jobs || exit 1;

 
 

echo "$0: splitting the lattices to appropriate chunks according to the reference utt2spk files."

utils/filter_scps.pl JOB=1:$num_jobs \

$data/split$num_jobs/JOB/utt2spk $temp_dir/lat.scp $temp_dir/lat.JOB.scp

 
 

for i in `seq 1 $num_jobs`; do

lattice-copy scp:$temp_dir/lat.${i}.scp "ark:|gzip -c >$dest/lat.$i.gz" || exit 1;

done

 
 

echo $num_jobs > $dest/num_jobs || exit 1

 
 

echo "$0: checking the lattice files generated have at least 90% of the utterances."

for i in `seq 1 $num_jobs`; do

num_lines=`cat $temp_dir/lat.$i.scp | wc -l` || exit 1;

num_lines_tot=`cat $data/split$num_jobs/$i/utt2spk | wc -l` || exit 1;

python -c "import sys;

percent = 100.0 * float($num_lines) / $num_lines_tot

if percent < 90 :

print ('$dest/lat.$i.gz {0}% utterances missing.'.format(percent))" || exit 1;

done

rm -r $temp_dir 2>/dev/null

 
 

echo "Combined lattices and stored in $dest"

exit 0

combine_lat_dirs.sh的更多相关文章

  1. 数据库备份并分离日志表(按月)sh 脚本

    #!/bin/sh year=`date +%Y` month=`date +%m` day=`date +%d` hour=`date +%H` dir="/data/dbbackup/f ...

  2. Linux下如何查找.sh后缀的文件

    find / -name *.sh或locate *.shfind 与locate的区别:locate 配合数据库查看文件位置 find 实际搜寻硬盘查询文件名称

  3. sh 测试网段在线主机

    yum install nmap nmap -sP  192.168.21.1/24 查看网段在线主机 grep -vwf file1 file2 文件内容比较 #!/bin/bash # day=` ...

  4. Maven打包生成可运行bat/sh脚本文件

    利用Maven的appassembler-maven-plugin插件,就可以实现自动打包可运行的脚本,还可以跨平台.   <plugin>      <groupId>org ...

  5. 记一个简单的保护if 的sh脚本

    真是坑爹,就下面的sh,竟然也写了很久! if [ `pwd` != '/usr/xx/bin/tomcat' ] then echo "rstall is not allowed in c ...

  6. 主机巡检脚本:OSWatcher.sh

    主机巡检脚本:OSWatcher.sh 2016-09-26更新,目前该脚本只支持Linux操作系统,后续有需求可以继续完善. 注意: 经测试,普通用户执行脚本可以顺利执行前9项检查: 第10项,普通 ...

  7. Oracle巡检脚本:ORAWatcher.sh

    Oracle巡检脚本:ORAWatcher.sh #!/usr/bin/ksh echo "" echo "ORAWatcher Version:1.0.1" ...

  8. 解决:/bin/sh: 1: /home/**/custom_app.sh: Permission denied错误

    出现如下错误,一般是执行权限不够. /bin/sh: : /home/custom_app.sh: Permission denied 解决方法是:cd 到此文件目录,对提示的文件赋予可执行权限或读写 ...

  9. SH Script Grammar

    http://linux.about.com/library/cmd/blcmdl1_sh.htm http://pubs.opengroup.org/onlinepubs/9699919799/ut ...

随机推荐

  1. Java基础系列--03_Java中的方法描述

    方法 (1)方法的定义:就是完成特定功能的代码块. 注意:在很多语言里面有函数的定义,而在Java中,函数被称为方法. (2)格式: 修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2 ...

  2. 智表ZCELL产品V1.4.0开发API接口文档 与 产品功能清单

    为了方便大家使用ZCELL,应网友要求,整理编写了相关文档,现与产品一起同步发布,供大家下载使用,使用过程中如有疑问,请与我QQ联系. 智表(ZCELL)V1.4.0版本  功能清单文档下载地址: 功 ...

  3. python开发之路-LuffyCity

    阅读目录 一.python基础语法 二.python基础之字符编码 三.python基础之文件操作 四.python基础小练习 五.python之函数基础 六.python之函数对象.函数嵌套.名称空 ...

  4. Bloom Filter(布隆过滤器)如何解决缓存穿透

    本文摘抄自我的微信公众号"程序员柯南",欢迎关注!原文阅读 缓存穿透是什么? 关于缓存穿透,简单来说就是系统处理了大量不存在的数据查询.正常的使用缓存流程大致是,数据查询先进行缓存 ...

  5. python3.6新特性

    print(f'{6:^30}') print('\n'.join([' '.join([f'{i}*{j}={i*j:2d}' for j in range(1,i+1)]) for i in ra ...

  6. C#关于TreeView树在节点数较多时总是会出现闪烁的问题方法记录

    首先介绍下背景吧,问题如题,这个问题应该说困扰我大半年了(不是说我没有请教大佬,不是说我没有上网查过,之前在搜索时,总是没有解决此问题~~),直到最近一次在在优化代码时,再次上网查找,在发现搜索词条” ...

  7. nodejs部署方式-pm2

    目前Nodejs开发中有很多痛点,其中有一个是修改完代码以后需要我们重启服务才能看到效果.这样一次次的杀进程.重启,杀进程.重启很让人头大.程序员是最痛恨重复工作的物种,之前有了解过的同学可能知道 f ...

  8. MessageDigest类

    public abstract class MessageDigest extends MessageDigestSpi API中的中英文对照简介(未完) java.security.MessageD ...

  9. Django(九)下:Ajax操作、图片验证码、KindEditor使用

    三.Ajax操作 ajax操作基于浏览器的xmlHttpRequest对象,IE低版本是另外一个对象,jQuery 1 版本对那两个对象做了封装,兼容性最好,2 .3版本不再支持IE低版本了. Aja ...

  10. Django(九)上:ModelForm操作

    一.内容回顾 Model - 数据库操作 - 验证 class A(MOdel): user = email = pwd = Form - class LoginForm(Form): email = ...