-
Notifications
You must be signed in to change notification settings - Fork 251
Predictions just add up? #111
Copy link
Copy link
Closed
Description
Hello! I am new to using openWakeWord and I coded my own script based off of the streaming_server.py snippet provided in the examples folder. I created an API endpoint using flask and following all the rules of openWakeWord but I don't get desired outputs. My model works perfectly on all of the snippets provided in the examples folder so I'm wondering now is this an issue with me or an openWakeWord issue? Also just to state, I am new to Python.
Steps:
- I speak saying "Hey, Grape" and I get no predictions >= 0.5
- I speak saying "Hey, Grape" and I get no predictions >= 0.5
- I speak saying "Hey, Grape" and I get no predictions >= 0.5
- Usually on the 4th or 5th time I do get a prediction and its very short as you can see in the code provided below I have logs and after it finally gets detected everything else i say after that will be the same exact prediction and it only logs 1 prediction.
- Everything I say after I get a prediction >= 0.5 will be the same exact prediction of the first >= 0.5.
What can i do!
from flask import Flask, request, jsonify
import numpy as np
from openwakeword import Model
import resampy
import wave
import io
app = Flask(__name__)
model_path = "C:/Users/clap/Desktop/wake/hey_grape.onnx"
owwModel = Model(wakeword_models=[model_path], inference_framework='onnx')
@app.route('/detect', methods=['POST'])
def detect_wakeword():
try:
audio_data = request.get_data()
with io.BytesIO(audio_data) as audio_stream:
with wave.open(audio_stream, 'rb') as wf:
sample_rate = wf.getframerate()
chunk_size = 1280
detected = False
while True:
chunk = wf.readframes(chunk_size)
if not chunk:
break
if len(chunk) % 2 == 1:
chunk += b'\x00'
data = np.frombuffer(chunk, dtype=np.int16)
if sample_rate != 16000:
data = resampy.resample(data, sample_rate, 16000)
predictions = owwModel.predict(data)
for key in predictions:
print(predictions[key])
if predictions[key] >= 0.5:
detected = True
break
if detected:
break
return jsonify({"detected": detected})
except Exception as e:
print(f"Error: {e}")
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels