#!/bin/csh
# -----------------------------------------------------------------------
# Name   : SUSAS_Labeling
#
# Purpose: A script to create the label files of SUSAS database by using 
#          Duke University Speech Time-Aligner (DUST) which is developed  
#          for continuous speech segmentation. The directory structure of 
#          label files will be the exact mirror image of directory 
#          structure of SUSAS speech files. The label files will be composed 
#          of the speech file name followed by a ".lab" extension. 
#
#          The user should set the "ROOT" variable (first line) below to
#          be the root path of the SUSAS database. 
#       
#          The user wishing to use another aligner should modify only 
#          the three lines labeled as "LINE 1, LINE 2, LINE 3" below.
#          DUST receives only three parameters: (1) text transcription 
#          of the speech file, (2) The label file, (3) The Speech waveform.
#              
#          Reference: B. Pellom and J.H.L. Hansen, "Automatic Segmentation
#          and Labeling of Speech Recorded in Unknown Channel Environments,"
#          ESCA-NATO Workshop on Robust Speech Recognition in Unknown Communication
#          Channels, pp. 167-170, Pont-a-Mousson, France, April 1997.  
#
# -----------------------------------------------------------------------
#          Duke University 
#          Robust Speech Processing Laboratory
#          Durham, NC 27708-0291
#           
#          Ruhi Sarikaya ( ruhi@ee.duke.edu )
#          Created : November 10, 1997
# -----------------------------------------------------------------------

# default parameters and paths

set ROOT="/auto/home/speech"

set DATABASEDIR = {$ROOT}/SUSAS
set SUSASLABELDIR="/auto/home/speech8/SUSAS_labs"

set Major_Directories = ( sim  actual )


# SIMULATED STRESS LABELING


set Sim_SubDir_Lev1 = `echo boston1 boston2 boston3 general1 general2 general3 nyc1 nyc2 nyc3` 
set Sim_SubDir_Lev2 = `echo angry clear cond50 cond70 fast lombard loud neutral question slow soft train` 

set Sim_Ext_List = ( a c c5 c7 f lom l n q s w t )

set LabelTextFileList = `echo break change degree destin  east eight eighty enter fifty fix freeze gain go hello help histog hot mark nav no oh on out  point six south stand steer strafe ten thirty three white wide zero`

mkdir $SUSASLABELDIR/$Major_Directories[1]
mkdir $SUSASLABELDIR/TempTextDir
cd $SUSASLABELDIR/TempTextDir

set j = 1
while ($j <= ${#LabelTextFileList} )	
	
	if ($LabelTextFileList[$j] == "histog" ) then
		echo "\!"sil  histogram "\!"sil > histog.tex
	else if ($LabelTextFileList[$j] == "destin" ) then
		echo "\!"sil  destination "\!"sil > destin.tex
	else
		echo "\!"sil  $LabelTextFileList[$j] "\!"sil  > ${LabelTextFileList[$j]}\.tex
	endif
	
	@ j++
end

# It is assumed that label phone-text file has the same name as the 
# Word name with "tex" extension

setenv DUST_USER /home/speech2/ruhi/DUST_test/mydict
set j = 1
while ($j <= ${#Sim_SubDir_Lev1})
     set Speaker = $Sim_SubDir_Lev1[$j]
     mkdir $SUSASLABELDIR/$Major_Directories[1]/$Speaker
     set k = 1 
     while ($k <= ${#Sim_SubDir_Lev2} ) 
        set Stress = $Sim_SubDir_Lev2[$k]
        set Ext = $Sim_Ext_List[$k]
        mkdir $SUSASLABELDIR/$Major_Directories[1]/$Speaker/$Stress
        if ($Stress == train ) then
	   set IndexToGivenWord = ( 1 2 3 4 5 6 7 8 9 10 11 12 )
        else
	   set IndexToGivenWord  = ( 1 2 )
        endif 
        set  ActiveDir =  $DATABASEDIR/$Major_Directories[1]/$Speaker/$Stress 
        set m = 1
        while ($m <= ${#LabelTextFileList} )
	   set Word = $LabelTextFileList[$m]        
	   foreach WordIndex ($IndexToGivenWord)
	       set tempdat = $Word$WordIndex\.$Speaker$Ext

# LINE 1
	       dust -t $SUSASLABELDIR/TempTextDir/$LabelTextFileList[$m]\.tex -op $SUSASLABELDIR/$Major_Directories[1]/$Speaker/$Stress/$tempdat\.lab  -gm $ActiveDir/$tempdat	




	   end
	   @ m++
        end
        @ k++
     end
     @ j++
end


# ACTUAL STRESS LABELING

set Act_SubDir_Lev1 = `echo f1 f2 f3 m1 m2 m3 m4 m5`
set Act_SubDir_Lev2 = `echo freefall ff_oov_All hist hist_oov_All medst medst_oov_All neutral neutral_oov_All scream  sm_oov_All`

mkdir $SUSASLABELDIR/$Major_Directories[2]
foreach Level1 ( $Act_SubDir_Lev1 )
    mkdir $SUSASLABELDIR/$Major_Directories[2]/$Level1
    foreach Level2 ( $Act_SubDir_Lev2 )
       mkdir $SUSASLABELDIR/$Major_Directories[2]/$Level1/$Level2 
       foreach Word ( $LabelTextFileList )
          cd $DATABASEDIR/$Major_Directories[2]/$Level1/$Level2
          foreach token (`ls {$Word}?.*`)
             
# LINE 2	

		  dust -t $SUSASLABELDIR/TempTextDir/$Word\.tex -op $SUSASLABELDIR/$Major_Directories[2]/$Level1/$Level2/$token\.lab  -gm $DATABASEDIR/$Major_Directories[2]/$Level1/$Level2/$token
          


	  end
          foreach token (`ls {$Word}??.*`)
               

# LINE 3
			dust -t $SUSASLABELDIR/TempTextDir/$Word\.tex -op $SUSASLABELDIR/$Major_Directories[2]/$Level1/$Level2/$token\.lab  -gm $DATABASEDIR/$Major_Directories[2]/$Level1/$Level2/$token
         


	  end
       end
    end
end


cd $SUSASLABELDIR/TempTextDir
rm *\.tex
cd  $SUSASLABELDIR
rmdir $SUSASLABELDIR/TempTextDir














