#!/usr/bin/perl # Converts intermediate transition-model format into Kaldi "topology" format (where # the transitions become the "default" transition values in the topology; when we # initialize the actual transition-model these will be used... print "\n"; while(<>) { if(m/\ (\S+) (\d+)/) { $phone = $1; $numstates = $2; # Normally 5. Two are dummy states. print " $phone \n"; for($n = 1; $n <= $numstates; $n++) { $l = <>; @A = split(" ", $l); @A == $numstates || die "Bad line $l: line $."; if($n == 1) { if($A[1] != 1.0) { print STDERR "Warning: phone $phone seems not to be normal topology: result may not be correct.\n"; } } else { $nm2 = $n-2; # Kaldi-numbered state, 2 less than HTK one. if($n < $numstates) { print " $nm2 $nm2\n"; } else { print " $nm2\n"; } # The next few lines are just a sanity check-- that we have the "normal" topology. for($p = 0; $p < $numstates; $p++) { if($A[$p] != 0) { $deststate = $p-1; # in kaldi numbering. print " $deststate $A[$p]\n"; } } print " \n"; } } print "\n"; } else { die "Bad line $_: line $.\n"; } } print "\n";