diff options
Diffstat (limited to 'util/lib')
-rw-r--r-- | util/lib/geo/Makefile | 15 | ||||
-rw-r--r-- | util/lib/geo/index.js | 48 | ||||
-rw-r--r-- | util/lib/geo/package.json | 7 | ||||
-rwxr-xr-x | util/lib/naturalvoices/att.sh | 33 | ||||
-rw-r--r-- | util/lib/stt/README.md | 4 | ||||
-rw-r--r-- | util/lib/stt/google.sh | 40 |
6 files changed, 147 insertions, 0 deletions
diff --git a/util/lib/geo/Makefile b/util/lib/geo/Makefile new file mode 100644 index 00000000..d13cd471 --- /dev/null +++ b/util/lib/geo/Makefile @@ -0,0 +1,15 @@ +all: node_modules GeoLiteCity.dat + +node_modules: package.json + npm install + @touch -r $< $@ + +GeoLiteCity.dat: + @test -e GeoLiteCity.dat && ln -s GeoLiteCity.dat $@ || { \ + echo 'No GeoIP City database found.'; \ + echo 'You can get one from http://dev.maxmind.com/geoip/geolite:'; \ + echo ' wget -N http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz'; \ + echo ' gunzip GeoLiteCity.dat.gz'; \ + exit 23; \ + } + diff --git a/util/lib/geo/index.js b/util/lib/geo/index.js new file mode 100644 index 00000000..0763b1a4 --- /dev/null +++ b/util/lib/geo/index.js @@ -0,0 +1,48 @@ +function slurp (stream, callback) { + var data = [] + stream.on('data', function (chunk) { + data.push(chunk) + }) + stream.on('end', function () { + callback(null, Buffer.concat(data)) + }) + stream.resume() +} + + +var path = require('path') +var city_dat = path.join(__dirname, 'GeoLiteCity.dat') + +var geoip = require('geoip') +var city = new geoip.City(city_dat) + +slurp(process.stdin, function (err, data) { + var lines = data.toString().split('\n') + // remove last, empty element (caused by the [mandatory] final \n) + if (lines.length > 1 && lines[lines.length - 1] === '') { + lines.pop() + } + var name = 0, addr = 1 + lines + .map(function (line) { return line.split(' ') }) + .forEach(function (host) { + //city.lookup(host[addr], function (err, loc) { + // if (err) { + // console.error('#', host[name], err.message) + // } else { + // console.log(host[name] + ': ' + loc.longitude + ',' + loc.latitude) + // } + //}) + var loc = city.lookupSync(host[addr]) + //if (!loc) { console.error('#', host[name]) } + if (loc) { + var a = loc.latitude + var b = loc.longitude + //var c = loc.altitude + //var geo = 'geo:' + [a,b,c].join(',') + var geo = 'geo:' + [a,b].join(',') + + console.log(host[name], geo) + } + }) +}) diff --git a/util/lib/geo/package.json b/util/lib/geo/package.json new file mode 100644 index 00000000..ad449a62 --- /dev/null +++ b/util/lib/geo/package.json @@ -0,0 +1,7 @@ +{ + "name": "geo", + "version": "0.0.0", + "dependencies": { + "geoip": "*" + } +} diff --git a/util/lib/naturalvoices/att.sh b/util/lib/naturalvoices/att.sh new file mode 100755 index 00000000..3ec903c5 --- /dev/null +++ b/util/lib/naturalvoices/att.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# The cached version of naturalvoices +# This should prevent us from being pwned again ... + + + +get_tts(){ + # ENV: + # OUTFILE - path to outfile (required) + # voice - voice to use (default: klara) + # INP: + # $@ - input text + + : ${OUTFILE?please provide OUTFILE} + text=$(echo $* | sed -e "s/ /+/g" -e "s/\//%2F/g") + voice="${voice:-klara}" + # TODO grab this url from the tts demo page + ip="204.178.9.51" + base_url="http://$ip" + curl -sS $base_url$( curl -Ss -H "Host:$ip" \ + -H "Origin:http://www2.research.att.com" \ + -e "http://www2.research.att.com/~ttsweb/tts/demo.php" \ + -A "Mozilla/5.0 (X11; Linux x86_64; rv:23.0) Gecko/20100101 Firefox/23.0" \ + -d "voice=$voice" -d "txt=$text" -d "speakButton=SPEAK" \ + -H "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" \ + "$base_url/tts/cgi-bin/nph-nvttsdemo" | \ + grep HREF|sed 's/.*\(".*"\).*/\1/' | \ + sed -e 's/"//g' ) > "$OUTFILE" +} + +play_file(){ + aplay "$*" >/dev/null +} diff --git a/util/lib/stt/README.md b/util/lib/stt/README.md new file mode 100644 index 00000000..be905770 --- /dev/null +++ b/util/lib/stt/README.md @@ -0,0 +1,4 @@ +# Speech to Text api wrapper + +Because Speech to text is hardâ„¢ with FOSS, these libraries utilize the magic of +the internets to solve this problem. diff --git a/util/lib/stt/google.sh b/util/lib/stt/google.sh new file mode 100644 index 00000000..8d23a73d --- /dev/null +++ b/util/lib/stt/google.sh @@ -0,0 +1,40 @@ +#!/bin/sh + +cat <<EOF >&2 +NOTE: The google speech-to-text api v1 has been made obsolete! +Code is here only for reference and will most likely not work anymore. +EOF + +_get_content_type(){ + file -b --mime-type "$1" +} +_get_audio_rate(){ + file "$1" | sed -n -e 's/.* \([.0-9]\+\) kHz.*/\1/p' \ + | awk '{print int($1 *1000)}' +} + +record_audio(){ + # usage : _record_audio num_seconds + # echoes the output file + tmpfile=$(mktemp) + : ${1?please provide number of seconds to record} + arecord -d "$1" -r 16000 -t wav -q -f cd | flac -s -f - -o "$tmpfile" && echo "$tmpfile" +} +stt(){ + # usage: (lang=de-de stty recorded_file) + : ${1? please provide recorded file} + infile="$1" + lang=${lang:-en-us} + _get_content_type "$1" | (! grep -q "x-flac" ) \ + && echo "infile needs to be in flac format" \ + && return 1 + # only flac seems to be working... + wget -q -O - \ + -U 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7' \ + --post-file "$infile" \ + --header "Content-Type: `_get_content_type $infile`; rate=`_get_audio_rate $infile`;" \ + "http://www.google.com/speech-api/v1/recognize?lang=${lang}&client=chromium&maxresults=1" \ + | sed -n 's/.*utterance":"\([^"]*\)".*/\1/p' + + # returns {"status":0,"id":"d9269e6f741997161e41a4d441b34ba1-1","hypotheses":[{"utterance":"hallo Welt","confidence":0.7008959}]} +} |