| The Following 38 Users Say Thank You to BluesLee For This Useful Post: | ||
ahmadamaj, ajack, baem90, Bahador, BananaOnDrugs, banong, bingomion, Crogge, cy8aer, don.edri, duesselschorsch, ersanpermana, et3rnal, fw190, HtheB, ibrakalifa, imo, Iryus, Jordi, khan.orak, lorenzo, Maj3stic, MaKenZi, mariusmssj, marmistrz, MartinK, mike_shenoda, nicholes, nsuffys, PUNK, reinob, rotoflex, samipower, saponga, taixzo, thedead1440, turbovomit, ukki | ||
|
|
2012-09-22
, 18:08
|
|
|
Posts: 1,103 |
Thanked: 368 times |
Joined on Oct 2010
@ india, indore
|
#3
|
| The Following 2 Users Say Thank You to nicholes For This Useful Post: | ||
|
|
2012-09-23
, 01:50
|
|
Posts: 958 |
Thanked: 3,426 times |
Joined on Apr 2012
|
#5
|
vim -c ':/description' -c ':.-1' -c ":1,. d" -c ":.+1" -c ":.,$ d" -c ":wq!" ${file_prefix}.html
| The Following 3 Users Say Thank You to taixzo For This Useful Post: | ||
|
|
2012-09-23
, 05:36
|
|
Posts: 235 |
Thanked: 86 times |
Joined on Dec 2010
|
#7
|
What exactly does this line do:
I'm trying to implement this in Python.Code:vim -c ':/description' -c ':.-1' -c ":1,. d" -c ":.+1" -c ":.,$ d" -c ":wq!" ${file_prefix}.html
|
|
2012-09-23
, 06:11
|
|
|
Posts: 411 |
Thanked: 1,105 times |
Joined on Jan 2010
@ Europe
|
#8
|
What exactly does this line do:
I'm trying to implement this in Python.Code:vim -c ':/description' -c ':.-1' -c ":1,. d" -c ":.+1" -c ":.,$ d" -c ":wq!" ${file_prefix}.html
grep "description" ${file_prefix}.html | head -1
| The Following 4 Users Say Thank You to BluesLee For This Useful Post: | ||
|
|
2012-09-23
, 14:52
|
|
|
Posts: 1,348 |
Thanked: 1,863 times |
Joined on Jan 2009
@ fr/35/rennes
|
#10
|
| The Following User Says Thank You to www.rzr.online.fr For This Useful Post: | ||
About Mee42
Essentially the shell script works as follows: Record audio from mic & convert to flac format -> Google Voice API for speech recognition -> do some text manipulations here and there -> get an answer from wiki.answers.com -> read the answer using espeak.
Security aspects
Sending a text phrase to answers.com is one thing, sending your individual voice samples to Google's cloud is another thing. Just be aware what you are doing. It's your data.
About GUI discussions, N900/N9 versions etc
My aim was to share the script as a proof of concept so that the community can profit from it as soon as possible. Taixzo who develops Saera, a Siri clone with GUI which is available for the N900, integrates the essential ideas into his app. The best thing to do now is to support him by voting for Saera in 2012's Coding competition. With a N9/N950 in his hands the chances are even better to see a Harmattan port of Saera.
Changelog
Output of a single (!) terminal session
#!/bin/sh # # Mee42 - Siri/Google Now for the poor man ;-) # # CopyStraightForward blueslee@tmo # # What you need: gst-launch or alternatively arecord + flac, wget, espeak # Choose your language here, only English is supported yet # (html structure of answers from *.answers.com are different) lang="en" if [ "${lang}" = 'en' ]; then lang_flag='wiki' else lang_flag=${lang} fi # Maximum speech recording time in sec speech_rec_time=4 #use for arecord speech_num_buffers="$(( 50 * ${speech_rec_time} ))" #used for gstreamer # Default sample rate for flac. Use 48000 if you are using arecord + flac # as flac's --sample-rate=16000 does not work for me sample_rate=16000 # Just a shortcut for Google's Voice API Url api_url='http://www.google.com/speech-api/v1/recognize?lang=${lang}-${lang}\ &client=chromium' # Temporary files are named as below with the corresponding suffix file_prefix='file_temp' rm -f ${file_prefix}* about() { cat << EOF ----------------------------------------------------------------------------- Mee42 is a shell script which records your voice and tries to answer your question using Google Voice API for speech recognition, answers.com for db of answers and espeak for speech synthesis. CopyStraightForward blueslee@tmo. EOF } # Record voice via gst-launch, alternatively you can use arecord and flac record_voice() { gst-launch-0.10 pulsesrc num-buffers=${speech_num_buffers} ! audioconvert\ ! audioresample ! audiorate ! audio/x-raw-int,rate=${sample_rate} ! flacenc\ ! filesink location=${file_prefix}.flac 1>/dev/null 2>&1 #arecord -f dat -d ${speech_rec_time} ${file_prefix}.wav 1>/dev/null 2>&1 #flac --compression-level-5 ${file_prefix}.wav 1>/dev/null 2>&1 #Remark: sox on N900 doesnt work as below i.e. has no flac support #sox ${file_prefix}.wav ${file_prefix}.flac rate 16k gain -n -5 silence 1 5 2% } # Speech2Txt uses Google Voice API speech2txt() { wget -q -U "Mozilla/5.0" --post-file ${file_prefix}.flac\ --header="Content-Type: audio/x-flac; rate=${sample_rate}" -O\ - ${api_url} > ${file_prefix}.ret cat ${file_prefix}.ret | sed 's/.*utterance":"//'\ | sed 's/","confidence.*//' > ${file_prefix}.txt } # Get answer from answers.com get_answer() { # We are replacing ' ' by '_' as a typical request is handled in the http # header, for instance http://wiki.answers.com/Q/who_is_michael_jordan sed -e 's/ /_/g' ${file_prefix}.txt > ${file_prefix}2.txt request_url="http://${lang_flag}.answers.com/Q/"`cat ${file_prefix}2.txt` wget ${request_url} --output-document=${file_prefix}.html 1>/dev/null 2>&1 # The first occurance of 'description' contains our answer grep 'og:description' ${file_prefix}.html | head -1\ | sed -e 's/.*og:description//' | cut -d"\"" -f3,3 > ${file_prefix}.txt } # Sanity check if something went wrong, i.e. we have no or wrong answer error_handling() { errorcheck=`cat ${file_prefix}.txt | cut -c1-4` if [ "${errorcheck}" = "http" -o "${errorcheck}" = "" ]; then echo 'Something went wrong.' > ${file_prefix}.txt fi } # Txt2speech via espeak txt2speech() { espeak -v${lang} -f ${file_prefix}.txt 1>/dev/null 2>&1 } # Cleanup of temporary files cleanup() { rm -f ${file_prefix}* } clear about while true; do espeak -v${lang} "Ask your question or say exit." 1>/dev/null 2>&1 printf 'Recording sound input.................' record_voice espeak -v${lang} "Thank you." 1>/dev/null 2>&1 sleep 1 echo printf 'Speech2txt via Google Voice...........' speech2txt; cat ${file_prefix}.txt # Leave the while loop if users says 'exit' || 'quit' || 'stop' exit_code=`cat ${file_prefix}.txt` if [ "${exit_code}" = "exit" -o "${exit_code}" = "quit"\ -o "${exit_code}" = "stop" ]; then cleanup exit 0 fi printf 'Getting answer from answers.com.......' get_answer error_handling cat ${file_prefix}.txt printf 'Txt2speech via espeak.................' txt2speech echo; echo cleanup doneYou will need to install the debian packages mentioned in the script, i hope the below list is complete:
As always have fun.
Last edited by BluesLee; 2012-09-29 at 19:01. Reason: Security Aspects