diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-10-17 19:44:46 +0100 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-10-17 19:44:46 +0100 |
commit | 010020d4a48c722d12b00cade0295c7f7766da35 (patch) | |
tree | 5fafa717847320a7f4314b68dfb1df55649b4199 | |
parent | 05481f400bbf2318d13ad7eb2f8b87242ece3eaa (diff) | |
download | speech-010020d4a48c722d12b00cade0295c7f7766da35.tar.gz speech-010020d4a48c722d12b00cade0295c7f7766da35.tar.bz2 speech-010020d4a48c722d12b00cade0295c7f7766da35.zip |
prettify and comment process.pl
-rwxr-xr-x | process.pl | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -6,12 +6,16 @@ use JSON::MaybeXS; use File::Slurp; use Data::Dumper; -our $found; +my $found; my $json_input = read_file( "./jaroutput.txt" ) ; $json_input =~ s/.+//; + +# Quit if there is not text rurned from google api if($json_input eq "\n"){ system "./tts.sh 'Excuse me?'; exit;";} + my $data_structure = decode_json($json_input); +# Unpack the JSON my %data=%{$data_structure}; my $in=$data{'result'}; my @data2=@{$in}; @@ -21,16 +25,20 @@ my @data3=@{$in2}; my %transcript; my $i=0; -foreach(@data3){ -my %temp=%{$data3[$i]}; -if(!$found){ - check($temp{transcript}); #magic line -} -$i++; +# For each result check regex until a match is found +foreach(@data3){ + my %temp=%{$data3[$i]}; + + if(!$found){ + check($temp{transcript}); #magic line + } + + $i++; } +# If no match is found ask Wolfram alpha for help 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}\""; |