File size: 2,748 Bytes
9f1c059 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
#ortho_to_phonetic1
if(scalar(@ARGV)!=3)
{
print " Argument1 --> file for phonetic transcription\n";
print " Argument2 --> phone_list\n";
print " Argument2 --> output file\n";
exit(0);
}
$num_words = scalar(split(/\s+/,cat($ARGV[0])));
$num_phones = scalar(split("\n",cat($ARGV[1])));
$word_start = 1;
open(phn_handle,">",@ARGV[2]);
while($word_start <= $num_words)
{
@temp = split(/\s+/,cat($ARGV[0]));
$word = @temp[$word_start-1];
if($word ne "SIL")
{
$num = length($word);
$phone_start1 = 0;
while($phone_start1 < $num)
{
$p1 = substr($word,$phone_start1,2);
$p2 = substr($word,$phone_start1,3);
$p3 = substr($word,$phone_start1,4);
$p4 = substr($word,$phone_start1,5);
$p5 = substr($word,$phone_start1,6);
$cou = scalar(grep(/\b$p1\b/,cat($ARGV[1])));
$cou1 = scalar(grep(/\b$p2\b/,cat($ARGV[1])));
$cou2 = scalar(grep(/\b$p3\b/,cat($ARGV[1])));
$cou3 = scalar(grep(/\b$p4\b/,cat($ARGV[1])));
$cou4 = scalar(grep(/\b$p5\b/,cat($ARGV[1])));
if($cou4 ==1)
{
print phn_handle $p5."\n";
$phone_start1 = $phone_start1 + 6;
}
elsif($cou3 ==1)
{
print phn_handle $p4."\n";
$phone_start1 = $phone_start1 + 5;
}
elsif($cou2 ==1)
{
print phn_handle $p3."\n";
$phone_start1 = $phone_start1 + 4;
}
elsif($cou1==1)
{
print phn_handle $p2."\n";
$phone_start1 = $phone_start1 + 3;
}
elsif($cou==1)
{
print phn_handle $p1."\n";
$phone_start1 = $phone_start1 + 2;
}
else
{
$p1 = substr($word,$phone_start1,1);
if($p1 eq ",")
{
$phone_start1++
}
elsif ($p1 eq ".")
{
$phone_start1++
}
else
{
print phn_handle $p1."\n";
$phone_start1++
}
}
}
}
else
{
print phn_handle "SIL\n";
break;
}
$word_start++;
}
close(phn_handle);
sub cat
{
$val="";
$file = $_[0];
open (input, "<",$file) ||die;
while(<input>)
{
$val.="$_";
}
return $val;
close (input);
}
sub head
{
$text_head="";
@text_h_split = split("\n",$_[0]);
$line_h = $_[1];
$i =0;
while($i < $line_h)
{
if($i < $line_h-1)
{
$text_head.="$text_h_split[$i]\n";
}
elsif($i == $line_h-1)
{
$text_head.="$text_h_split[$i]";
}
$i++;
}
return $text_head;
}
sub tail
{
$text_tail="";
@text_t_split = split("\n",$_[0]);
$line_t = $_[1];
$total = scalar(@text_t_split);
$start_t = $total - $line_t;
while($start_t <$total)
{
if($start_t<$total-1)
{
$text_tail.="$text_t_split[$start_t]\n";
}
elsif($start_t==$total-1)
{
$text_tail.="$text_t_split[$start_t]";
}
$start_t++;
}
return $text_tail;
}
|