Commit 7047c622 authored by Jan Trmal's avatar Jan Trmal
Browse files

(trunk/egs/babel) Adding scripts for conversion from kaldi ali directory to NIST rttm file

git-svn-id: https://svn.code.sf.net/p/kaldi/code/trunk@5181 5e6a8d80-dfce-4ca6-a32a-6e07a63d50c8
parent 3cdbab99
#!/bin/bash
# Copyright 2012-2013 Johns Hopkins University (Author: Guoguo Chen, Yenda Trmal)
# Apache 2.0.
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
# WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
# MERCHANTABLITY OR NON-INFRINGEMENT.
# See the Apache 2 License for the specific language governing permissions and
# limitations under the License.
#This script will take the ali directory andcreate the corresponding rttm file
#Example
#steps/align_sgmm2.sh --nj 20 --cmd "$decode_cmd" \
# --transform-dir exp/tri5/decode_dev2h.uem \
# data/dev2h.uem data/lang exp/sgmm5 exp/sgmm5/align_dev2h.uem
#local/ali_to_rttm.sh data/dev2h data/lang exp/sgmm5/align_dev2h/
cmd=run.pl
scale_opts="--transition-scale=1.0 --acoustic-scale=0.1 --self-loop-scale=0.1"
beam=10
retry_beam=40
boost_silence=1.0
if [ -f path.sh ]; then . path.sh; fi
. parse_options.sh || exit 1;
if [ $# != 3 ]; then
echo "This script takes an ali directory and creates the corresponding RTTM file"
echo ""
echo "Usage: align_text.sh <data-dir> <lang-dir> <exp-dir>"
echo " e.g.: align_text.sh data/heldout data/lang exp/heldout_ali"
echo "main options (for others, see top of script file)"
echo " --cmd (utils/run.pl|utils/queue.pl <queue opts>) "
exit 1;
fi
set -e
set -o pipefail
set -u
data=$1
lang=$2
dir=$3
oov=`cat $lang/oov.txt`
mkdir -p $dir/log
echo "$0: writing alignments."
wbegin=`grep "#1" $lang/phones.txt | head -1 | awk '{print $2}'`
wend=`grep "#2" $lang/phones.txt | head -1 | awk '{print $2}'`
if [ ! -f $lang/L_align.fst ]; then
echo "$0: generating $lang/L_align.fst"
local/make_L_align.sh data/local/tmp.lang/ $lang $lang 2>&1 | tee $dir/log/L_align.log
fi
$cmd $dir/log/align_to_words.log \
ali-to-phones $dir/final.mdl "ark:gunzip -c $dir/ali.*.gz|" ark,t:- \| \
phones-to-prons $lang/L_align.fst $wbegin $wend ark:- "ark,s:utils/sym2int.pl -f 2- --map-oov '$oov' $lang/words.txt <$data/text|" ark,t:- \| \
prons-to-wordali ark:- "ark:ali-to-phones --write-lengths=true $dir/final.mdl 'ark:gunzip -c $dir/ali.*.gz|' ark,t:- |" ark,t:$dir/align.txt
echo "$0: done writing alignments."
echo "$0: writing rttm."
[ ! -x local/txt_to_rttm.pl ] && \
echo "Not creating rttm because local/txt2rttm.pl does not exist or not executable." && exit 1;
local/txt_to_rttm.pl --symtab=$lang/words.txt --segment=$data/segments $dir/align.txt $dir/rttm 2>$dir/log/rttm.log
echo "$0: done writing rttm."
exit 0;
#!/bin/bash
# Copyright 2013 Johns Hopkins University (authors: Guoguo Chen, Yenda Trmal)
# 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
#
# THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
# WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
# MERCHANTABLITY OR NON-INFRINGEMENT.
# See the Apache 2 License for the specific language governing permissions and
# limitations under the License.
set -o pipefail
set -e
if [ $# -ne 3 ]; then
echo "This is a simple script that will generate the L_align.fst"
echo "The FST L_align.fst is used for getting the force-aligned "
echo "utterances"
echo "The script automaticky recognizes the probabilistic lexicon"
echo "is used and will use the correct file"
echo ""
echo "usage: local/L_align.sh <lang-local-dir> <lang-dir> <out-dir>"
echo "e.g.: local/L_align.sh data/local/lang data/lang data/lang"
exit 1;
fi
tmpdir=$1
dir=$2
outdir=$3
silphone=`cat $dir/phones/optional_silence.txt` || exit 1;
# Create lexicon with alignment info
if [ -f $tmpdir/lexicon.txt ] ; then
cat $tmpdir/lexicon.txt | \
awk '{printf("%s #1 ", $1); for (n=2; n <= NF; n++) { printf("%s ", $n); } print "#2"; }'
elif [ -f $tmpdir/lexiconp.txt ] ; then
cat $tmpdir/lexiconp.txt | \
awk '{printf("%s #1 ", $1); for (n=3; n <= NF; n++) { printf("%s ", $n); } print "#2"; }'
else
echo "Neither $tmpdir/lexicon.txt nor $tmpdir/lexiconp.txt does not exist"
exit 1
fi | utils/make_lexicon_fst.pl - 0.5 $silphone | \
fstcompile --isymbols=$dir/phones.txt --osymbols=$dir/words.txt \
--keep_isymbols=false --keep_osymbols=false | \
fstarcsort --sort_type=olabel > $outdir/L_align.fst
exit 0;
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my $Usage = <<EOU;
Usage: txt2rttm.pl [options] <txt_in|-> <rttm_out|->
Allowed options:
--flen : Frame length (float, default = 0.1)
--symtab : Symbol table (string, default = "")
--segment : Segment file from Kaldi (string, default = "")
EOU
my $symtab = "";
my $segment = "";
my $flen = 0.01;
GetOptions('symtab=s' => \$symtab,
'segment=s' => \$segment,
'flen=f' => \$flen);
if ($symtab) {
if (!open(S, "<$symtab")) {print "Fail to open symbol table: $symtab\n"; exit 1;}
}
if ($segment) {
if (!open(SEG, "<$segment")) {print "Fail to open segment file: $segment\n"; exit 1;}
}
if(@ARGV != 2) {
die $Usage;
}
# Get parameters
my $filein = shift @ARGV;
my $fileout = shift @ARGV;
# Get input source
my $source = "";
if ($filein eq "-") {
$source = "STDIN";
} else {
if (!open(I, "<$filein")) {print "Fail to open input file: $filein\n"; exit 1;}
$source = "I";
}
# Open output fst list
my $sourceout = "";
if ($fileout ne "-") {
if (!open(O, ">$fileout")) {print "Fail to open output file: $fileout\n"; exit 1;}
$sourceout = "O";
}
# Get symbol table and start time
my %sym = ();
my %tbeg = ();
my %uid2utt = ();
if ($symtab) {
while(<S>) {
chomp;
my @col = split(" ", $_);
@col == 2 || die "Bad number of columns in $symtab\n";
$sym{$col[1]} = $col[0];
}
}
if ($segment) {
while(<SEG>) {
chomp;
my @col = split(" ", $_);
@col == 4 || die "Bad number of columns in $segment\n";
$tbeg{$col[0]} = $col[2];
$uid2utt{$col[0]} = $col[1];
}
}
# Processing
while (<$source>) {
chomp;
my @col = split(" ", $_);
my $uid = shift @col;
my $words = join(" ", @col);
@col = split(/;/, $words);
my $utt = $uid;
my $sta = 0;
if ($segment) {
$utt = $uid2utt{$uid};
$sta = $tbeg{$uid};
}
foreach (@col) {
my @subcol = split(" ", $_);
@subcol == 2 || die "Bad number of columns in word-frame pair\n";
my $word = $subcol[0];
my $dur = $subcol[1]*$flen;
my $lex = "LEXEME";
if ($symtab) {$word = $sym{$word};}
if ($word =~ m/^<.*>$/) {$lex = "NON-LEX";}
eval "print $sourceout \"$lex $utt 1 $sta $dur $word <NA> <NA> <NA>\n\"";
$sta += $dur;
}
}
if ($symtab) {close(S);}
if ($segment) {close(SEG);}
if ($filein ne "-") {close(I);}
if ($fileout ne "-") {close(O);}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment