[ Foro de Python ]

BUSCO SOLUCIÓN A ESTE PROBLEMA EN MI CÓDIGO: SyntaxError: unexpected EOF while parsing

25-Aug-2021 12:44
Invitado (ZafiroW)
1 Respuestas

Muy buenas, estoy aprendiendo programación y me recomendaron aprender python, así que después de aprender algo me dispuse a crear con mucho entusiasmo mi propio asistente virtual, después de haber solucionado muchos errores me topo con este que creo que no podré solucionarlo por mi mismo: dejo dos scripts adjuntos para que les puedan hechar un vistazo.

PRIMER SCRIPT:
from ACTIONS import N_EXECUTER, STATE, state1, state2
import VOICE_byIGOR as VOICE
import pyttsx3
import speech_recognition as sr
import os
global recording
global RECOGNIZER
global ACTIVE_VOCAB
global ACTIVE_DICT
global ASLEEP_VOCAB
global ASLEEP_DICT
RECOGNIZER = sr.Recognizer()
ACTIVE_VOCAB = [
[ ],"estás despierta", "despierta",
"duerme", "activar modo usuario corriente",
"activar modo usuario", "iniciar modo usuario corriente",
"iniciar modo usuario", "inicia el modo usuario", "activa el modo usuario",
"inicia el modo usuario corriente", "activa el modo usuario"
]
ACTIVE_DICT = {
1:1, 2:2, 3:3, 4:6, 5:6, 6:6, 7:6, 8:6, 9:6, 10:6, 11:6
}
# ES IMPORTANTE QUE NO HAYA VALORES IGUALES EN LAS DOS LISTAS
ASLEEP_VOCAB = [
[ ], "despierta"
]
ASLEEP_DICT = {
1:3
}
def LISTENING(language, adjust_for_ambient_noise_duration):
global sentence
with sr.Microphone() as mic:
RECOGNIZER.adjust_for_ambient_noise(mic, duration = adjust_for_ambient_noise_duration)
recording = RECOGNIZER.listen(mic, phrase_time_limit = None)
sentences = RECOGNIZER.recognize_google(recording, language = language)
sentences = sentences.lower()
sentences = sentences.split("irina ")
unnecessary_info = sentences[0]
sentences.remove(str(unnecessary_info))
sentence = " ".join(str(each_word) for each_word in sentences)
if " y " in sentence:
global both_statements
both_statements = sentence.split(" y ")
if len(both_statements) >= 3:
PROCESS()
else:
BIG_PROCESS()



def PROCESS():
if STATE is True:
if sentence not in ACTIVE_VOCAB:
print("ERROR 1")
VOICE.SAY("NO ENTIENDO LO QUE ME DICES.")
LISTENING("es-ES", 1)
else:
n = ACTIVE_VOCAB.index(sentence)
if n in ACTIVE_DICT:
n = ACTIVE_DICT.get(n)
ACTIONS.N_EXECUTER(n)
LISTENING("es-ES", 1)
else:
VOICE.SAY("NO SE ENCUENTRA EL IDENTIFICADOR DE LA FUNCIÓN EN ACTIF DIC, HAY QUE AÑADIR EL UN ID A LA FUNCIÓN.")
LISTENING("es-ES", 1)
else:
if sentence not in ASLEEP_VOCAB:
print("ERROR 2")
VOICE.SAY("NO ENTIENDO LO QUE ME DICES.")
LISTENING("es-ES", 1)
else:
n = ASLEEP_VOCAB.index(sentence)
if n in ASLEEP_DICT:
n = ASLEEP_DICT.get(n)
ACTIONS.N_EXECUTER(n)
LISTENING("es-ES", 1)
else:
SAY("NO SE ENCUENTRA EL IDENTIFICADOR DE LA FUNCIÓN EN ASLIP DIC, HAY QUE AÑADIR EL UN ID A LA FUNCIÓN.")
LISTENING("es-ES", 1)

def BIG_PROCESS():
for i in both_statements:
unnecessary_info = both_statements[0]
sentence = " ".join(str(each_word) for each_word in unnecessary_info)
both_statements.remove(str(unnecessary_info))
if STATE is True:
if sentence not in ACTIVE_VOCAB:
print("ERROR 1")
VOICE.SAY("NO ENTIENDO LO QUE ME DICES.")
LISTENING("es-ES", 1)
else:
n = ACTIVE_VOCAB.index(sentence)
if n in ACTIVE_DICT:
n = ACTIVE_DICT.get(n)
ACTIONS.N_EXECUTER(n)
LISTENING("es-ES", 1)
else:
VOICE.SAY("NO SE ENCUENTRA EL IDENTIFICADOR DE LA FUNCIÓN EN ACTIF DIC, HAY QUE AÑADIR EL UN ID A LA FUNCIÓN.")
LISTENING("es-ES", 1)
else:
if sentence not in ASLEEP_VOCAB:
print("ERROR 2")
VOICE.SAY("NO ENTIENDO LO QUE ME DICES.")
LISTENING("es-ES", 1)
else:
n = ASLEEP_VOCAB.index(sentence)
if n in ASLEEP_DICT:
n = ASLEEP_DICT.get(n)
ACTIONS.N_EXECUTER(n)
LISTENING("es-ES", 1)
else:
SAY("NO SE ENCUENTRA EL IDENTIFICADOR DE LA FUNCIÓN EN ASLIP DIC, HAY QUE AÑADIR EL UN ID A LA FUNCIÓN.")
LISTENING("es-ES", 1)

SEGUNDO SCRIPT:

import pyttsx3
import speech_recognition as sr
import os
from datetime import datetime
import pytz
import VOICE_byIGOR as VOICE
from Time_zones import *
global state1
global state2
global STATE
state1 = True
state2 = False
STATE = None
global hour
global hour_minutes
hour = tz_Madrid_hour
minute = tz_Madrid_minutes

def STATE_CONFIRMATION():
VOICE.SAY("Afirmativo Igor, y siempre a su disposición.")

def GREET():
VOICE.SAY("Sí, señor.")

def FIRST_GREET():
if hour <= 3:
VOICE.SAY(f"Buenasnoches, son las {hour} y {minute}, hora española.")
elif tz_Madrid_hour <= 11:
VOICE.SAY(f"Buenosdías, son las {hour} y {minute}, hora española.")
elif hour <= 20:
VOICE.SAY(f"Buenastardes, son las {hour} y {minute}, hora española.")
else:
VOICE.SAY(f"Buenasnoches, son las {hour} y {minute}, hora española.")

#def N_EXECUTER(n):
# if n == 1:
# STATE_CONFIRMATION()
# elif n == 2:
# FIRST_GREET()
# elif n == 3:
# STATE = state2
# print("Sí, señor")
# elif n == 6:
#
#
# #elif n ==  :
#
# else:
# VOICE.SAY("No está identificada la función en el N_EXECUTER")

def N_EXECUTER(n):

EL ERROR LITERALMETE ES EL SIGUIENTE:
   def N_EXECUTER(n):
                    ^
SyntaxError: unexpected EOF while parsing


03-Sep-2021 18:41
Nacho Cabanes (+83)

Después de " def N_EXECUTER(n):" debería haber una línea más, que detalle el contenido de esa función.






(No se puede continuar esta discusión porque tiene más de dos meses de antigüedad. Si tienes dudas parecidas, abre un nuevo hilo.)