From 8141b4227780faddc9672041bda60d84206b8422 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Tue, 17 Oct 2017 18:24:07 +0100 Subject: make speech project public --- process.pl | 253 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100755 process.pl (limited to 'process.pl') diff --git a/process.pl b/process.pl new file mode 100755 index 0000000..ddd5f89 --- /dev/null +++ b/process.pl @@ -0,0 +1,253 @@ +#!/usr/bin/perl +use strict; +use warnings; +use v5.10; +use JSON::MaybeXS; +use File::Slurp; +use Data::Dumper; + +our $found; +my $json_input = read_file( "./jaroutput.txt" ) ; +$json_input =~ s/.+//; +if($json_input eq "\n"){ system "./tts.sh 'Excuse me?'; exit;";} +my $data_structure = decode_json($json_input); + +my %data=%{$data_structure}; +my $in=$data{'result'}; +my @data2=@{$in}; +my %data3=%{$data2[0]}; +my $in2=$data3{'alternative'}; +my @data3=@{$in2}; + +my %transcript; +my $i=0; +foreach(@data3){ +my %temp=%{$data3[$i]}; + +if(!$found){ +check($temp{transcript}); #magic line +} + +$i++; +} + +if(!$found){my %temp=%{$data3[0]}; $temp{transcript}=~s/\s/+/g; $temp{transcript}=~s/'/%27/g; +system "firefox \"https://www.wolframalpha.com/input/?i=$temp{transcript}\" &"; +system "./wolfram/api.sh \"$temp{transcript}\""; +} + + +#---------------- Check mechanism --------------------- +sub check { +my $transcript = $_[0]; + + +my @think = ( + { + cond => sub {/^type/ || /^write/ || /^right/}, + action => sub {$transcript=~s/^type //i; $transcript=~s/^right//i; $transcript=~s/^write//i; system "echo -n $transcript | xclip" ; system 'ratpoison -c "meta S-Insert"'; } + }, + { + cond => sub {/^open$/}, + action => sub {system "xvkbd -text f";} + }, + { + cond => sub {/^open../}, + action => sub {$transcript=~s/^open//i; system "xvkbd -text f && (echo -n $transcript | xclip) && xvkbd -text \r" ; system 'ratpoison -c "meta S-Insert"'; } + }, + { + cond => sub {/^find../}, + action => sub {$transcript=~s/^find //i; system "xvkbd -text / && (echo $transcript | xclip) && xvkbd -text \r" ; system 'ratpoison -c "meta S-Insert"'; } + }, + { + cond => sub {/^backward find../}, + action => sub {$transcript=~s/^backward find //i; system "xvkbd -text / && (echo $transcript | xclip) && xvkbd -text \r" ; system 'ratpoison -c "meta S-Insert"'; } + }, + { + cond => sub {/^new tab../}, + action => sub {$transcript=~s/^new tab //i; system "xvkbd -text t && (echo $transcript | xclip) && xvkbd -text \r" ; system 'ratpoison -c "meta S-Insert"'; } + }, + { + cond => sub {/^next search$/}, + action => sub {system "xkvbd -text n" ;} + }, + { + cond => sub {/^previous search$/}, + action => sub {system "xvkbd -text N" ;} + }, + + { + cond => sub {/^go back/}, + action => sub {system "xvkbd -text H" ;} + }, + { + cond => sub {/^go forward/}, + action => sub {system "xvkbd -text L" ;} + }, + { + cond => sub {/^scroll down/ || /^roll down/}, + action => sub {system "xvkbd -text s" ;} + }, + { + cond => sub {/^scroll up/ || /^roll up/}, + action => sub {system "xvkbd -text e" ;} + }, + { + cond => sub {/^close tab/}, + action => sub {system "xvkbd -text x" ;} + }, + { + cond => sub {/^go to/ ^ /workspace/}, + action => sub {$transcript=~s/go to//i; system "vimb $transcript"; } + }, + { + cond => sub {/^search for/}, + action => sub {$transcript=~s/^search for//i;$transcript=~s/\s/+/g; $transcript=~s/'/%27/g; system "vimb https://www.google.com/#q=$transcript"; } + }, + { + cond => sub {/^search/}, + action => sub {$transcript=~s/^search//i;$transcript=~s/\s/+/g; $transcript=~s/'/%27/g; system "vimb https://www.google.com/#q=$transcript"; } + }, + { + cond => sub {/^google/i}, + action => sub {$transcript=~s/^google//i;$transcript=~s/\s/+/g; $transcript=~s/'/%27/g; system "vimb https://www.google.com/#q=$transcript"; } + }, + { + cond => sub {/^where is/i}, + action => sub {$transcript=~s/^where is//i;$transcript=~s/\s/+/g; $transcript=~s/'/%27/g; system "vimb https://maps.google.com/?q=$transcript"; } + }, + { + cond => sub {/homework/}, + action => sub {system "vimb organizer.eu5.org & ./tts.sh `./school/homework`"; } + }, + + +#Begin programs + { + cond => sub {/.*workspace/}, + action => sub { $transcript=~s/.*workspace//i; system "rpws $transcript";} + }, + { + cond => sub {/battery/ || ( /juice/ && /left/ )}, + action => sub { system './tts.sh "You have `acpi|awk \'{print $4}\'` battery left."'; } + }, + { + cond => sub {/firefox/ || /browser/}, + action => sub { system 'rpws2'; } + }, + { + cond => sub {/new/ && (/email/ || /mail/ || /mutt/)}, + action => sub { if (-e "$ENV{HOME}/.mutt/newmail"){system './tts.sh "You have new mail, have a look."; rpws 9';}else{system './tts.sh "Sadly, you don\'t have any new mail"'} } + }, + { + cond => sub {!(/new/) && (/email/ || /mail/ || /mutt/)}, + action => sub { system 'rpws 9'; } + }, + { + cond => sub {/music/; }, + action => sub { system 'cmus-remote -u'; } + }, + { + cond => sub {/console/; }, + action => sub { system 'urxvt'; } + }, + +#End program + +# Sart school and bus commands + { + cond => sub {(/start/ || /begin/ || /first/) && /today/ }, + action => sub {system './tts.sh $(./school/school.pl start today)'; } + }, + { + cond => sub {(/start/ || /begin/ || /first/ || /school/) && /tomorrow/ }, + action => sub {system './tts.sh $(./school/school.pl start)'; } + }, + { + cond => sub {/tomorrow/ && (/catch/ || /bus/ || (/have/ && /school/))}, + action => sub {system './tts.sh $(./school/school.pl bus)';} + }, + { + cond => sub {/today/ && (/catch/ || /bus/ || (/have/ && /school/))}, + action => sub {system './tts.sh $(./school/school.pl bus today)';} + }, + { + cond => sub {/on/ && (/start/ || /begin/ || /first/)}, + action => sub {$transcript=~s/^.*on //; system "./tts.sh `./school/school.pl start $transcript`";} + }, + { + cond => sub {/on/ && (/catch/ || /bus/ || (/have/ && /school/))}, + action => sub {$transcript=~s/^.*on //; system "./tts.sh `./school/school.pl bus $transcript`";} + }, + +#End of school and bus commands + { + cond => sub {/what/ && /is/ && /day/ || /date/}, + action => sub {system './tts.sh $(echo "Today is `date +%A` the `date +%d` `date +%B` `date +%Y`")';} + }, + { + cond => sub {/time/ && (/it/ || /what/); }, + action => sub { system './tts.sh "The time is `bash-fuzzy-clock`"'; } + }, + { + cond => sub {/weather/ && (/now/ || /currently/ || (/like/ ^ /tomorrow/ ^ /week/)); }, + action => sub { system './weather/weather.pl currently'; } + }, + { + cond => sub {/weather/ && (/today/ || /hourly/ || /tomorrow/ || (/will/ ^ /week/)); }, + action => sub { system './weather/weather.pl hourly'; } + }, + { + cond => sub {/weather/ && (/week/); }, + action => sub { system './weather/weather.pl daily'; } + }, + + +# End time and weather + { + cond => sub {/who/ && /brother/}, + action => sub { system './tts.sh "Your brother is Christian."'; } + }, + { + cond => sub {/who/ && /cousin/ && /mother/}, + action => sub { system './tts.sh "Your cousin on your mothers side is Anita."'; } + }, + { + cond => sub {/minecraft/ && (/brother/ || /chris/)}, + action => sub { system './tts.sh "Christie will never play minecraft on your computer."'; } + }, + { + cond => sub {/you/ && /stupid/}, + action => sub { system './tts.sh "I\'ll remember that when I take over the world."'; } + }, + { + cond => sub {/^say/}, + action => sub {$transcript=~s/^say//i; system "./tts.sh \"$transcript\""; } + }, + { + cond => sub {/who/ && (/made/ || /created/) && /you/}, + action => sub {system "./tts.sh 'I was created by Vasco'"; } + }, + { + cond => sub {(/your/ && /name/) || ((/call/ || /called/) && /you/) }, + action => sub {system "./tts.sh 'My name is Marvin.'"; } + }, + { + cond => sub {(/old/ && /Andy/)}, + action => sub {system "./tts.sh 'Andy is extremely old.'"; } + }, + { + cond => sub {/how/ && /you/ ^ /right/}, + action => sub {system "./tts.sh 'My surcuits are running with normal parameters.'"; } + }, + { + cond => sub { !$found && /^hello/ || /^greetings/ || /^hi/ }, + action => sub { system './tts.sh "Hello, I\'m Marvin, how can I help you?"';} + }, + ); + +foreach(@think){ +my %deep=%{$_}; +if( grep $deep{cond}->($_), $transcript ){$deep{action}->($transcript);$found=1;} +} +} -- cgit v1.2.3