SHOW:
|
|
- or go back to the newest paste.
1 | #Constantes de nivel de confianca e coeficiente de Viterbi | |
2 | NivelConf = 0.4 | |
3 | CoefViterbi = -10000 | |
4 | #Biblioteca de execucao automatica de aplicativos | |
5 | import pexpect | |
6 | #Biblioteca de busca de correspondencia entre strings | |
7 | import re | |
8 | #Biblioteca de manipulacao de strings | |
9 | import string | |
10 | #Biblioteca das funcoes das GPIO | |
11 | import RPi.GPIO as GPIO | |
12 | #Funcao de pausa da biblioteca "time" | |
13 | from time import sleep | |
14 | #Configuracoes iniciais das GPIO | |
15 | *********************) | |
16 | **********************) | |
17 | ||
18 | #Pino 16: saida-> Rele - ativacao | |
19 | GPIO.setup(16, GPIO.OUT) | |
20 | #Inicializacaso da variavel global de indicacao de Primeiro Ciclo | |
21 | global PrimCiclo | |
22 | #Inicializacao das variaveis globais de estado do comando | |
23 | global ComandoAcender | |
24 | global ComandoApagar | |
25 | #Inicializacao das saidas em "False" | |
26 | GPIO.output(16, False) | |
27 | ||
28 | #Funcao que busca 'sentence1' no texto de saida do Julius | |
29 | def AbrirJulius(TextoJulius): | |
30 | print ("ERRO 1") | |
31 | global PrimCiclo | |
32 | print ("ERRO 2") | |
33 | match_res = re.match(r'(.*)sentence1(\.*)', TextoJulius, re.S) | |
34 | print ("ERRO 3") | |
35 | if PrimCiclo==True: | |
36 | pass | |
37 | elif match_res: | |
38 | TestesErro(TextoJulius) | |
39 | else: | |
40 | print('ERRO!! Problemas ao carregar o Julius') | |
41 | pass | |
42 | #Funcao que busca valores invalidos para as variaveis 'sentence1','cmscore1' e 'score1' no texto de saida do Julius | |
43 | def TestesErro(TextoJulius): | |
44 | VetorLinhas = *********************") | |
45 | for line in VetorLinhas: | |
46 | if line.find('sentence1') != -1: | |
47 | sentence1 = line | |
48 | elif line.find('cmscore1') != -1: | |
49 | cmscore1 = line | |
50 | elif line.find('score1') != -1: | |
51 | score1 = line | |
52 | VetorCmscore = cmscore1.split() | |
53 | FlagErro = False | |
54 | for score in VetorCmscore: | |
55 | try: | |
56 | score_float = float(score) | |
57 | except ValueError: | |
58 | continue | |
59 | if (score_float < NivelConf): | |
60 | FlagErro = True | |
61 | print ("ERRO!! Nivel de confianca (%.3f) menor que %.3f.Tente novamente.")% (score_float, NivelConf) | |
62 | score1_float = float(score1.split()[1]) | |
63 | if (score1_float < CoefViterbi): | |
64 | FlagErro = True | |
65 | print ("ERRO!! Coeficiente de Viterbi (%f) menor que %f. Tente novamente.")% (score1_float, CoefViterbi) | |
66 | if (FlagErro== False): | |
67 | print (sentence1) | |
68 | print (cmscore1) | |
69 | print (score1) | |
70 | MoverPlat(sentence1) | |
71 | else: | |
72 | pass | |
73 | #Funcao que utiliza a plavra de comando para ligar a luz | |
74 | def LigarLuz(ComandoFalado): | |
75 | global ComandoAcender | |
76 | global ComandoApagar | |
77 | VetorStr = ComandoFalado.split() | |
78 | VetorStrTamanho = len(VetorStr) | |
79 | if (VetorStrTamanho<2): | |
80 | PalavraComando = 'erro' | |
81 | print ("ERRO!! Comando nao entendido.") | |
82 | elif (VetorStrTamanho>2): | |
83 | PalavraComando = 'erro' | |
84 | print ("ERRO!! Fale uma palavra por vez.") | |
85 | else: | |
86 | PalavraComando = VetorStr[1] | |
87 | print ("OK!! Comando reconhecido: %s") % (PalavraComando) | |
88 | if ((PalavraComando=='apagar') or (PalavraComando=='apaga') or | |
89 | (PalavraComando=='desliga') or (PalavraComando=='desligar')): | |
90 | ComandoApagar = True | |
91 | print ("A luz está apagada!") | |
92 | GPIO.output(16, False) | |
93 | sleep(2) | |
94 | elif ((PalavraComando=='ativa') or (PalavraComando=='ative') or | |
95 | (PalavraComando=='ativar') or (PalavraComando=='aciona') or | |
96 | (PalavraComando=='acione') or (PalavraComando=='acionar')): | |
97 | ComandoAcender = True | |
98 | print ("Luz Acessa!") | |
99 | GPIO.output(16, True) | |
100 | sleep(2) | |
101 | def Julius(): | |
102 | print ("Julius começa aqui") | |
103 | #child.expect(pexpect.EOF) | |
104 | child.expect('please speak', timeout=None) | |
105 | #child.expect (EOF) | |
106 | #child.expect_exact('please speak', timeout=None) | |
107 | #child.expect(pexpect.EOF, timeout=None) | |
108 | print ("erro aqui") | |
109 | ************************) | |
110 | print ("FALE....") | |
111 | if __name__== "__main__": | |
112 | global PrimCiclo | |
113 | global ComandoApagar | |
114 | global ComandoAcender | |
115 | PrimCiclo = True | |
116 | ComandoApagar= True | |
117 | ComandoAcender = False | |
118 | if PrimCiclo==True: | |
119 | #GPIO.output(16, True) | |
120 | print ('####################################################') | |
121 | print ('# Bem vindo ao sistema de reconhecimento de voz!! #') | |
122 | print ('####################################################') | |
123 | print ('Aguarde, carregando o Julius...') | |
124 | #child = *******************************************') | |
125 | child = pexpect.spawn('julius -C julius.jconf') | |
126 | #child.expect(pexpect.EOF) | |
127 | try: | |
128 | Julius() | |
129 | except KeyboardInterrupt: | |
130 | child.close(force=True) | |
131 | sys.exit() | |
132 | #break | |
133 | PrimCiclo=False | |
134 | #GPIO.cleanup() |