deepgram-python-sdk
deepgram-python-sdk copied to clipboard
[HOLD] Reintroduce TTS WS
Proposed changes
Reintroduce TTS WS
Types of changes
What types of changes does your code introduce to the community Python SDK?
Put an x in the boxes that apply
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Documentation update or tests (if none of the other choices apply)
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
- [ ] I have read the CONTRIBUTING doc
- [ ] I have lint'ed all of my code using repo standards
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added necessary documentation (if appropriate)
Further comments
Walkthrough
The recent updates to the Deepgram SDK integrate WebSocket capabilities across multiple modules, enabling real-time streaming and communication for text-to-speech applications. New WebSocket client classes, response handlers, and utility functions have been introduced. Import statements have been reorganized, and example scripts demonstrating the new functionalities have been added, enhancing the overall public API.
Changes
| Files | Change Summary |
|---|---|
deepgram/__init__.py, deepgram/client.py, deepgram/clients/__init__.py, deepgram/clients/speak/__init__.py |
Uncommented and reorganized WebSocket-related import statements, enhancing module functionality and public API clarity. |
deepgram/clients/speak/client.py, deepgram/clients/speak/v1/websocket/client.py |
Introduced WebSocket client classes (SpeakWebSocketClient, AsyncSpeakWebSocketClient), enabling real-time TTS communication. |
deepgram/clients/speak/v1/websocket/response.py, deepgram/clients/speak/v1/websocket/options.py, deepgram/clients/speak/v1/websocket/helpers.py |
Added utility functions and data classes for managing WebSocket messages and configurations, improving response handling. |
deepgram/clients/speak/v1/websocket/async_client.py |
Implemented the AsyncSpeakWebSocketClient class for asynchronous WebSocket interactions, enhancing real-time TTS capabilities. |
deepgram/clients/speak/v1/websocket/__init__.py |
Established the WebSocket module structure by importing essential components, laying the groundwork for WebSocket features. |
examples/* |
Introduced multiple example scripts demonstrating real-time TTS using WebSocket connections, showcasing new functionality. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant WebSocket
participant DeepgramAPI
Client->>WebSocket: Connect
WebSocket->>DeepgramAPI: Establish WebSocket connection
DeepgramAPI-->>WebSocket: Connection established
WebSocket-->>Client: Connection open
Client->>WebSocket: Send TTS text
WebSocket->>DeepgramAPI: Process text for TTS
DeepgramAPI-->>WebSocket: Return audio data
WebSocket-->>Client: Send audio data
Client->>Client: Play audio
Client->>WebSocket: Close connection
WebSocket->>DeepgramAPI: Close WebSocket connection
DeepgramAPI-->>WebSocket: Connection closed
WebSocket-->>Client: Connection closed
Possibly related issues
- deepgram/deepgram-python-sdk#427: This issue discusses the inability to process subsequent audio chunks sent through the WebSocket connection. The recent changes enhance WebSocket communication handling, which may address the underlying cause of this issue.
[!TIP]
Announcements
- The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
- We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
- Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
- Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
- Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).
Recent review details
Configuration used: CodeRabbit UI Review profile: CHILL
Commits
Files that changed from the base of the PR and between 4cc5bec1b34cd04c5ac75367f3e2c7265e8480df and 78c207bf41a12f993de04d2892a1a465da98372c.
Files selected for processing (31)
- deepgram/init.py (3 hunks)
- deepgram/audio/init.py (1 hunks)
- deepgram/audio/microphone/constants.py (1 hunks)
- deepgram/audio/microphone/microphone.py (10 hunks)
- deepgram/audio/speaker/init.py (1 hunks)
- deepgram/audio/speaker/constants.py (1 hunks)
- deepgram/audio/speaker/errors.py (1 hunks)
- deepgram/audio/speaker/speaker.py (1 hunks)
- deepgram/client.py (2 hunks)
- deepgram/clients/init.py (2 hunks)
- deepgram/clients/listen/v1/websocket/async_client.py (12 hunks)
- deepgram/clients/listen/v1/websocket/client.py (10 hunks)
- deepgram/clients/speak/init.py (1 hunks)
- deepgram/clients/speak/client.py (3 hunks)
- deepgram/clients/speak/enums.py (2 hunks)
- deepgram/clients/speak/v1/init.py (1 hunks)
- deepgram/clients/speak/v1/rest/init.py (1 hunks)
- deepgram/clients/speak/v1/rest/options.py (1 hunks)
- deepgram/clients/speak/v1/websocket/init.py (1 hunks)
- deepgram/clients/speak/v1/websocket/async_client.py (1 hunks)
- deepgram/clients/speak/v1/websocket/client.py (1 hunks)
- deepgram/clients/speak/v1/websocket/helpers.py (1 hunks)
- deepgram/clients/speak/v1/websocket/options.py (3 hunks)
- deepgram/clients/speak/v1/websocket/response.py (1 hunks)
- deepgram/options.py (4 hunks)
- examples/requirements-examples.txt (1 hunks)
- examples/speech-to-text/rest/url/main.py (1 hunks)
- examples/text-to-speech/websocket/async_complete/main.py (1 hunks)
- examples/text-to-speech/websocket/complete/main.py (1 hunks)
- examples/text-to-speech/websocket/simple/main.py (1 hunks)
- tests/unit_test/test_unit_async_listen_websocket.py (1 hunks)
Files skipped from review due to trivial changes (5)
- deepgram/audio/speaker/init.py
- deepgram/audio/speaker/constants.py
- deepgram/clients/speak/v1/rest/init.py
- deepgram/clients/speak/v1/websocket/init.py
- deepgram/clients/speak/v1/websocket/response.py
Files skipped from review as they are similar to previous changes (19)
- deepgram/audio/init.py
- deepgram/audio/microphone/constants.py
- deepgram/audio/microphone/microphone.py
- deepgram/audio/speaker/errors.py
- deepgram/client.py
- deepgram/clients/listen/v1/websocket/async_client.py
- deepgram/clients/listen/v1/websocket/client.py
- deepgram/clients/speak/init.py
- deepgram/clients/speak/client.py
- deepgram/clients/speak/v1/rest/options.py
- deepgram/clients/speak/v1/websocket/async_client.py
- deepgram/clients/speak/v1/websocket/client.py
- deepgram/clients/speak/v1/websocket/helpers.py
- deepgram/clients/speak/v1/websocket/options.py
- deepgram/options.py
- examples/requirements-examples.txt
- examples/speech-to-text/rest/url/main.py
- examples/text-to-speech/websocket/async_complete/main.py
- examples/text-to-speech/websocket/complete/main.py
Additional context used
Learnings (3)
deepgram/clients/speak/v1/__init__.py (6)
Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/listen/v1/websocket/__init__.py:8-8 Timestamp: 2024-07-01T19:21:39.778Z Learning: Unused imports in `deepgram/clients/listen/v1/websocket/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:11-11 Timestamp: 2024-07-01T19:14:53.172Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:14-14 Timestamp: 2024-07-01T19:14:41.918Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:10-10 Timestamp: 2024-07-01T19:14:59.869Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility, even if they are flagged as unused.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/__init__.py:16-19 Timestamp: 2024-07-01T19:12:57.715Z Learning: Unused imports in `deepgram/clients/speak/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#424 File: deepgram/client.py:81-81 Timestamp: 2024-06-27T00:06:01.811Z Learning: Imports for SpeakStreamClient and AsyncSpeakStreamClient in `deepgram/client.py` are necessary for export purposes and should not be flagged as unused in reviews.deepgram/clients/__init__.py (6)
Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/listen/v1/websocket/__init__.py:8-8 Timestamp: 2024-07-01T19:21:39.778Z Learning: Unused imports in `deepgram/clients/listen/v1/websocket/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:11-11 Timestamp: 2024-07-01T19:14:53.172Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:14-14 Timestamp: 2024-07-01T19:14:41.918Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:10-10 Timestamp: 2024-07-01T19:14:59.869Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility, even if they are flagged as unused.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#431 File: deepgram/clients/listen/v1/websocket/client.py:30-30 Timestamp: 2024-07-11T14:10:17.231Z Learning: The `LiveOptions` import in `deepgram/clients/listen/v1/websocket/client.py` is intentionally present for future use and should not be flagged for removal in reviews.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/__init__.py:16-19 Timestamp: 2024-07-01T19:12:57.715Z Learning: Unused imports in `deepgram/clients/speak/__init__.py` are retained for backward compatibility and should not be flagged for removal in reviews.deepgram/__init__.py (5)
Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/listen/v1/websocket/__init__.py:8-8 Timestamp: 2024-07-01T19:21:39.778Z Learning: Unused imports in `deepgram/clients/listen/v1/websocket/__init__.py` are retained to maintain backward compatibility and should not be flagged for removal in reviews.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:11-11 Timestamp: 2024-07-01T19:14:53.172Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:14-14 Timestamp: 2024-07-01T19:14:41.918Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#426 File: deepgram/clients/speak/v1/websocket/__init__.py:10-10 Timestamp: 2024-07-01T19:14:59.869Z Learning: User dvonthenen prefers to retain unused imports in the codebase to maintain backward compatibility, even if they are flagged as unused.Learnt from: dvonthenen PR: deepgram/deepgram-python-sdk#431 File: deepgram/clients/listen/v1/websocket/client.py:30-30 Timestamp: 2024-07-11T14:10:17.231Z Learning: The `LiveOptions` import in `deepgram/clients/listen/v1/websocket/client.py` is intentionally present for future use and should not be flagged for removal in reviews.
Additional comments not posted (15)
deepgram/clients/speak/v1/__init__.py (1)
7-7: LGTM!The changes to import statements are approved.
The learnings confirm that unused imports should be retained for backward compatibility, so there is no need to flag them for removal.
Also applies to: 12-14, 21-37
deepgram/clients/speak/enums.py (1)
10-19: LGTM!The new
SpeakWebSocketMessageclass is a great addition to enumerate the message types that can be received from the Deepgram API. It enhances the structure and clarity of handling specific message types within the API integration.examples/text-to-speech/websocket/simple/main.py (3)
21-88: LGTM!The changes to the
mainfunction significantly enhance the structure and functionality of the application, moving from a simple synchronous model to a more capable asynchronous event-driven model. The new implementation provides a more robust and efficient way of handling WebSocket events and sending text for speech synthesis.Some key improvements include:
- Setting up a WebSocket connection using the
deepgram.speak.websocket.v("1")method, enabling event-driven handling of WebSocket events.- Sending the text to be converted to speech using the
send_textmethod.- Explicitly flushing the connection if the
auto_flush_speak_deltaoption is not utilized.- Improved error handling to catch
ValueErrorand generic exceptions, providing feedback on any issues encountered during execution.Overall, these changes greatly enhance the functionality and reliability of the application.
9-14: LGTM!The introduction of the
DeepgramClientandDeepgramClientOptionsclasses is a great addition to the codebase. These classes facilitate the configuration of the Deepgram client with options such as verbosity levels, providing a more structured and flexible way of customizing the client behavior.This change enhances the maintainability and extensibility of the codebase by allowing for easy configuration of the Deepgram client based on specific requirements.
Also applies to: 23-29
34-48: LGTM!The introduction of dedicated callback functions (
on_open,on_binary_data,on_close) to manage WebSocket events is a great improvement in the code structure. This change provides a more organized and efficient way of handling these events, enhancing the readability and maintainability of the codebase.By separating the event handling logic into distinct functions, the code becomes more modular and easier to understand, as each function focuses on a specific event and its corresponding actions.
deepgram/clients/__init__.py (1)
110-110: LGTM!The changes to enable WebSocket-related imports are approved.
Based on the learnings, the user prefers to retain unused imports for backward compatibility. Therefore, the changes should not be flagged for removal.
Also applies to: 116-116, 130-146
deepgram/__init__.py (1)
106-106: LGTM!The changes to enable WebSocket-related imports are approved.
Based on the learnings, the user prefers to retain unused imports for backward compatibility. Therefore, the changes should not be flagged for removal.
Also applies to: 111-111, 125-141, 185-207
tests/unit_test/test_unit_async_listen_websocket.py (1)
115-115: LGTM!The change to use an asynchronous check for the connection status in the while loop is approved.
Awaiting the connection status using
await dg_connection.is_connected()is crucial for proper handling of asynchronous operations. The loop will now correctly pause execution until the connection status is resolved, which is important in an asynchronous context. This change enhances the reliability of the connection check within the loop.deepgram/audio/speaker/speaker.py (7)
275-280: This code segment has been previously reviewed and the comment is still valid. Please refer to the past review comment for more details.
193-200: LGTM!The code changes are approved.
202-222: LGTM!The code changes are approved.
223-242: LGTM!The code changes are approved.
244-252: LGTM!The code changes are approved.
253-293: LGTM!The code changes are approved.
295-306: LGTM!The code changes are approved.
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?
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>.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
@coderabbitaiin 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
@coderabbitaiin 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 generate interesting stats about this repository and render them as a table.@coderabbitai show all the console.log statements in this repository.@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 pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.