diff options
author | Vasil Zlatanov <v@skozl.com> | 2017-10-17 18:24:07 +0100 |
---|---|---|
committer | Vasil Zlatanov <v@skozl.com> | 2017-10-17 18:24:07 +0100 |
commit | 8141b4227780faddc9672041bda60d84206b8422 (patch) | |
tree | 10b8894b9718b5642baf08b66faad9b67a662042 | |
download | speech-8141b4227780faddc9672041bda60d84206b8422.tar.gz speech-8141b4227780faddc9672041bda60d84206b8422.tar.bz2 speech-8141b4227780faddc9672041bda60d84206b8422.zip |
make speech project public
-rwxr-xr-x | api2.sh | 6 | ||||
-rwxr-xr-x | process.pl | 253 | ||||
-rwxr-xr-x | run.sh | 7 | ||||
-rwxr-xr-x | tts.sh | 2 | ||||
-rw-r--r-- | weather/.api.sh.un~ | bin | 0 -> 1479 bytes | |||
-rw-r--r-- | weather/.test.perl.un~ | bin | 0 -> 9295 bytes | |||
-rw-r--r-- | weather/.test.pl.un~ | bin | 0 -> 14600 bytes | |||
-rw-r--r-- | weather/.weather.pl.un~ | bin | 0 -> 67098 bytes | |||
-rwxr-xr-x | weather/weather.pl | 37 | ||||
-rw-r--r-- | wolfram/.api-old.sh.un~ | bin | 0 -> 705 bytes | |||
-rw-r--r-- | wolfram/.api.sh.un~ | bin | 0 -> 3520 bytes | |||
-rw-r--r-- | wolfram/.wolf.p6.un~ | bin | 0 -> 18707 bytes | |||
-rw-r--r-- | wolfram/.wolf.un~ | bin | 0 -> 6458 bytes | |||
-rw-r--r-- | wolfram/.wolfram.sh.un~ | bin | 0 -> 60875 bytes | |||
-rw-r--r-- | wolfram/api-perl6.sh | 6 | ||||
-rwxr-xr-x | wolfram/api.sh | 7 | ||||
-rw-r--r-- | wolfram/api.sync-conflict-20150502-090303.sh | 7 | ||||
-rw-r--r-- | wolfram/api.sync-conflict-20150615-220742.sh | 7 | ||||
-rw-r--r-- | wolfram/example-result.xml | 64 | ||||
-rw-r--r-- | wolfram/example2-result.xml | 64 | ||||
-rw-r--r-- | wolfram/lat | 40 | ||||
-rw-r--r-- | wolfram/lat.py | 26 | ||||
-rw-r--r-- | wolfram/wolfram-old.sh | 16 |
23 files changed, 542 insertions, 0 deletions
@@ -0,0 +1,6 @@ +curl -X POST \ +--data-binary @$1 \ +--header 'Content-Type: audio/x-flac; rate=44100;' \ +'https://www.google.com/speech-api/v2/recognize?output=json&lang=en-uk&app&key=AIzaSyAwpyvbeG6NrGMXSK1LjOvbREjx3nM_C8E' + + 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;} +} +} @@ -0,0 +1,7 @@ +#!/bin/zsh +DIR="./" +rec --channels 1 --rate 44100 ./jarsound.flac silence -l 1 0.01 1% 1 2.0 1% +$DIR/api2.sh ./jarsound.flac > ./jaroutput.txt +echo 'speaking' +$DIR/process.pl ./tmp/jaroutput.txt + @@ -0,0 +1,2 @@ +#!/bin/sh +echo $* | festival --tts diff --git a/weather/.api.sh.un~ b/weather/.api.sh.un~ Binary files differnew file mode 100644 index 0000000..ee14c0f --- /dev/null +++ b/weather/.api.sh.un~ diff --git a/weather/.test.perl.un~ b/weather/.test.perl.un~ Binary files differnew file mode 100644 index 0000000..604f035 --- /dev/null +++ b/weather/.test.perl.un~ diff --git a/weather/.test.pl.un~ b/weather/.test.pl.un~ Binary files differnew file mode 100644 index 0000000..b462ed2 --- /dev/null +++ b/weather/.test.pl.un~ diff --git a/weather/.weather.pl.un~ b/weather/.weather.pl.un~ Binary files differnew file mode 100644 index 0000000..5c42ce2 --- /dev/null +++ b/weather/.weather.pl.un~ diff --git a/weather/weather.pl b/weather/weather.pl new file mode 100755 index 0000000..2d9a10a --- /dev/null +++ b/weather/weather.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use Forecast::IO; +use Data::Dumper; + +my $lat = 55.6; +my $long = 13.0; +my $key = "1f154a62adc6843a77cc29de6ac1cc4b"; + +my $forecast = Forecast::IO->new( + key => $key, + longitude => $long, + latitude => $lat, +); +if(!$ARGV[0] || $ARGV[0] eq 'daily'){ +$query='daily'; +$text='The daily forecast is '; +}elsif($ARGV[0] eq 'hourly'){ +$query='hourly'; +$text='It will be '; +}elsif($ARGV[0] eq 'currently'){ +$query='currently'; +$text='Currently, the weather is '; +} + + + +system "~/Dropbox/speech/tts.sh \"$text $forecast->{$query}->{summary}\""; +print "$forecast->{$query}->{summary}"; +print "\n"; + +#my @daily_data_points = @{ $forecast->{daily}->{data} }; +# +## Use your imagination about how to use this data. +## in the meantime, inspect it by dumping it. +#for (@daily_data_points) { +# print Dumper($_); +#} diff --git a/wolfram/.api-old.sh.un~ b/wolfram/.api-old.sh.un~ Binary files differnew file mode 100644 index 0000000..279d7f5 --- /dev/null +++ b/wolfram/.api-old.sh.un~ diff --git a/wolfram/.api.sh.un~ b/wolfram/.api.sh.un~ Binary files differnew file mode 100644 index 0000000..6b72a93 --- /dev/null +++ b/wolfram/.api.sh.un~ diff --git a/wolfram/.wolf.p6.un~ b/wolfram/.wolf.p6.un~ Binary files differnew file mode 100644 index 0000000..446a50e --- /dev/null +++ b/wolfram/.wolf.p6.un~ diff --git a/wolfram/.wolf.un~ b/wolfram/.wolf.un~ Binary files differnew file mode 100644 index 0000000..f320ec4 --- /dev/null +++ b/wolfram/.wolf.un~ diff --git a/wolfram/.wolfram.sh.un~ b/wolfram/.wolfram.sh.un~ Binary files differnew file mode 100644 index 0000000..7dd5287 --- /dev/null +++ b/wolfram/.wolfram.sh.un~ diff --git a/wolfram/api-perl6.sh b/wolfram/api-perl6.sh new file mode 100644 index 0000000..8990cf1 --- /dev/null +++ b/wolfram/api-perl6.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# id: U6E8UV-AP3QJAT6RK +DIR="$HOME/Dropbox/speech" +toread=$(curl "http://api.wolframalpha.com/v2/query?input=$1&appid=U6E8UV-AP3QJAT6RK" | perl6 -e 'my $crap=slurp;my $out = $crap ~~ ms/"200" .*? "<plaintext>" <( .*? )> "</plaintext>"/;$out ~~ s/\(.*\)//;print "$out"') +$DIR/tts.sh "$toread" + diff --git a/wolfram/api.sh b/wolfram/api.sh new file mode 100755 index 0000000..28fcd93 --- /dev/null +++ b/wolfram/api.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# id: U6E8UV-AP3QJAT6RK +DIR="$HOME/Sync/Programming/speech" +toread=$(curl "http://api.wolframalpha.com/v2/query?input=$1&appid=U6E8UV-AP3QJAT6RK&format=plaintext&podindex=2" | sed ':a;N;$!ba;s/\n/ /g' |perl -pe '($_)=m{<plaintext>(.*?)</plaintext>} or print "No data found";s/\(.*\)//g') +$DIR/tts.sh "$toread" +echo $toread; + diff --git a/wolfram/api.sync-conflict-20150502-090303.sh b/wolfram/api.sync-conflict-20150502-090303.sh new file mode 100644 index 0000000..2ac45b2 --- /dev/null +++ b/wolfram/api.sync-conflict-20150502-090303.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# id: U6E8UV-AP3QJAT6RK +DIR="$HOME/Dropbox/speech" +toread=$(curl "http://api.wolframalpha.com/v2/query?input=$1&appid=U6E8UV-AP3QJAT6RK&format=plaintext&podindex=2" | gsed ':a;N;$!ba;s/\n/ /g' |perl -pe '($_)=m{<plaintext>(.*?)</plaintext>} or print "No data found";s/\(.*\)//g') +$DIR/tts.sh "$toread" +echo $toread; + diff --git a/wolfram/api.sync-conflict-20150615-220742.sh b/wolfram/api.sync-conflict-20150615-220742.sh new file mode 100644 index 0000000..2ac45b2 --- /dev/null +++ b/wolfram/api.sync-conflict-20150615-220742.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# id: U6E8UV-AP3QJAT6RK +DIR="$HOME/Dropbox/speech" +toread=$(curl "http://api.wolframalpha.com/v2/query?input=$1&appid=U6E8UV-AP3QJAT6RK&format=plaintext&podindex=2" | gsed ':a;N;$!ba;s/\n/ /g' |perl -pe '($_)=m{<plaintext>(.*?)</plaintext>} or print "No data found";s/\(.*\)//g') +$DIR/tts.sh "$toread" +echo $toread; + diff --git a/wolfram/example-result.xml b/wolfram/example-result.xml new file mode 100644 index 0000000..6dc1570 --- /dev/null +++ b/wolfram/example-result.xml @@ -0,0 +1,64 @@ +<?xml version='1.0' encoding='UTF-8'?> +<queryresult success='true' + error='false' + numpods='2' + datatypes='' + timedout='' + timedoutpods='' + timing='0.664' + parsetiming='0.299' + parsetimedout='false' + recalculate='' + id='MSPa2661b53440gdhceah8200002e67fb9ae0777967' + host='http://www2.wolframalpha.com' + server='18' + related='http://www2.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa2671b53440gdhceah82000060b56f323e8bg19i&s=18' + version='2.6'> + <pod title='Input interpretation' + scanner='Identity' + id='Input' + position='100' + error='false' + numsubpods='1'> + <subpod title=''> + <plaintext>Answer to the Ultimate Question of Life, the Universe, and Everything</plaintext> + <img src='http://www2.wolframalpha.com/Calculate/MSP/MSP2681b53440gdhceah82000067ib32g29di4d9g8?MSPStoreType=image/gif&s=18' + alt='Answer to the Ultimate Question of Life, the Universe, and Everything' + title='Answer to the Ultimate Question of Life, the Universe, and Everything' + width='455' + height='18' /> + </subpod> + </pod> + <pod title='Result' + scanner='Data' + id='Result' + position='200' + error='false' + numsubpods='1' + primary='true'> + <subpod title=''> + <plaintext>42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)</plaintext> + <img src='http://www2.wolframalpha.com/Calculate/MSP/MSP2691b53440gdhceah82000019d6099492d028ff?MSPStoreType=image/gif&s=18' + alt='42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)' + title='42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)' + width='486' + height='47' /> + </subpod> + </pod> + <assumptions count='1'> + <assumption type='SubCategory' + word='the answer to life' + template='Assuming ${desc1}. Use ${desc2} instead' + count='2'> + <value name='AnswerToLifeUniverseEverything' + desc='The Ultimate Answer' + input='*DPClash.MiscellaneousE.the+answer+to+life-_*AnswerToLifeUniverseEverything-' /> + <value name='MontyPythonsMeaningOfLife' + desc='Monty Python's Meaning of Life' + input='*DPClash.MiscellaneousE.the+answer+to+life-_*MontyPythonsMeaningOfLife-' /> + </assumption> + </assumptions> +</queryresult>
\ No newline at end of file diff --git a/wolfram/example2-result.xml b/wolfram/example2-result.xml new file mode 100644 index 0000000..6aae1cc --- /dev/null +++ b/wolfram/example2-result.xml @@ -0,0 +1,64 @@ +<?xml version='1.0' encoding='UTF-8'?> +<queryresult success='true' + error='false' + numpods='2' + datatypes='' + timedout='' + timedoutpods='' + timing='0.664' + parsetiming='0.299' + parsetimedout='false' + recalculate='' + id='MSPa2661b53440gdhceah8200002e67fb9ae0777967' + host='http://www2.wolframalpha.com' + server='18' + related='http://www2.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa2671b53440gdhceah82000060b56f323e8bg19i&s=18' + version='2.6'> + <pod title='Input interpretation' + scanner='Identity' + id='Input' + position='100' + error='false' + numsubpods='1'> + <subpod title=''> + <plaintext>Answer to the Ultimate Question of Life, the Universe, and Everything + <img src='http://www2.wolframalpha.com/Calculate/MSP/MSP2681b53440gdhceah82000067ib32g29di4d9g8?MSPStoreType=image/gif&s=18' + alt='Answer to the Ultimate Question of Life, the Universe, and Everything' + title='Answer to the Ultimate Question of Life, the Universe, and Everything' + width='455' + height='18' /> + </subpod> + </pod> + <pod title='Result' + scanner='Data' + id='Result' + position='200' + error='false' + numsubpods='1' + primary='true'> + <subpod title=''> + <plaintext>42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)</plaintext> + <img src='http://www2.wolframalpha.com/Calculate/MSP/MSP2691b53440gdhceah82000019d6099492d028ff?MSPStoreType=image/gif&s=18' + alt='42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)' + title='42 +(according to Douglas Adams' humorous science-fiction novel The Hitchhiker's Guide to the Galaxy)' + width='486' + height='47' /> + </subpod> + </pod> + <assumptions count='1'> + <assumption type='SubCategory' + word='the answer to life' + template='Assuming ${desc1}. Use ${desc2} instead' + count='2'> + <value name='AnswerToLifeUniverseEverything' + desc='The Ultimate Answer' + input='*DPClash.MiscellaneousE.the+answer+to+life-_*AnswerToLifeUniverseEverything-' /> + <value name='MontyPythonsMeaningOfLife' + desc='Monty Python's Meaning of Life' + input='*DPClash.MiscellaneousE.the+answer+to+life-_*MontyPythonsMeaningOfLife-' /> + </assumption> + </assumptions> +</queryresult> diff --git a/wolfram/lat b/wolfram/lat new file mode 100644 index 0000000..8d3cdf0 --- /dev/null +++ b/wolfram/lat @@ -0,0 +1,40 @@ +<?xml version='1.0' encoding='UTF-8'?> +<queryresult success='true' + error='false' + numpods='1' + datatypes='' + timedout='Integral,Series,Plot,Plotter,Simplification,Sequence,Sum' + timedoutpods='' + timing='4.551' + parsetiming='0.832' + parsetimedout='false' + recalculate='http://www3.wolframalpha.com/api/v2/recalc.jsp?id=MSPa54207hied0e9cb85c30000613102i371h49b63&s=16' + id='MSPa55207hied0e9cb85c300004c5338diei1i0bg0' + host='http://www3.wolframalpha.com' + server='16' + related='http://www3.wolframalpha.com/api/v2/relatedQueries.jsp?id=MSPa56207hied0e9cb85c300004a3i69g2d3i729f9&s=16' + version='2.6'> + <pod title='Alternate form of the integral' + scanner='Integral' + id='AlternateForm' + position='200' + error='false' + numsubpods='1'> + <subpod title=''> + <plaintext>1/24 (3 r (sqrt(3) r-2 x) sqrt(-3 r^2+4 r (sqrt(3) x+1)-4 x^2)-4 (3 r^2 (x-tan^(-1)((sqrt(3) r-2 x)/sqrt(-3 r^2+4 sqrt(3) r x+4 r-4 x^2)))-3 r (sqrt(3) x+2) x+2 x^3))+constant</plaintext> + </subpod> + </pod> + <assumptions count='1'> + <assumption type='Clash' + word='integral' + template='Assuming "${word}" is ${desc1}. Use as ${desc2} instead' + count='2'> + <value name='IntegralsWord' + desc='an integral' + input='*C.integral-_*IntegralsWord-' /> + <value name='MathematicalFunctionIdentityPropertyClass' + desc='a function property' + input='*C.integral-_*MathematicalFunctionIdentityPropertyClass-' /> + </assumption> + </assumptions> +</queryresult>
\ No newline at end of file diff --git a/wolfram/lat.py b/wolfram/lat.py new file mode 100644 index 0000000..92f31d1 --- /dev/null +++ b/wolfram/lat.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import requests +from urllib import quote_plus +import xml.etree.ElementTree as ET + +appid = 'U6E8UV-AP3QJAT6RK' + +def get_plaintext_query(latex): + r = requests.get('http://api.wolframalpha.com/v2/query?input=%s&appid=%s' % (quote_plus(latex), appid)) + root = ET.fromstring(r.text.encode('utf8')) + + for pod in root: + if pod.attrib.get('title', '') in ['Decimal approximation', 'Definite integral']: + subpod = pod.find('subpod') + result = subpod.find('plaintext').text + + if pod.attrib.get('title', '') == 'Definite integral': + return result.split('~~')[1] + else: + return result + +if __name__ == '__main__': + from sys import stdin + print get_plaintext_query(stdin.read()) diff --git a/wolfram/wolfram-old.sh b/wolfram/wolfram-old.sh new file mode 100644 index 0000000..c5fd338 --- /dev/null +++ b/wolfram/wolfram-old.sh @@ -0,0 +1,16 @@ +DIR="$HOME/Dropbox/speech/wolfram" +DIRA="$HOME/Dropbox/speech" +curl "`curl \"$1\" |gsed ':a;N;$!ba;s/\n/ /g'|perl -lpe 's/^.*Result<//' |perl -lpe 's/^.*?src="//' |perl -lpe 's/&.*$//'`" > /tmp/jarresult.gif +echo $? +if [[ $? -ne 0 ]] ; then + exit 1 +fi +convert /tmp/jarresult.gif /tmp/jarresult.tiff + +if [[ $? -ne 0 ]] ; then + exit 1 +fi + +if tesseract -l eng /tmp/jarresult.tiff /tmp/jarout; then +$DIRA/tts.sh `cat /tmp/jarout.txt` +fi |