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:b64 improvements #107

Merged
merged 4 commits into from
Oct 23, 2024
Merged

fix:b64 improvements #107

merged 4 commits into from
Oct 23, 2024

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Oct 23, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced text-to-speech (TTS) service initialization with additional configuration options.
    • Improved control over fallback behavior during TTS execution.
    • Added a parameter to indicate whether a user response is expected during TTS execution.
  • Bug Fixes

    • Resolved issues related to TTS reloading and fallback management.
  • Documentation

    • Updated method signatures for clarity and better understanding of functionality.

Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in the ovos_audio/service.py file enhance the PlaybackService class by adding new parameters to its constructor, updating method signatures with return type annotations, and modifying several methods to improve functionality and configurability. Notable updates include the introduction of tts and disable_fallback parameters, adjustments to TTS execution methods to include a listen parameter, and enhancements to type clarity across various methods.

Changes

File Change Summary
ovos_audio/service.py - Updated __init__ to accept tts: Optional[TTS] and disable_fallback: bool.
- Added return type annotations for _maybe_reload_tts, execute_tts, is_speaking, _resolve_sound_uri, and _path_from_hexdata.
- Modified _maybe_reload_tts to check disable_reload and disable_fallback.
- Updated execute_tts, handle_speak, and handle_b64_audio to include a listen parameter.

Poem

In the land of audio, where rabbits play,
New tunes are crafted, brightening the day.
With TTS now flexible, and fallback in tow,
We hop to the rhythm, let our voices flow!
So here’s to the changes, a joyful delight,
In the world of sound, everything feels right! 🐇🎶


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 23, 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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8e51f38 and 3a93639.

📒 Files selected for processing (1)
  • ovos_audio/service.py (11 hunks)
🧰 Additional context used

JarbasAl and others added 3 commits October 23, 2024 15:45
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@github-actions github-actions bot added fix and removed fix labels Oct 23, 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: 0

🧹 Outside diff range and nitpick comments (2)
ovos_audio/service.py (2)

57-59: LGTM! Constructor changes improve flexibility and type safety.

The addition of tts and disable_fallback parameters enhances configurability and testability. Type hints improve code clarity.

Consider adding docstring parameters for the new arguments:

 def __init__(self, ready_hook=on_ready, error_hook=on_error,
              stopping_hook=on_stopping, alive_hook=on_alive,
              started_hook=on_started, watchdog=lambda: None,
              bus=None, disable_ocp=None, validate_source=True,
              tts: Optional[TTS] = None,
              disable_fallback: bool = False):
+    """
+    Args:
+        tts: Optional TTS instance for dependency injection
+        disable_fallback: If True, disables fallback TTS loading
+    """

Also applies to: 74-79


282-294: Consider adding error handling for file operations.

While the changes improve the API and file handling, consider adding error handling for file operations to gracefully handle potential I/O errors.

-with open(str(wav), "rb") as f:
-    audio = f.read()
-
-b64_audio = base64.b64encode(audio).decode("utf-8")
-self.bus.emit(message.response({"audio": b64_audio,
-                                "listen": listen,
-                                'tts_id': self.tts.plugin_id,
-                                "utterance": utterance}))
+try:
+    with open(str(wav), "rb") as f:
+        audio = f.read()
+    b64_audio = base64.b64encode(audio).decode("utf-8")
+    self.bus.emit(message.response({"audio": b64_audio,
+                                   "listen": listen,
+                                   'tts_id': self.tts.plugin_id,
+                                   "utterance": utterance}))
+except IOError as e:
+    LOG.error(f"Failed to read audio file: {e}")
+    self.bus.emit(message.response({"error": str(e)}))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3a93639 and b6ffa8b.

📒 Files selected for processing (1)
  • ovos_audio/service.py (11 hunks)
🧰 Additional context used
🔇 Additional comments (3)
ovos_audio/service.py (3)

Line range hint 350-376: LGTM! Improved TTS reload logic with better control flow.

The addition of early returns for disabled reload and fallback scenarios improves code readability and provides better control over TTS behavior.


471-471: LGTM! Type annotations improve code clarity.

The addition of return type hints to _resolve_sound_uri, _path_from_hexdata, and _get_tts_fallback methods improves code clarity and maintainability.

Also applies to: 485-485, 414-414


451-453: Previous review comment about protected member access is still applicable.

The concern about accessing the protected member _now_playing of playback object remains valid.

@JarbasAl JarbasAl merged commit 29ab229 into dev Oct 23, 2024
6 checks passed
@JarbasAl JarbasAl deleted the b64 branch October 23, 2024 15:57
@coderabbitai coderabbitai bot mentioned this pull request Oct 23, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 30, 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