ウェイクワードエンジンモジュールテスト(失敗)

ウェイクワードエンジンモジュールテスト

import pyaudio
import numpy as np
from openwakeword.model import Model

class SimpleWakeWordDetector:
    def __init__(self, model_path="alexa_v0.1.onnx", threshold=0.5):
        self.model_path = model_path
        self.threshold = threshold
        self.format = pyaudio.paInt16
        self.channels = 1
        self.rate = 16000
        self.chunk = 1024

        self.model_name = model_path  # モデル名 = ファイル名
        self.model = Model(
            wakeword_models=[self.model_path],
            inference_framework="onnx"
        )

        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(
            format=self.format,
            channels=self.channels,
            rate=self.rate,
            input=True,
            frames_per_buffer=self.chunk
        )

    def listen_for_wakeword(self):
        print(f"ウェイクワード待機中...({self.model_path})")
        prev_detect = False

        while True:
            data = self.stream.read(self.chunk, exception_on_overflow=False)
            audio = np.frombuffer(data, dtype=np.int16).astype(np.float32) / 32768.0

            self.model.predict(audio)
            score = self.model.get_last_prediction(self.model_name)

            print(f"score: {score:.3f}", end='\r')

            detect = score > self.threshold
            if detect and not prev_detect:
                print(f"\nWakeword Detected! (score: {score:.3f})")
                return True

            prev_detect = detect

 touch simple_wakeword.py

で作成

touch wordtest.py

from simple_wakeword import SimpleWakeWordDetector

# モジュール初期化(Alexa用モデルとしきい値指定)
wakeword_detector = SimpleWakeWordDetector(
    model_path="alexa_v0.1.onnx",
    threshold=0.5
)

# 検知まで待機
detected = wakeword_detector.listen_for_wakeword()

if detected:
    print("こんにちは")

しかし反応がない

とりあえずウェイクワードは保留とし
先にRAGと llama index を行う

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です