gidvalencia

Artificial intelligence, voice recognition using Google

Jan 1st, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.08 KB | None | 0 0
  1. #!/bin/bash
  2.     #######################################################################
  3.     #Artificial intelligence, voice recognition using Google.
  4.     #Inteligencia artificial con reconocimiento de voz usando Google.
  5.     #Искусственный интеллект, распознавание голоса с помощью Google.
  6.     #Script creado por Alexis Zaytsev (alexiszaytsev@gmail.com)
  7.     #######################################################################
  8.     #Antes de ejecutar el script hay que instalar dependencias.
  9.     #sudo apt-get install alsa-utils
  10.     #sudo apt-get install sox
  11.     ##sudo apt-get install espeak
  12.     #######################################################################
  13.     # LICENCIA DE USO
  14.     #######################################################################    
  15.     # This program is free software: you can redistribute it and/or modify
  16.     # it under the terms of the GNU General Public License as published by
  17.     # the Free Software Foundation, either version 3 of the License, or
  18.     # (at your option) any later version.
  19.     #
  20.     # This program is distributed in the hope that it will be useful,
  21.     # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23.     # GNU General Public License for more details.
  24.     #
  25.     # You should have received a copy of the GNU General Public License
  26.     # along with this program. If not, see «http://www.gnu.org/licenses/».
  27.     #######################################################################
  28. echo "grabando..."
  29.     arecord -D plughw:1,0 -d 3 -q -f cd -r 16000 speech.wav # Grabamos audio file speech.wav de 03 segundos сon 16 мГц samping rate.
  30. echo "grabacion finalizada"
  31.     sox speech.wav speech.flac gain -n -5 silence 1 5 2% # Conversión de formato  speech.wav en speech.flac
  32. rm speech.wav # Eliminamos speech.wav
  33. echo "analisis de voz..."
  34. wget -q -U "Mozilla/5.0" --post-file speech.flac --header="Content-Type: audio/x-flac; rate=16000" -O - "https://www.google.com/speech-api/v2/recognize?output=json&lang=es-ES&key=AIzaSyAqk7vE0vQDR3JItUPgFp6bcPqgJz8h8tI" | cut -d\" -f8  > text.txt
  35. rm speech.flac # Eliminamos speech.flac
  36. file="/home/tu_nombre/text.txt"      #La ruta donde se encuentra el archivo text.txt
  37. read -d $'\x04' name < "$file"       #El contenido de $ archivo se redirige a la entrada estándar desde donde se lee en la variable $ name
  38. case $name  in #Ponemos los parametros para buscar y comparar las palabras.
  39.           "Hola") echo "Hola!!! Que tal!" | espeak -v es-la -s 160
  40.           ;;
  41.           "hola qué tal") echo "Hola!!! Que tal!" | espeak -v es-la -s 160
  42.           ;;
  43.           "qué tal") echo "Hola!!! Que tal!" | espeak -v es-la -s 160
  44.           ;;
  45.           "ordenador") echo "Si!!! Te  escucho!!!" | espeak -v es-la -s 160
  46.           ;;
  47.           "gracias") echo "de nada" | espeak -v es-la -s 160
  48.           ;;
  49.           "muchas gracias") echo "Vale! De nada!" | espeak -v es-la -s 160
  50.           ;;
  51.           "todo bien") echo "Si!!! Todo bien!!!" | espeak -v es-la -s 160
  52.           ;;
  53.           "todo va bien") echo "Si!!! Todo bien!!!" | espeak -v es-la -s 160
  54.           ;;
  55.           "está bien") echo "Si!!! Todo bien!!!" | espeak -v es-la -s 160
  56.           ;;
  57.           "todo está bien") echo "Si!!! Todo bien!!!" | espeak -v es-la -s 160
  58.           ;;
  59.           "quiero decir") echo "Que quieres decirme!!!" | espeak -v es-la -s 160
  60.           ;;
  61.           "quiero decirte") echo "Que quieres decirme!!!" | espeak -v es-la -s 160
  62.           ;;
  63.           "quería decir") echo "Que quieres decirme!!!" | espeak -v es-la -s 160
  64.           ;;
  65.           "quería decirte") echo "Que quieres decirme!!!" | espeak -v es-la -s 160
  66.           ;;
  67.           "qué te quiero") echo "Gracias!!! Yo tambien te quiero!!!" | espeak -v es-la -s 160
  68.           ;;
  69.           "qué te quiero mucho") echo "Gracias!!! Yo tambien te quiero!!!" | espeak -v es-la -s 160
  70.           ;;
  71.           "te quiero mucho") echo "Gracias!!! Yo tambien te quiero!!!" | espeak -v es-la -s 160
  72.           ;;
  73. esac
Add Comment
Please, Sign In to add comment