Skip to content

Commit 2c6c8aa

Browse files
committedMay 22, 2014
Sustituido parte del codigo por un script de shell
1 parent b224de9 commit 2c6c8aa

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed
 

‎STT.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
arecord -D plughw:1,0 -q -f cd -t wav -d 4 -r 16000 | flac - -f --best --sample-rate 16000 -s -o voz.flac;
2+
3+
wget -q -U "Mozilla/5.0" --post-file voz.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "http://www.google.com.mx/speech-api/v2/recognize?output=json&lang=es&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw" | cut -d\" -f8 > stt.txt
4+
5+
value=`cat stt.txt`
6+
echo "$value"

‎SpeakPy.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@
55
def escuchar():
66
#Grabar audio del microfono, convertirlo a FLAC
77
#y enviarlo a Google quien devolvera un JSON
8-
print('Grabando voz...')
9-
voz_raw = subprocess.Popen(['arecord', '-D', 'plughw:1,0', '-q', '-f', 'cd', '-t', 'wav', '-d', '3', '-r', '16000'], shell=False, stdout=subprocess.PIPE)
10-
voz_flac = subprocess.call(['flac', '-', '-f', '--best', '--sample-rate', '16000', '-s', '-o', 'voz.flac'], shell=False, stdin=voz_raw.stdout)
11-
print('Convirtiendo voz a texto...')
12-
envio = subprocess.Popen('wget -q -U "Mozilla/5.0" --post-file voz.flac --header "Content-Type: audio/x-flac; rate=16000" -O - "https://www.google.com.mx/speech-api/v2/recognize?output=json&lang=es&key=AIzaSyBOti4mM-6x9WDnZIjIeyEU21OpBXqWBgw"', shell=True, universal_newlines=True, stdout=subprocess.PIPE)
8+
envio = subprocess.Popen(["./STT.sh"], shell=True, universal_newlines=True, stdout=subprocess.PIPE)
139
texto = envio.communicate()[0]
14-
texto = texto.split('"')
15-
if len(texto) < 9:
16-
return " "
17-
else:
18-
return texto[9]
10+
texto = texto.strip('\n')
11+
return texto
1912

2013
def decir(frase):
2114
#Enviar texto a Google y reproducir el audio devuelto
@@ -45,16 +38,18 @@ def buscar(texto):
4538

4639
while True:
4740
clave = escuchar()
41+
print('Escuche:' + clave)
4842
if clave == 'Janis':
4943
decir("Dime Ricardo")
5044
orden = escuchar()
5145
comando = buscar(orden)
5246
if comando != 'no existe':
5347
proceso = subprocess.Popen(comando, shell=False)
54-
time.sleep(2)
48+
#time.sleep(3)
5549
while proceso.poll() == None:
56-
print('estoy en while')
50+
#print('-> ¿Cerrar?')
5751
terminar = escuchar()
52+
#print('Terminar:' + terminar)
5853
if terminar == 'cerrar':
5954
proceso.kill()
6055
else:

‎stt.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

‎test.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/python3
2+
3+
import subprocess, string, time, configparser
4+
5+
def escuchar():
6+
#Grabar audio del microfono, convertirlo a FLAC
7+
#y enviarlo a Google quien devolvera un JSON
8+
envio = subprocess.Popen(["./STT.sh"], shell=True, universal_newlines=True, stdout=subprocess.PIPE)
9+
texto = envio.communicate()[0]
10+
texto = texto.strip('\n')
11+
print(texto)
12+
13+
escuchar()

‎voz.flac

26.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)