#!/usr/bin/perl
$inp=$ARGV[0];
$out=$ARGV[1];
open(INP,"<$inp");
open(OUT,">$out");
$valid=0;
$sp_text="~h \"sp\"\n<BEGINHMM>\n<NUMSTATES> 3\n";
while(<INP>)
{
$line=$_;
chop($line);
print OUT"$line\n";
if($line =~ /\s*~h\s+\"sil\"\s*/)
{
$valid=1;
}
if ($valid==2)
{
$sp_text=$sp_text.$line."\n";
}
if ($valid==1 && $line =~ /\s*<STATE>\s+3\s*/)
{
$valid=2;
$sp_text=$sp_text."<STATE> 2\n";
}

if($valid ==2 && $line =~ /\s*<GCONST>\s+\S+/)
{
$valid=0;
$sp_text=$sp_text."<TRANSP> 3 \n 0.0 1.0 0.0\n0.0 0.9 0.1\n0.0 0.0 0.0\n<ENDHMM>";
}

}

print OUT"$sp_text";
