#!/usr/bin/perl # # Yousef Rabah - April 13th, 2004 # # DisplaySpeech.pm # # Using db.pm, people.pm and DisplaySpeech.pm # # This application contains different scripts that would be # used in other scripts # functions are: # welcome() # - main_menu() # This function displays the menu, depending on what match # it gets back, another script is called that in tern will do: # retrieve by speech, manual search, viewing ADB, or adding user. # This function will start the process of adding # users to database ADB. # - add_user() # All this function will do is take the number and # run it through people.pl script. # search_style() # Function that will prompt user to type whether or not they want # to search by First name or Last name. # Depending on the match, the result will be stored in an external file # that would be used in other scripts. I decided to use this way, because # other scripts would be able to access the string easily rather than prompting # user each time, about the search option # - record_wav() # Calls the record using wav format, it will call this perl scrip that # will record from user's speech using microphone to a .wav format. # - wav_to_raw() # This wav_to_raw file will execute this perl script that in turn would # go in wav directory and then change wav format into .raw format into # another directory called raw_files. # g- et_speech() # This per getSpeech.pl would take the file needed b/c that is the format # that it works with and then exectue the ASR sphinx system to decode # what the user spoke. # - display_speech() # This perl DisplaySpeech.pl file takes in an entry point displaySpeech # which calls multiple files to see whether or not Sphinx made the correct # decode of speech and if so it continues and runs other scripts that # would connect to DB and trys to get back with what the user tried to # search for by first name or last name. # - start_postgreSQL() # This function will start the postgrSQL database. If it is running, # it will display to output saying that the database is already running # - add_string() # Function that would make a new raw file that has a new string and cat it in the older one. # After recording, should see whether or not there is another raw file, # if there is, then add string function would put both raw files together # to run through as one raw file. # Basically, we are always dealing with 2 files, the first one record000.raw which contains current # speech, and record001 that contains the new speech string. This function will take record000.raw # and cat it into the first one record000.raw. # After that is done, the record001.raw and record001.wav will be removed, so that if the user # wanted to add another string it would be saved in record001 and then the process is repeated again. # play_wav() # This simple call will call the record000.wav sound file and play it useing # play function. # ###################################################### package VEPD; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( welcome main_menu add_user search_style record_wav wav_to_raw get_speech display_speech start_postgreSQL add_string play_wav ); use strict; use db; use people; use DisplaySpeech; #XXX need to make main menu function that gives option sub welcome(){ print "***************************************\n"; print "* Welcome to VEPD *\n"; print "* *\n"; print "***************************************\n\n"; print " A Voice Enabled Phone Directory \n\n"; } # This function displays the menu, depending on what match # it gets back, another script is called that in tern will do: # retrieve by speech, manual search, viewing ADB, or adding user. sub main_menu(){ my $input; print "Menu:\n"; print "(A) Add new contact to phone book\n"; print "(R) Record to retrieve contact\n"; print "(M) Manually retrieve contact\n"; print "(V) View ADB\n"; print "(Q) Quit program\n\n"; print "Press letter to begin: "; $input = ; if ($input =~ /^[Aa]/){ add_user(); #fux that will add user } elsif ($input =~ /^[Rr]/){ search_style(); display_speech(); } elsif ($input =~ /^[Mm]/){ #function to do operation manually get_manual(); } elsif ($input =~ /^[Vv]/){ system ("./people.pl view_ADB"); } elsif($input =~ /^[Qq]/){ exit(); } else { exit(); } } # This function will start the process of adding # users to database ADB. # All this function will do is take the number and # run it through people.pl script. sub add_user(){ my $pid; print "\n: Enter People ID (usage: 29): "; $pid = ; chomp ($pid); if ($pid =~ /[0-9]/){ system ("./people.pl insert_to_ADB $pid"); } else { exit(); } } # Function that will prompt user to type whether or not they want # to search by First name or Last name. # Depending on the match, the result will be stored in an external file # that would be used in other scripts. I decided to use this way, because # other scripts would be able to access the string easily rather than prompting # user each time, about the search option sub search_style(){ my $input; my $getChoice; my $choice_file = "/root/perl/choice_result.txt"; ## Getting Info whether user wants to search by First of Last Name print "\n\nSearch by First Name or Last Name? [F or L]: "; $input = ; chomp ($input); if ($input =~ /^[Ff]/){ $getChoice = "getFirstChar"; }elsif ($input =~ /^[Ll]/) { $getChoice = "getLastChar"; } else { $getChoice = "getFirstChar"; print "\nThen Default is by getting First Name \n" } open (OUT, ">$choice_file") || die "cannot create $choice_file: $!"; print OUT $getChoice; close (OUT) || die "cannot close $choice_file: $!"; return ($getChoice); } # Start of postgreSQL ADB sub start_postgreSQL(){ print "ADB: "; system ("/etc/init.d/postgresql start"); print "\n"; } # Function that would make a new raw file that has a new string and cat it in the older one. # After recording, should see whether or not there is another raw file, # if there is, then add string function would put both raw files together # to run through as one raw file. # Basically, we are always dealing with 2 files, the first one record000.raw which contains current # speech, and record001 that contains the new speech string. This function will take record000.raw # and cat it into the first one record000.raw. # After that is done, the record001.raw and record001.wav will be removed, so that if the user # wanted to add another string it would be saved in record001 and then the process is repeated again. sub add_string(){ my $raw_target = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my $wav_target = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $name; my $counter=0; my $catlog = "/root/perl/catlog.txt"; #system ("sox -r 16000 -c 2 -s -w $raw_target/record000.raw $wav_target/record000.wav") # Here if record001.raw exists then, system call will cat new raw file into record000.raw if ("$raw_target/record001.raw"){ system ("cat $raw_target/record001.raw >> $raw_target/record000.raw"); } # Now that we already took the speech out of record001.raw the file will be # removed so that user can add as many strings. system("rm $raw_target/record001.raw"); system("rm $wav_target/record001.wav"); } sub get_manual(){ my $peopleLocation = "/root/perl/./people.pl"; my $input; my $name; print "\nSearch for: \n"; print "(F) First Name \n"; print "(L) Last Name \n"; print "(P) Phone Number \n"; print "(C) City \n"; print ": Press F, L, P, C : "; $input = ; if ($input =~ /^[Ff]/){ print ": Please type name (usage: NAME): "; $name = ; $name =~ tr/a-z/A-Z/; #uppercase everything system ("$peopleLocation getFirstChar $name"); main_menu(); } elsif ($input =~ /^[Ll]/){ print ": Please type name (usage: NAME ): "; $name = ; $name =~ tr/a-z/A-Z/; #uppercase everything system ("$peopleLocation getLastChar $name"); main_menu(); } elsif ($input =~ /^[Pp]/){ print ": Please type phone (usage: 000-000-0000): "; $name = ; system ("$peopleLocation getPhoneChar $name"); main_menu(); } elsif($input =~ /^[Cc]/){ print ": Please type phone (usage: NAME): "; $name = ; $name =~ tr/a-z/A-Z/; #uppercase everything system ("$peopleLocation getCityChar $name"); main_menu(); } else { exit(); } } # Calls the record using wav format, it will call this perl scrip that # will record from user's speech using microphone to a .wav format. sub record_wav(){ # Calls record system file with different options if needed system ("./record_wav.pl"); } # This wav_to_raw file will execute this perl script that in turn would # go in wav directory and then change wav format into .raw format into # another directory called raw_files. sub wav_to_raw(){ # Calls wav_to_raw file using system command and/or with more options if needed system ("./wav_to_raw.pl"); } # This per getSpeech.pl would take the file needed b/c that is the format # that it works with and then exectue the ASR sphinx system to decode # what the user spoke. sub get_speech(){ # calls getSpeech.pl file using system command with or with more options if needed system ("./getSpeech.pl"); } # This perl DisplaySpeech.pl file takes in an entry point displaySpeech # which calls multiple files to see whether or not Sphinx made the correct # decode of speech and if so it continues and runs other scripts that # would connect to DB and trys to get back with what the user tried to # search for by first name or last name. sub display_speech(){ # calls DisplaySpeech.pl file using system command with or with more options if neede. system ("./DisplaySpeech.pl displaySpeech"); } # This simple call will call the record000.wav sound file and play it useing # play function. sub play_wav(){ my $wav_files_directory = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; print "\nYou said:\n" ; system ("play $wav_files_directory/record000.wav"); }