I'm doing an artificial intelligence project I'm trying to get my boat to run command from a list in .txt
but I'm running into next
errorFile "C: /Users/leandro/PycharmProjects/Iana/main.py", line 22, in load_cmds indexError: list index out of range
When I delete everything I have in this list, cmds.txt
works but I can not see the commands because there are none in the list, please someone can help me
follow the code:
from chatterbot import ChatBot
# from datetime import datetime
import os
import speech_recognition as sr
import pyttsx3
speaker = pyttsx3.init('sapi5')
bot = ChatBot('Iana', read_only=True)
dict_cmds = {}
def load_cmds():
lines = open('cmds.txt', 'r').readline()
for line in lines:
line = line.replace('\n', '')
parts = line.split('\t')
dict_cmds.update({parts[0]: parts[1]})
def Speak(text):
speaker.say(text)
speaker.runAndWait()
load_cmds()
for k, v in dict_cmds.items():
print(k, '====>', v)
r = sr.Recognizer()
with sr.Microphone() as s:
r.adjust_for_ambient_noise(s)
print('voce: ')
while True:
audio = r.listen(s)
speech = r.recognize_google(audio, language='pt')
response = bot.get_response(speech)
print('você disse ', speech)
print('Ana:', response)
Speak(response)
que horas sao? askTime
me informe as horas. askTime
pode me dizer as horas? askTime
que dia e hoje? askDate
So this is my text file
'