Warum Funktioniert mein Wake Word nicht?

Hallo,

ich programmiere gerade einen Sprachassistenten und bin gerade am Wake Word dran. Mein Code sieht so aus:

import openai
import pyttsx3
import re
import pyjokes
import speech_recognition as sr
from pyowm import OWM
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import time
import random
import datetime
import pytz
from geopy.geocoders import Nominatim
from timezonefinder import TimezoneFinder
import sounddevice as sd
import pvporcupine

openai.api_key = 'sk-...'
model_id = "gpt-4"

engine = pyttsx3.init()

WAKE_WORD_MODEL_FILE_PATH = "C:\\Hey-Luna_de_windows_v3_0_0\\Hey-Luna_de_windows_v3_0_0.ppn"


def recognize_speech():
    recognizer = sr.Recognizer()

    while True:
        with sr.Microphone() as source:
            print("Sage etwas...")
            audio = recognizer.listen(source, timeout=15)

        try:
            text = recognizer.recognize_google(audio, language="de-DE")
            print("Text: " + text)
            return text
        except sr.UnknownValueError:
            return "not_understood"
        except sr.RequestError as e:
            print(f"Fehler bei der Anfrage an die Google Web Speech API: {e}")
            return ""


def record_audio(sample_rate, duration):
    print("Aufnahme gestartet...")
    audio = sd.rec(int(sample_rate * duration), samplerate=sample_rate, channels=1, dtype='int16')
    sd.wait()
    print("Aufnahme beendet.")
    return audio.flatten()


def picovoice_listen():
    keyword_file_path = "C:\\Hey-Luna_de_windows_v3_0_0\\Hey-Luna_de_windows_v3_0_0.ppn"
    sensitivities = [0.5]  # Adjust as needed

    try:
        handle = pvporcupine.create(
            keyword_paths=[keyword_file_path],
            sensitivities=sensitivities,
            access_key='...'
        )

        sample_rate = handle.sample_rate

        while True:
            pcm = record_audio(sample_rate=sample_rate, duration=15)
            keyword_index = handle.process(pcm)

            if keyword_index >= 0:
                print("Wake word detected!")
                break

    except pvporcupine.PorcupineError as e:
        print(f"Porcupine error: {e}")

    finally:
        if 'handle' in locals():
            handle.delete()


def openai_request(prompt):
    response = openai.ChatCompletion.create(
        model=model_id,
        messages=prompt
    )

    api_usage = response['usage']
    print('Total Token consumed: {0}'.format(api_usage['total_tokens']))
    prompt.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
    return prompt


def speak(text):
    engine.say(text)
    engine.runAndWait()


def ausführen():
    while True:
        picovoice_listen()

        q = recognize_speech()
        print("Erkannter Text:", q)

        if q == "not_understood":
            speak("Entschuldigung! Das habe ich nicht verstanden.")
            break

        elif not q:
            break

        elif "hallo" in q:
            speak('Hallo! Womit kann ich dir behilflich sein?')
            continue

        else:
            prompt = [{'role': 'user', 'content': q}]
            prompt = openai_request(prompt)
            response = prompt[-1]['content']
            speak(response)
            break


if __name__ == '__main__':
    ausführen()

wenn ich nun aber das Programm ausführe, kommt diese Meldung und ich muss das Wake Word nicht sagen, um meine Frage zu stellen, welche dann von z.B. OpenAI beantwortet wird:

C:\Users\User\PycharmProjects\voiceAssistant\venv\interpreter\Scripts\python.exe C:\Users\User\PycharmProjects\voiceAssistant\main.py 

Porcupine error: Initialization failed:

 [0] Keyword file (.ppn) and model file (.pv) should belong to the same language. File belongs to `de` while model file (.pv) belongs to `en`.

Sage etwas...

woran liegt das?

Freundliche Grüsse

Code, künstliche Intelligenz, Programmiersprache, Python, Python 3, Pycharm, ChatGPT

Meistgelesene Beiträge zum Thema Künstliche Intelligenz