#!/usr/bin/perl # FORM2 2 Praat # # This scripts takes a .form2 file as an arugment # and converts it to the .praat file format for display # in the Praat speech analysis tool. # # Chris Osborn # cosborn@ldc.upenn.edu # # FORM Project, Linguistic Data Consortium # University of Pennsylvania # # http://www.ldc.upenn.edu/Projects/FORM/ # foreach $file (@ARGV){ $columns = 10; $rightRows = 0; $leftRows = 0; $outFileRight = $file; $outFileLeft = $file; $outFileRight =~ s/.form2/Right\.praat/g; $outFileLeft =~ s/.form2/Left\.praat/g; open(FILE, "./$file"); open(OUTR, ">./$outFileRight"); open(OUTL, ">./$outFileLeft"); while(){ if($_ =~ /^\#.*?\.form2/){ ($newName) = ($_ =~ /\#(.*?)\.form2/); } if($_ =~ /Right/){$arm = 0;} elsif($_ =~ /Left/){$arm = 1;} if($_ =~ /^\d/){ ($frame, $x, $y, $z, $lift, $orientation, $shape, $wristUpDown, $wristSideSide, $effort, $tension) = ($_ =~ /^(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?),(.*?)$/); if(($x ne "")&&($y ne "")&&($x ne "")&&($lift ne "")&&($orientation ne "")&&($shape ne "")&&($wristUpDown ne "")&&($wristSideSide ne "")&&($effort ne "")&&($tension ne "")){ if($arm == 0){ $lineHashRight{$frame}{"x"} = $x; $lineHashRight{$frame}{"y"} = $y; $lineHashRight{$frame}{"z"} = $z; $lineHashRight{$frame}{"lift"} = $lift; $lineHashRight{$frame}{"orientation"} = $orientation; $lineHashRight{$frame}{"shape"} = $shape; $lineHashRight{$frame}{"wristUpDown"} = $wristUpDown; $lineHashRight{$frame}{"wristSideSide"} = $wristSideSide; $lineHashRight{$frame}{"effort"} = $effort; $lineHashRight{$frame}{"tension"} = $tension; $rightRows = $rightRows + 1; } else{ $lineHashLeft{$frame}{"x"} = $x; $lineHashLeft{$frame}{"y"} = $y; $lineHashLeft{$frame}{"z"} = $z; $lineHashLeft{$frame}{"lift"} = $lift; $lineHashLeft{$frame}{"orientation"} = $orientation; $lineHashLeft{$frame}{"shape"} = $shape; $lineHashLeft{$frame}{"wristUpDown"} = $wristUpDown; $lineHashLeft{$frame}{"wristSideSide"} = $wristSideSide; $lineHashLeft{$frame}{"effort"} = $effort; $lineHashLeft{$frame}{"tension"} = $tension; $leftRows = $leftRows + 1; } } } } close(FILE); print OUTR "\"ooTextFile\"\n"; print OUTR "\"TableOfReal\"\n"; print OUTR "$columns \"x\" \"y\" \"z\" \"lift\" \"orientation\" \"shape\" \"wristUpDown\" \"wristSideSide\" \"effort\" \"tension\"\n"; print OUTR "$rightRows\n"; foreach $frame (sort {$a <=> $b} keys %lineHashRight){ $tempX = $lineHashRight{$frame}{"x"}; $tempY = $lineHashRight{$frame}{"y"}; $tempZ = $lineHashRight{$frame}{"z"}; $tempLift = $lineHashRight{$frame}{"lift"}; $tempOrientation = $lineHashRight{$frame}{"orientation"}; $tempShape = $lineHashRight{$frame}{"shape"}; $tempWristUpDown = $lineHashRight{$frame}{"wristUpDown"}; $tempWristSideSide = $lineHashRight{$frame}{"wristSideSide"}; $tempEffort = $lineHashRight{$frame}{"effort"}; $tempTension = $lineHashRight{$frame}{"tension"}; if(($tempX ne "")&&($tempY ne "")&&($tempZ ne "")&&($tempLift ne "")&&($tempOrientation ne "")&&($tempShape ne "")&&($tempWristUpDown ne "")&&($tempWristSideSide ne "")&&($tempEffort ne "")&&($tempTension ne "")){ print OUTR "\"$frame\" $tempX $tempY $tempZ $tempLift $tempOrientation $tempShape $tempWristUpDown $tempWristSideSide $tempEffort $tempTension\n"; } else{ $rightRows = $rightRows - 1; } } print OUTL "\"ooTextFile\"\n"; print OUTL "\"TableOfReal\"\n"; print OUTL "$columns \"x\" \"y\" \"z\" \"lift\" \"orientation\" \"shape\" \"wristUpDown\" \"wristSideSide\" \"effort\" \"tension\"\n"; print OUTL "$leftRows\n"; foreach $frame (sort {$a <=> $b} keys %lineHashLeft){ $tempX = $lineHashLeft{$frame}{"x"}; $tempY = $lineHashLeft{$frame}{"y"}; $tempZ = $lineHashLeft{$frame}{"z"}; $tempLift = $lineHashLeft{$frame}{"lift"}; $tempOrientation = $lineHashLeft{$frame}{"orientation"}; $tempShape = $lineHashLeft{$frame}{"shape"}; $tempWristUpDown = $lineHashLeft{$frame}{"wristUpDown"}; $tempWristSideSide = $lineHashLeft{$frame}{"wristSideSide"}; $tempEffort = $lineHashLeft{$frame}{"effort"}; $tempTension = $lineHashLeft{$frame}{"tension"}; if(($tempX ne "")&&($tempY ne "")&&($tempZ ne "")&&($tempLift ne "")&&($tempOrientation ne "")&&($tempShape ne "")&&($tempWristUpDown ne "")&&($tempWristSideSide ne "")&&($tempEffort ne "")&&($tempTension ne "")){ print OUTL "\"$frame\" $tempX $tempY $tempZ $tempLift $tempOrientation $tempShape $tempWristUpDown $tempWristSideSide $tempEffort $tempTension\n"; } else{ $leftRows = $leftRows - 1; } } close(OUTR); close(OUTL); }