Monday, 25 June 2012

a PRAAT script

You probably have your own routines to check the outliers coming from PRAAT textgrids. I didn't have one so far, so here is a very quick and dirty hack that does the job for me, in case someone would find it useful :


 #visualise_tokens.praat  
   
 #this script could be usefull if you want to inspect particular tokens (e.g. outliers)  
 #export the tokens you want to inspect to a 2 column csv file. col.1 header must be "sound_file" ; col.2 header must be "time_marker"  
 #the script will loop through each wavefile found in col.1 and will move the cursor to the desired time marker found in col.2  
   
 #note that the script can be easily improved by :  
 #1) allowing you to choose whatever col header you want (so that you don't have to name them sound_file and time_marker)  
 #2) doing some IMPORTANT checks!!! Right now it assumes your wavefiles and associated textgrids DO exist and are placed in the same directory  
 #3) allowing you to save the changes you would like to your textgrids  
 #4) predicting the jackpot for the next Big Wednesday lottery (man, how cool would that be?)  
   
 #THIS IS JUST A QUICK AND DIRTY SCRIPT, IT IS PROVIDED FOR VISUALISATION PURPOSES ONLY  
   
 form Arguments  
      comment Give the directory of the sound files:  
      sentence Directory /home/romain/Doctorat/experiences/transfer_of_position/expe_2011/french/data/  
      comment Give the name of the input csv file:  
      word InputFile /home/romain/Desktop/all/outliers.csv  
 endform  
   
 Read Table from comma-separated file... 'InputFile$'  
 Rename... table  
 select Table table  
 numF=Get number of rows  
   
 for i from 1 to 'numF'  
      select Table table  
      fileName$=Get value... i sound_file  
      target=Get value... i time_marker  
      utt$=fileName$-".wav"  
      Read from file... 'directory$''fileName$'  
      pathTG$=directory$+utt$+".TextGrid"  
      Read from file... 'pathTG$'  
      Rename... 'utt$'  
      utt$ = replace$(utt$, " ", "_", 0)  
      select Sound 'utt$'  
      plus TextGrid 'utt$'  
      Edit  
      editor TextGrid 'utt$'  
      Move cursor to... 'target'  
      endeditor  
      pause Click [Continue] to move on to the next soundfile or [Stop] to stop the script  
      select Sound 'utt$'  
      plus TextGrid 'utt$'  
      Remove  
 endfor  
   
 select Table table  
   

Thursday, 23 February 2012

Mount Windows Shares

1. Make sure the smbfs package is installed, if not then install it (under Debian/Ubuntu):

$ sudo apt-get install smbfs


2. Create a directory where you will mount the Windows shares:


$ sudo mkdir /media/mount_point


3. Mount the Windows shares (assuming my username is "abc123" and my password is "passwd"):


$ sudo mount -t cifs  //path_to_the_server -o username=abc123, password=paswd /media/mount_point


Note: In order to have read/write access to the files on the server, access them from your local machine as root.

Thursday, 5 January 2012

Finding files duplicates

One of my all time favourites : fdupes. You have a bunch a files in a directory (and/or sub-directories) and you suspect that some of them have the same content but different filenames. Fdupes will find them and will list them for you (or prompt you to delete them with the -d option).


Syntax : 

fdupes [ options ] DIRECTORY

The -r option will search sub-directories recursively. Look up the MAN page for some other useful options.

Wednesday, 4 January 2012

Exporting a Lattice plot as a grayscale PDF file

Took me a while to figure out how to output a simple grayscale plot using the Lattice package.

A few solutions are provided here : http://stackoverflow.com/questions/3712402/r-how-to-change-lattice-levelplot-color-theme. However, I somehow had troubles using the PDF device in R: the output file was blank. Using the PNG device works fine, but I'd rather have PDF files included in my thesis as I'm working with LaTeX.

The simplest solution was to output a PDF with the basic Lattice code then to use the gs command in bash to convert to grayscale. Job done!


1. Output the plot :
pdf(file='myfile.pdf')
## my lattice plot code
dev.off()


2. Convert to grayscale using gs in bash :
$ gs -sOutputFile=output.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibilityLevel=1.4 myfile.pdf < /dev/null


The result simply looks like this :






Saving a lattice plot with grayscale directly in R can be a bit too tricky, to me this is by far the fastest solution around.