Python sesli asistan kodunda "Jsondecodeerror"

GGHOST

Hectopat
Katılım
20 Nisan 2020
Mesajlar
1.783
Çözümler
4
Merhaba, basit bir sesli asistan yapma calisiyorum da calistirinca soyle bir hata veriyor;

Kod:
C:\Users\sinan\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/sinan/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
 File "C:\Users\sinan\PycharmProjects\pythonProject\main.py", line 114, in <module>
 Assistant = genericassistant('intents. JSON', intent_methods = mappings)
 File "C:\Users\sinan\PycharmProjects\pythonProject\venv\lib\site-packages\neuralintents\main.py", line 53, in __init__.
 Self. Load_json_intents(intents)
 File "C:\Users\sinan\PycharmProjects\pythonProject\venv\lib\site-packages\neuralintents\main.py", line 58, in load_json_intents.
 Self. İntents = json.loads(open(intents).read())
 File "C:\Users\sinan\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 346, in loads.
 Return _default_decoder. Decode(s)
 File "C:\Users\sinan\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode.
 Obj, end = self. Raw_decode(s, idx = _w(s, 0).end())
 File "C:\Users\sinan\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode.
 Raise jsondecodeerror("expecting Value", S, err. Value) from none.
JSON. Decoder. Jsondecodeerror: Expecting Value: Line 19 column 1 (char 682)
Process finished with exit code 1
Kod budur.

Python:
from neuralintents import GenericAssistant.
import speech_recognition.
import pyttsx3 as tts.
import sys.

recognizer = speech_recognition.Recognizer()

speaker = tts.init()
speaker.setProperty('rate', 150)

todo_list = ['Go Shopping', 'Clean Room', 'Record Video']

def create_note():
 global recognizer.

 speaker.say("What do you want to write onto your note boss?")
 speaker.runAndWait()

 done = False.

 while not done:
 try:

 with speech_recognition.Microphone() as mic:

 recognizer.adjust_for_ambient_noise(mic, duration=0.2)
 audio = recognizer.listen(mic)

 note = recognizer.recognize_google(audio)
 note = note.lower()

 speaker.say("Choose a filename boss!")
 speaker.runAndWait()

 recognizer.adjust_for_ambient_noise(mic, duration=0.2)
 audio = recognizer.listen(mic)

 filename = recognizer.recognize_google(audio)
 filename = filename.lower()

 with open(f"{filename}.txt", 'w') as f:
 f.write(note)
 done = True.
 speaker.say(f"I successfully created the note {filename} boss")
 speaker.runAndWait()

 except speaker.recognition.UnknownValueError:
 recognizer = speech_recognition.Recognizer()
 speaker.say("I did not understand you! Please try again! boss")
 speaker.runAndWait()

def add_todo():

 global recognizer.

 speaker.say("What todo do you want to add boss?")
 speaker.runAndWait()

 done = False.

 while not done:
 try:

 with speech_recognition.Microphone() as mic:

 recognizer.adjust_for_ambient_noise(mic,duration=0.2)
 audio = recognizer.listen(mic)

 item = recognizer.recognize_google(audio)
 item = item.lower()

 todo_list.append(item)
 done = True.

 speaker.say(f"I added {item} to the to do list boss")
 speaker.runAndWait()

 except speech_recognition.UnknownValueError:
 recognizer = speech_recognition.Recognizer()
 speaker.say("I did not understand. Please try again boss!")
 speaker.runAndWait()

def show_todos():

 speaker.say("the items on your to do list are the following boss")
 for item in todo_list:
 speaker.say(item)
 speaker.runAndWait()

def hello():
 speaker.say("Hello.What can I do for you Boss?")
 speaker.runAndWait()

def quit():
 speaker.say("Okay Boss")
 speaker.runAndWait()
 sys.exit(0)

mappings = {
 "greeting": hello,
 "create_note": create_note,
 "add_todo": add_todo,
 "show_todos": show_todos,
 "exit": quit.

}

assistant = GenericAssistant('intents.json', intent_methods=mappings)
assistant.train_model()

while True:

 try:
 with speech_recognition.Microphone() as mic:

 recognizer.adjust_for_ambient_noise(mic, duration=0.2)
 audio = recognizer.listen(mic)

 message = recognizer.recognize_google(audio)
 message = message.lower()

 assistant.request(message)

 except speech_recognition.UnknownValueError:
 recognizer = speech_recognition.Recognizer()

Bu da ıntents. JSON kodum:

JSON:
{"intents":
[
 {"tag": "greeting",
 "patterns": ["Hey","Hello","What's up?","How is it going?","Hi"],
 "responses": ["Hi Boss!"]},

 {"tag": "create_note",
 "patterns": ["Please create a new note","New note","Create a note","I want to create a note"],
 "responses": [""]},

 {"tag": "add_todo",
 "patterns": ["I want to add a todo","add a new todo","add a todo to my list","new item on my todo list"],
 "responses": [""]},
 {"tag": "show_todos",
 "patterns": ["Show my todos","What are my todos","What is on my todo list"],
 "responses": [""]},
 {"tag": "exit",
 "pattern": ["Bye","Stop","Quit","I want to quit","Goodbye","I want to exit","I have to go"]},
]}
 
Son düzenleyen: Moderatör:

Yeni konular

Geri
Yukarı