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

fix:add hotwords kwarg #154

Merged
merged 1 commit into from
Oct 24, 2024
Merged

fix:add hotwords kwarg #154

merged 1 commit into from
Oct 24, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 24, 2024

handle mic hickups, docstrs say they may return None but we throw an exception when that happens

Summary by CodeRabbit

  • New Features

    • Enhanced configurability for the voice service with optional microphone and bus parameters.
    • New hotword loading controls added, allowing for better management of hotword engine reloading.
  • Bug Fixes

    • Improved error handling during audio processing to prevent failures from missing audio data.
  • Documentation

    • Updated method signatures to reflect new parameters and functionality.

handle mic hickups, docstrs say they may return None but we throw an exception when that happens
@github-actions github-actions bot added the fix label Oct 24, 2024
Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in this pull request enhance the OVOSDinkumVoiceService, HotwordContainer, and DinkumVoiceLoop classes across several files. Key modifications include the addition of optional parameters for microphone and bus configurations, improved hotword management, and refined error handling in audio processing. The constructor signatures have been updated to accommodate new parameters, enhancing configurability. The overall structure is improved for better maintainability and robustness, particularly in handling audio interruptions and hotword engine lifecycle management.

Changes

File Change Summary
ovos_dinkum_listener/service.py Updated OVOSDinkumVoiceService constructor to include optional mic and bus parameters. Enhanced hotword handling and error logging.
ovos_dinkum_listener/voice_loop/hotwords.py Modified HotwordContainer constructor to add reload_allowed and autoload parameters. Improved control over hotword engine reloading.
ovos_dinkum_listener/voice_loop/voice_loop.py Altered audio processing in DinkumVoiceLoop to handle missing audio more robustly, replacing assertion with conditional checks.

Possibly related PRs

  • fix:save utterances #148: Modifies the OVOSDinkumVoiceService class in ovos_dinkum_listener/service.py, focusing on STT functionality and error handling, directly related to the main PR.
  • fix:handle empty string transcriptions #150: Updates the OVOSDinkumVoiceService class in ovos_dinkum_listener/service.py, addressing STT processing and empty string transcriptions, aligning with enhancements in the main PR.

Suggested reviewers

  • goldyfruit

Poem

🐇 In the meadow where voices sing,
Changes made, oh what joy they bring!
Hotwords dance and loops now flow,
With every tweak, our skills will grow.
So hop along, let’s celebrate,
For voice and sound, we elevate! 🎶


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added fix and removed fix labels Oct 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
ovos_dinkum_listener/voice_loop/hotwords.py (2)

100-102: LGTM! Consider adding parameter documentation.

The new parameters reload_allowed and autoload enhance control over hotword engine lifecycle, which could help prevent microphone interruptions. The implementation looks correct.

Consider adding docstring documentation for the new parameters:

def __init__(self, bus=FakeBus(), expected_duration=3, sample_rate=16000,
             sample_width=2, reload_allowed=True, autoload=False):
    """
    @param reload_allowed: If False, prevents reloading of already loaded hotword engines
    @param autoload: If True, automatically loads hotword engines during initialization
    """

Also applies to: 110-111


Line range hint 279-293: Consider enhancing microphone data handling.

While the changes help prevent unnecessary reloads that could cause mic interruptions, the update method could be enhanced to handle None chunks from the microphone.

Consider adding explicit None handling:

 def update(self, chunk: bytes):
     """
     Update appropriate engines based on self.state
     @param chunk: bytes of audio to feed to hotword engines
     """
+    if chunk is None:
+        LOG.debug("Received None chunk from microphone, skipping update")
+        return
     self.audio_buffer.append(chunk)
     if self.state == HotwordState.LISTEN:
         engines = self.listen_words.values()
🧰 Tools
🪛 Ruff

99-99: Do not perform function call FakeBus in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

ovos_dinkum_listener/voice_loop/voice_loop.py (1)

210-212: Consider keeping the warning with DEBUG level.

The change from assertion to conditional check improves robustness by handling None chunks gracefully. However, completely removing the warning message reduces observability of microphone issues.

 if chunk is None:
-    #LOG.warning("No audio from microphone")
+    LOG.debug("No audio from microphone")
     continue
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fed6e67 and fd868a7.

📒 Files selected for processing (3)
  • ovos_dinkum_listener/service.py (7 hunks)
  • ovos_dinkum_listener/voice_loop/hotwords.py (1 hunks)
  • ovos_dinkum_listener/voice_loop/voice_loop.py (1 hunks)
🔇 Additional comments (7)
ovos_dinkum_listener/voice_loop/voice_loop.py (1)

210-212: LGTM! The changes improve robustness.

The replacement of the assertion with a conditional check successfully addresses the microphone interruption issue while maintaining the integrity of the voice loop state machine.

ovos_dinkum_listener/service.py (6)

157-158: Addition of mic and bus parameters enhances configurability

The inclusion of optional mic and bus parameters in the constructor allows for more flexible instantiation of OVOSDinkumVoiceService, facilitating easier testing and integration with custom microphone and bus instances.


163-163: Addition of hotwords parameter improves hotword management

Introducing the optional hotwords parameter enables custom hotword configurations through the HotwordContainer instance, enhancing control over the hotword engine's lifecycle.


200-201: Initialize hotwords and vad with provided instances or defaults

The code correctly initializes self.hotwords and self.vad using the provided instances or defaults, ensuring modularity and allowing for custom implementations if needed.


202-203: Wrap non-streaming STT instances with FakeStreamingSTT

Wrapping non-streaming STT instances with FakeStreamingSTT ensures compatibility by providing a uniform streaming interface within the voice loop.


207-207: Verify the logic of disable_hotword_reload

Setting self.disable_hotword_reload to hotwords is not None means that hotword reloading is disabled when a hotwords instance is provided. Please confirm that this behavior aligns with the intended functionality.


1140-1140: Conditional hotword reload respects disable_hotword_reload flag

The conditional check ensures that hotwords are reloaded only when disable_hotword_reload is False and the hotword configuration has changed, preventing unnecessary reloads.

ovos_dinkum_listener/voice_loop/hotwords.py Show resolved Hide resolved
ovos_dinkum_listener/voice_loop/voice_loop.py Show resolved Hide resolved
ovos_dinkum_listener/service.py Show resolved Hide resolved
@JarbasAl JarbasAl merged commit e658ac0 into dev Oct 24, 2024
11 checks passed
@JarbasAl JarbasAl deleted the fix/misc branch October 24, 2024 06:01
This was referenced Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant