diff --git a/main.py b/main.py index 8413509..9055f03 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ import sounddevice as sd # KONFIGURATION # ========================= -VOSK_MODEL_PATH = "/home/tino/Documents/_Documents/Schule/4 Wilhelm Maybach Schule/2BKI Jahr 2/Abschlussprojekt/test assistant/assistant_all_in_one/vosk-model-de-0.21/" +VOSK_MODEL_PATH = "/home/tino/Desktop/Abschlussprojekt/test assistant/cloneAssistantAllInOne/RasPi_Voice_Assistant--WIP/vosk-model-de-0.21" PIPER_BIN = "piper" PIPER_MODEL = "de_DE-thorsten-medium.onnx" SAMPLE_RATE = 22050 @@ -190,18 +190,21 @@ def vosk_listener(): # stream.start_stream() while True: - data = stream.read(4000, exception_on_overflow=False) - if rec.AcceptWaveform(data): - result = json.loads(rec.Result()) - text = result.get("text", "") - if text: - audio_queue.put(text) + if state != STATE_SPEAKING: #hinzugefügt um fehlerhafte eingaben zu stoppen + data = stream.read(4000, exception_on_overflow=False) + if rec.AcceptWaveform(data): + result = json.loads(rec.Result()) + text = result.get("text", "") + if text: + audio_queue.put(text) + else: + rec.Reset() # ========================= # WAKEWORD (SIMPLIFIZIERT) # ========================= - +""" def fake_wakeword_detector(): global state while True: @@ -209,7 +212,7 @@ def fake_wakeword_detector(): time.sleep(0.1) state = STATE_LISTENING speak("Wie kann ich helfen?") - + """ # ========================== # WAKEWORD (PORCUPINE) # ========================== @@ -226,12 +229,13 @@ def real_wakeword_detector(): access_key=ACCESS_KEY, keywords=[WAKEWORD] ) - if state == STATE_IDLE: + if state == STATE_IDLE: - def callback(indata, frames, time, status): + def callback(indata, frames, time_info, status): pcm = np.frombuffer(indata, dtype=np.int16) result = porcupine.process(pcm) if result >= 0: + time.sleep(1) #verbesserung der spracheingabe: wurde hinzugefügt weil es sonst worte halluziniert (wie "eine", "jarvis") state = STATE_LISTENING print("WAKE WORD DETECTED") speak("Ja, wie kann ich helfen?")