dscripka / openWakeWord

An open-source audio wake word (or phrase) detection framework with a focus on performance and simplicity.
Apache License 2.0
746 stars 71 forks source link

Simple example does not work on Ubuntu 24.04 in WSL2 #204

Open dibalavs opened 1 month ago

dibalavs commented 1 month ago

Trying to install oww and launch basic example:

pip install openwakeword --break-system-packages

Example script:

import openwakeword
from pyaudio import PyAudio, paInt16
from openwakeword.model import Model
import wave

CHUNK_SIZE=2048

# BUG1: download_models() is not available in utils.
#openwakeword.utils.download_models()

# Instantiate the model(s)
# BUG2:  CUDAExecutionProvider is used instead of CPU.
model = Model(
 #   wakeword_models=["path/to/model.tflite"],  # can also leave this argument empty to load all of the included pre-trained models
)

with wave.open("models/computer-en.wav", "r") as wf:
    # Get audio data containing 16-bit 16khz PCM audio data from a file, microphone, network stream, etc.
    # For the best efficiency and latency, audio frames should be multiples of 80 ms, with longer frames
    # increasing overall efficiency at the cost of detection latency
    frame = wf.readframes(CHUNK_SIZE)

    # Get predictions for the frame
    prediction = model.predict(frame)

And result is:

/home/vdybala/.local/lib/python3.12/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py:69: UserWarning: Specified provider 'CUDAExecutionProvider' is not in available provider names.Available providers: 'AzureExecutionProvider, CPUExecutionProvider'
  warnings.warn(

How to specify CPUExecutionProvider?

dibalavs commented 1 month ago

By some reasons pip installed version 0.4.0. When I try install most modern version 0.6.0 I got an error:

pip install openwakeword==0.6.0 --break-system-packages
Defaulting to user installation because normal site-packages is not writeable
Collecting openwakeword==0.6.0
  Using cached openwakeword-0.6.0-py3-none-any.whl.metadata (29 kB)
Requirement already satisfied: onnxruntime<2,>=1.10.0 in /home/vdybala/.local/lib/python3.12/site-packages (from openwakeword==0.6.0) (1.19.2)
Requirement already satisfied: tqdm<5.0,>=4.0 in /home/vdybala/.local/lib/python3.12/site-packages (from openwakeword==0.6.0) (4.66.5)
Requirement already satisfied: scipy<2,>=1.3 in /usr/lib/python3/dist-packages (from openwakeword==0.6.0) (1.11.4)
Requirement already satisfied: scikit-learn<2,>=1 in /home/vdybala/.local/lib/python3.12/site-packages (from openwakeword==0.6.0) (1.5.2)
Requirement already satisfied: requests<3,>=2.0 in /usr/lib/python3/dist-packages (from openwakeword==0.6.0) (2.31.0)
INFO: pip is looking at multiple versions of openwakeword to determine which version is compatible with other requirements. This could take a while.
ERROR: Could not find a version that satisfies the requirement tflite-runtime<3,>=2.8.0; platform_system == "Linux" (from openwakeword) (from versions: none)
ERROR: No matching distribution found for tflite-runtime<3,>=2.8.0; platform_system == "Linux"
dscripka commented 1 month ago

What version of Python are you using? It looks like tflite-runtime only has pre-built WHLs up to Python 3.11, otherwise you will get this error.

And you shouldn't need to specify the Execution provider, it will choose CPU automatically when appropriate.