Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change event order handling to most freq to least, all elif #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.1

-- change event handling order to most frequent to least, all elif, found one, stop looking for more"
-- upgrade wyoming to 1.6.0


## 1.0.0

- Initial release
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pymicro-wakeword==1.0.0
wyoming==1.5.4
wyoming==1.6.0
51 changes: 25 additions & 26 deletions wyoming_microwakeword/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,8 @@ def __init__(
_LOGGER.debug("Client connected: %s", self.client_id)

async def handle_event(self, event: Event) -> bool:
if Describe.is_type(event.type):
wyoming_info = self._get_info()
await self.write_event(wyoming_info.event())
_LOGGER.debug("Sent info to client: %s", self.client_id)
return True

if Detect.is_type(event.type):
detect = Detect.from_event(event)
self.models.clear()
if detect.names:
for name in detect.names:
try:
self.models.add(Model(name))
except ValueError:
_LOGGER.warning("Unknown model name: %s", name)
elif AudioStart.is_type(event.type):
if not self.models:
# Default
self.models.add(DEFAULT_MODEL)

self.detectors = [
Detector(name=m.value, mww=MicroWakeWord.from_builtin(m))
for m in self.models
]
_LOGGER.debug("Loaded models: %s", self.models)
elif AudioChunk.is_type(event.type):
if AudioChunk.is_type(event.type):
chunk = self.converter.convert(AudioChunk.from_event(event))
for detector in self.detectors:
if detector.mww.process_streaming(chunk.audio):
Expand All @@ -142,7 +118,6 @@ async def handle_event(self, event: Event) -> bool:
await self.write_event(
Detection(name=detector.name, timestamp=chunk.timestamp).event()
)

elif AudioStop.is_type(event.type):
# Inform client if not detections occurred
if not any(d.detected for d in self.detectors):
Expand All @@ -152,6 +127,30 @@ async def handle_event(self, event: Event) -> bool:
_LOGGER.debug(
"Audio stopped without detection from client: %s", self.client_id
)
elif AudioStart.is_type(event.type):
if not self.models:
# Default
self.models.add(DEFAULT_MODEL)

self.detectors = [
Detector(name=m.value, mww=MicroWakeWord.from_builtin(m))
for m in self.models
]
_LOGGER.debug("Loaded models: %s", self.models)
elif Detect.is_type(event.type):
detect = Detect.from_event(event)
self.models.clear()
if detect.names:
for name in detect.names:
try:
self.models.add(Model(name))
except ValueError:
_LOGGER.warning("Unknown model name: %s", name)
elif Describe.is_type(event.type):
wyoming_info = self._get_info()
await self.write_event(wyoming_info.event())
_LOGGER.debug("Sent info to client: %s", self.client_id)

else:
_LOGGER.debug("Unexpected event: type=%s, data=%s", event.type, event.data)

Expand Down