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

Reintroduce TTS WS #258

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

dvonthenen
Copy link
Contributor

@dvonthenen dvonthenen commented Jul 15, 2024

Proposed changes

Reintroduce TTS WS

Types of changes

What types of changes does your code introduce to the community Go 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

NA

Summary by CodeRabbit

  • New Features

    • Introduced Text-to-Speech functionality using WebSocket with new examples for both simple and interactive usage.
    • Added WebSocket client implementation for Deepgram API, enabling streaming text-to-speech capabilities.
    • Defined new constants for improved WebSocket communication.
  • Documentation

    • Updated README with new Text-to-Speech WebSocket links and examples, enhancing clarity and accessibility.
  • Bug Fixes

    • Restored functionality by uncommenting a line in the WebSocket API.
  • Chores

    • Introduced new files to define constants and types for WebSocket communication.

Copy link

coderabbitai bot commented Jul 15, 2024

Walkthrough

The changes enhance the Text-to-Speech (TTS) functionality by integrating WebSocket connections for real-time audio generation from text. This update includes new example implementations, callback handlers, and WebSocket clients for communication with the Deepgram API. Additionally, constants for managing WebSocket interactions have been established, and the README has been updated to provide comprehensive guidance on leveraging these new features.

Changes

Files/Directories Change Summary
README.md Expanded to include WebSocket functionalities for TTS with links to the Speak REST Client, API, and examples.
docs.go Uncommented an import line for the WebSocket API under the speak package.
examples/.../interactive/main.go, examples/.../simple/main.go Developed interactive and simple TTS examples using a callback structure to handle WebSocket responses.
pkg/client/speak/v1/websocket/constants.go, pkg/client/speak/v1/websocket/new_using_callbacks.go Introduced constants for WebSocket interactions and functions for creating WebSocket connections with callback handlers for TTS services.
pkg/client/listen/v1/websocket/client_callback.go Modified message inspection methods to focus on listening events and improved error handling for closed sockets.
tests/unit_test/prerecorded_test.go Minor cosmetic change in a constant string for formatting.

Sequence Diagram(s)

Text-to-Speech WebSocket Communication Flow

sequenceDiagram
    participant User
    participant Client
    participant WebSocket
    participant DeepgramAPI
    
    User->>Client: Initialize TTS library
    Client->>WebSocket: Create WebSocket client
    WebSocket->>DeepgramAPI: Connect to Deepgram API
    
    User->>Client: Send text for TTS
    Client->>WebSocket: Send text message
    WebSocket->>DeepgramAPI: Forward text message
    
    DeepgramAPI->>WebSocket: Return audio data
    WebSocket->>Client: Receive audio data
    Client->>User: Provide audio output
    
    DeepgramAPI->>WebSocket: Send end of stream
    WebSocket->>Client: Receive end of stream
    Client->>User: Notify completion
Loading

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>.
    • 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 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 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.

Copy link

@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: 10

Outside diff range, codebase verification and nitpick comments (2)
examples/text-to-speech/websocket/simple/main.go (1)

83-138: Review of main function.

The main function is well-structured and provides a clear flow for initializing the TTS client, connecting, sending text, and handling user input. However, consider adding error logs or handling mechanisms for the os.Exit(1) call to provide more context on failures.

-		fmt.Println("Client.Connect failed")
+		fmt.Println("Client.Connect failed: ensure API key and server availability")
pkg/api/speak/v1/websocket/router.go (1)

185-195: Debug Message Printing

The printDebugMessages method is a utility function for logging formatted JSON messages. It's a helpful tool for debugging, but ensure that it's not called excessively in production to avoid log flooding.

Consider adding a configuration to toggle this detailed logging based on the environment or operational mode.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8287a80 and d11c946.

Files selected for processing (14)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/default.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/router.go (1 hunks)
  • pkg/client/speak/client.go (2 hunks)
  • pkg/client/speak/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • docs.go
  • pkg/api/speak/v1/websocket/constants.go
Additional context used
Learnings (4)
pkg/api/speak/v1/websocket/interfaces/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/client/speak/v1/websocket/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/client/speak/client.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/api/speak/v1/websocket/default.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#239
File: pkg/api/speak-stream/v1/default.go:187-211
Timestamp: 2024-06-17T23:10:23.450Z
Learning: The `UnhandledEvent` method in the `DefaultCallbackHandler` from the `pkg/api/speak-stream/v1/default.go` file is intended for demonstration purposes only and not used in production environments.
LanguageTool
README.md

[style] ~45-~45: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (41)
pkg/api/speak/v1/websocket/interfaces/constants.go (1)

10-17: Constants for WebSocket message types are well-defined.

The constants for different message types such as Open, Metadata, Flushed, Close, Warning, and Error are clearly defined and appropriately named. This is crucial for maintaining clarity and consistency in message handling across the WebSocket interface.

Verify consistent usage of these constants.

Verification successful

Constants for WebSocket message types are consistently used across the codebase.

The constants TypeOpenResponse, TypeMetadataResponse, TypeFlushedResponse, TypeCloseResponse, TypeWarningResponse, and TypeErrorResponse are consistently used in various parts of the codebase, ensuring clarity and uniformity in handling WebSocket message types.

  • pkg/client/speak/v1/websocket/client.go
  • pkg/client/listen/v1/websocket/client.go
  • pkg/api/speak/v1/websocket/router.go
  • pkg/api/live/v1/interfaces/constants.go
  • pkg/api/listen/v1/websocket/router.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all defined message types are consistently used across the codebase.

# Test: Search for the constants usage. Expect: Consistent usage across all files.
rg --type go -A 5 $'TypeOpenResponse|TypeMetadataResponse|TypeFlushedResponse|TypeCloseResponse|TypeWarningResponse|TypeErrorResponse'

Length of output: 7008

pkg/api/speak/v1/websocket/interfaces/interfaces.go (1)

9-21: Interface for WebSocket message handling is well-defined.

The SpeakMessageCallback interface provides a structured way to handle different types of WebSocket messages, including open, metadata, flush, close, warning, error, and binary data. This is crucial for ensuring that all message types are handled appropriately in the WebSocket communication.

Verify implementation of this interface.

Verification successful

Verify implementation of SpeakMessageCallback interface.

The SpeakMessageCallback interface is referenced in multiple files, but we need to verify its actual implementations to ensure consistency. Let's search for the concrete types that implement this interface.


Verify implementation of SpeakMessageCallback interface.

The previous attempt to find implementations of the SpeakMessageCallback interface failed due to a syntax error. Let's search for the implementations of each method in the interface individually.


Interface for WebSocket message handling is well-defined and implemented consistently.

The SpeakMessageCallback interface is implemented across various files, including examples, tests, and actual implementation files. This confirms that the interface is well-defined and consistently used throughout the codebase.

  • Implementations found in:
    • examples/text-to-speech/websocket/simple/main.go
    • examples/text-to-speech/websocket/interactive/main.go
    • examples/speech-to-text/websocket/microphone/main.go
    • tests/edge_cases/reconnect_client/main.go
    • pkg/api/speak/v1/websocket/default.go
    • pkg/api/listen/v1/websocket/default.go
    • pkg/api/speak/v1/websocket/router.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `SpeakMessageCallback` interface is implemented consistently across the codebase.

# Test: Search for the interface implementation. Expect: Consistent implementation across all files.
rg --type go -A 5 $'SpeakMessageCallback'

Length of output: 6853


Script:

#!/bin/bash
# Description: Search for the implementations of the `SpeakMessageCallback` interface.

# Test: Find all types that implement the `SpeakMessageCallback` interface.
ast-grep --lang go --pattern 'type $_ struct { $$$ }' --pattern 'func ($_ $_) Open($_) error { $$$ }' --pattern 'func ($_ $_) Metadata($_) error { $$$ }' --pattern 'func ($_ $_) Flush($_) error { $$$ }' --pattern 'func ($_ $_) Close($_) error { $$$ }' --pattern 'func ($_ $_) Warning($_) error { $$$ }' --pattern 'func ($_ $_) Error($_) error { $$$ }' --pattern 'func ($_ $_) Binary($_) error { $$$ }'

Length of output: 570


Script:

#!/bin/bash
# Description: Search for the implementations of the `SpeakMessageCallback` interface by looking for each method individually.

# Search for the implementation of the `Open` method.
ast-grep --lang go --pattern 'func ($_ $_) Open($_) error { $$$ }'

# Search for the implementation of the `Metadata` method.
ast-grep --lang go --pattern 'func ($_ $_) Metadata($_) error { $$$ }'

# Search for the implementation of the `Flush` method.
ast-grep --lang go --pattern 'func ($_ $_) Flush($_) error { $$$ }'

# Search for the implementation of the `Close` method.
ast-grep --lang go --pattern 'func ($_ $_) Close($_) error { $$$ }'

# Search for the implementation of the `Warning` method.
ast-grep --lang go --pattern 'func ($_ $_) Warning($_) error { $$$ }'

# Search for the implementation of the `Error` method.
ast-grep --lang go --pattern 'func ($_ $_) Error($_) error { $$$ }'

# Search for the implementation of the `Binary` method.
ast-grep --lang go --pattern 'func ($_ $_) Binary($_) error { $$$ }'

Length of output: 35551

pkg/client/speak/v1/websocket/types.go (1)

18-34: Struct for WebSocket client is appropriately defined.

The Client struct is well-structured with fields for client options, speak options, buffer channels, context for cancellation, mutex for concurrency control, WebSocket connection, retry logic, and callbacks. This struct is central to managing WebSocket connections and should be robust and efficient.

Verify usage of the Client struct.

Verification successful

Struct for WebSocket client is appropriately defined.

The Client struct is well-structured with fields for client options, speak options, buffer channels, context for cancellation, mutex for concurrency control, WebSocket connection, retry logic, and callbacks. This struct is central to managing WebSocket connections and should be robust and efficient.

Verified usage of the Client struct.

The Client struct is used consistently and correctly across the codebase, ensuring that the implementation is robust and reliable.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `Client` struct is used consistently and correctly across the codebase.

# Test: Search for the `Client` struct usage. Expect: Consistent and correct usage across all files.
rg --type go -A 5 $'Client'

Length of output: 142284

pkg/client/speak/v1/websocket/constants.go (1)

12-57: Constants and error variables for WebSocket communication are well-defined.

The constants for package version, retry logic, chunk size, termination sleep, socket errors, and message types are clearly defined and appropriately named. Additionally, error variables for invalid input, invalid connection, and fatal panic recovery are well-defined, which is crucial for robust error handling in WebSocket communication.

Verify consistent usage of constants and error variables.

Verification successful

Constants and error variables for WebSocket communication are well-defined and consistently used.

The constants for package version, retry logic, chunk size, termination sleep, socket errors, and message types are clearly defined and appropriately named. Additionally, error variables for invalid input, invalid connection, and fatal panic recovery are well-defined and consistently used throughout the codebase, ensuring robust error handling in WebSocket communication.

  • pkg/client/speak/v1/websocket/constants.go
  • pkg/audio/replay/replay.go
  • pkg/client/speak/client.go
  • pkg/api/speak/v1/speak.go
  • pkg/client/speak/v1/rest/constants.go
  • pkg/client/speak/v1/websocket/client.go
  • pkg/api/listen/v1/websocket/constants.go
  • pkg/api/listen/v1/websocket/client.go
  • pkg/client/listen/v1/websocket/client.go
  • pkg/client/analyze/v1/constants.go
  • pkg/client/analyze/v1/client.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all defined constants and error variables are consistently used across the codebase.

# Test: Search for the constants and error variables usage. Expect: Consistent usage across all files.
rg --type go -A 5 $'PackageVersion|DefaultConnectRetry|ChunkSize|TerminationSleep|FatalReadSocketErr|FatalWriteSocketErr|UseOfClosedSocket|UnknownDeepgramErr|SuccessfulSocketErr|MessageTypeSpeak|MessageTypeFlush|MessageTypeReset|MessageTypeClose|ErrInvalidInput|ErrInvalidConnection|ErrFatalPanicRecovered'

Length of output: 30901

pkg/api/speak/v1/websocket/interfaces/types.go (5)

28-30: Introduced MessageType struct.

The MessageType struct is well-defined and uses appropriate JSON tags for unmarshalling. This is crucial for correctly interpreting WebSocket messages.


34-36: Introduced MetadataResponse struct.

The MetadataResponse struct is designed to encapsulate metadata about TTS requests. The use of omitempty in JSON tags is appropriate here, as it allows for optional fields which can be omitted if not set.


40-42: Introduced FlushedResponse struct.

The struct correctly represents the server's response after flushing the buffer. The use of omitempty for optional fields is consistent with best practices.


46-47: Introduced OpenResponse struct.

This struct is crucial for handling the initial connection response. The structure is simple and correctly annotated for JSON parsing.


51-52: Introduced CloseResponse struct.

This struct is used to handle the closing of a connection. The JSON annotation is correct and consistent with other response types.

examples/text-to-speech/websocket/simple/main.go (1)

28-52: Review of MyCallback methods.

Each method in MyCallback handles different types of WebSocket messages. The error handling within these methods is appropriate, ensuring that any file operations or message processing errors are caught and returned. This is crucial for robust error management in production environments.

examples/text-to-speech/websocket/interactive/main.go (1)

29-83: Review of MyCallback methods in interactive mode.

The callback methods handle different types of responses effectively. The inclusion of user prompts in the Flush method enhances interactivity, which is a key feature of this example. Proper error handling is maintained throughout.

pkg/client/speak/client.go (1)

91-146: Review of WebSocket client functions.

The newly introduced WebSocket client functions are well-documented and provide a clear interface for setting up WebSocket connections with various configurations. The use of default handlers and the option to pass a custom cancel function are good practices that offer flexibility to the SDK users.

pkg/api/speak/v1/websocket/router.go (6)

18-22: Class Definition: MessageRouter

The MessageRouter struct is well-defined, holding a callback interface and a debug flag. This setup is clear and maintains a single responsibility principle by focusing solely on message routing.


24-36: Constructor Methods: NewWithDefault and NewStream

Both methods provide flexibility in initializing the MessageRouter with either default or custom callbacks. The use of environment variables to control debugging is practical but ensure that this doesn't lead to unexpected behaviors in different environments.


38-51: Message Handling Methods

Methods like OpenHelper, CloseHelper, and ErrorHelper are concise and delegate the processing to the callback interface. This is a clean approach, ensuring that the router class does not get bloated with logic specific to message handling.


70-94: Specific Message Processors

Methods like processFlushed, processMetadata, etc., are well-implemented. They follow a consistent structure which aids in maintainability. Each method unmarshals the message, checks for errors, and then processes the message through a generic handler.


161-174: Binary Message Handling

The Binary method is succinct and delegates processing to the callback. This is an example of good separation of concerns.


176-183: Unhandled Message Logging

The method for handling unhandled messages logs the event, which is essential for debugging. Ensure that this method does not swallow messages that should otherwise cause the system to alert or fail.

Verification successful

Unhandled Message Logging

The UnhandledMessage method logs unhandled messages and propagates the error, ensuring that the system can alert or fail as needed. The error is logged and returned by the calling functions, confirming that the system does not swallow these messages.

  • pkg/api/speak/v1/websocket/router.go
  • pkg/api/listen/v1/websocket/router.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that unhandled messages are logged appropriately and do not cause system instability.
rg --type go -A 5 $'UnhandledMessage'

Length of output: 2687


Script:

#!/bin/bash
# Search for calls to the UnhandledMessage method and check how the ErrInvalidMessageType error is handled.
rg --type go 'UnhandledMessage' -A 10

Length of output: 3982

pkg/api/speak/v1/websocket/default.go (2)

19-25: Constructor method looks good.

The constructor for DefaultCallbackHandler is straightforward and correct.


120-124: Binary data handling is efficient and straightforward.

The Binary method is simple and handles binary data efficiently, logging the byte count.

README.md (2)

42-45: Updated Documentation Links for TTS WebSocket

The added links provide necessary documentation for the newly introduced TTS WebSocket functionality. This is crucial for users to understand and utilize the new features effectively.

Tools
LanguageTool

[style] ~45-~45: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)


161-164: Added Examples for TTS WebSocket

The links to the newly added examples for TTS using WebSocket are correctly placed under the Text-to-Speech section. This helps users find practical usage examples easily.

pkg/client/speak/v1/websocket/client.go (19)

28-34: Type Definitions for WebSocket Messages

The controlMessage and TextSource types are well-defined with appropriate JSON tags. This ensures correct serialization and deserialization of WebSocket messages.


42-44: Function to Create WebSocket Connection for Demo Purposes

The function NewWebSocketForDemo simplifies the creation of a WebSocket connection with default options. This is useful for quick setup in demo or testing environments.


52-54: Function to Create WebSocket Connection with Default Callback

The function NewWebSocketWithDefaults provides a convenient way to establish a WebSocket connection using a default callback handler. This is beneficial for standard use cases where custom handling is not required.

Comprehensive WebSocket Connection Creation

The function NewWebSocket is well-structured, providing flexibility in specifying client and speak options, as well as a callback handler. The use of context cancellation is appropriately handled.


90-127: Robust WebSocket Connection Handling

This function handles the WebSocket connection with detailed logging and error handling. The use of context for cancellation and the structured approach to managing connection retries are best practices.


130-137: Simplified Connection Retry Logic

The method Connect encapsulates the retry logic for establishing a WebSocket connection. This simplifies the client code that needs to manage connection retries.


139-143: Connection Management with Custom Cancel Function

The ConnectWithCancel method allows for more granular control over the WebSocket connection process by allowing the caller to provide a custom cancel function.


145-150: Reconnection Logic with Context Management

The AttemptReconnect method provides a mechanism for attempting to reconnect after connection failures, utilizing a new context for each attempt. This is crucial for maintaining a stable connection in unstable network conditions.


152-156: Flexible Reconnection with Custom Cancel Function

The AttemptReconnectWithCancel extends the reconnection functionality by allowing the caller to pass a custom cancel function, providing additional flexibility in connection management.


162-298: Complex Connection Logic with Detailed Error Handling

This function demonstrates a complex but well-handled connection logic, including detailed error handling and logging. The use of a custom dialer with TLS configuration and header management is notable.


300-450: WebSocket Message Handling with Error Recovery

The listen function handles incoming WebSocket messages with robust error recovery and logging. The use of a recovery block to handle panics is a critical feature for maintaining service stability.


452-487: Methods for Sending Text and Binary Data

The methods SpeakWithText and SpeakWithStream provide interfaces for sending text and binary data over the WebSocket connection. The clear separation of concerns and error handling in these methods are well-implemented.


489-521: Binary Data Transmission Functionality

The WriteBinary method is crucial for sending binary data over the WebSocket. The locking mechanism ensures thread safety during the write operation.


523-564: JSON Payload Transmission Handling

The WriteJSON method handles the transmission of JSON payloads over the WebSocket. The error handling and data marshaling are effectively managed.


566-582: Flush Control Message Handling

The Flush method sends a control message to instruct the server to flush the current buffer. This is an essential feature for real-time data processing.


584-598: Reset Control Message Functionality

The Reset method allows the client to reset the current buffer on the server, which is useful in scenarios where a clean state is required.


601-623: Stream Closure Handling

The closeStream method manages the closure of the WebSocket stream with an optional lock parameter, providing flexibility in concurrent environments.


625-657: Normal Closure of WebSocket Connection

The normalClosure method sends a standard closure message to the WebSocket server. This method is critical for gracefully terminating the WebSocket connection.


659-706: Comprehensive Connection Termination Logic

The Stop and closeWs methods provide comprehensive logic for stopping and closing the WebSocket connection. The detailed logging and conditional checks ensure a smooth closure process.


708-745: Error Handling and Response Generation

The sendError and errorToResponse methods convert errors into structured responses that can be handled by the callback. This encapsulation of error handling into a response format is a good practice.

pkg/api/speak/v1/websocket/router.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/router.go Outdated Show resolved Hide resolved
examples/text-to-speech/websocket/interactive/main.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the reintroduce-tts-ws branch 2 times, most recently from 2b7e8f7 to 19be5f1 Compare August 9, 2024 01:52
Copy link

@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

Outside diff range, codebase verification and nitpick comments (10)
pkg/api/speak/v1/websocket/interfaces/types.go (2)

17-30: Improve the comment for MessageType.

The comment for MessageType could be more descriptive. Consider explaining its role in the context of the WebSocket communication.

- // MessageType is the header to bootstrap you way unmarshalling other messages
+ // MessageType is used to determine the type of message received over the WebSocket connection.

32-36: Inconsistent use of omitempty in JSON field tags.

The MessageType struct does not use omitempty in its JSON field tag, whereas other structs like MetadataResponse, FlushedResponse, OpenResponse, and CloseResponse do. To ensure consistency, consider applying omitempty uniformly across all struct JSON tags in the file.

  • MessageType struct at line 28 lacks omitempty.
Analysis chain

Ensure consistency in JSON field naming.

The MetadataResponse struct uses omitempty for JSON fields. Ensure consistency across all structs regarding the use of omitempty and JSON field naming conventions.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify JSON field naming consistency across all structs in the file.

# Test: Search for all struct definitions and check JSON tags. Expect: Consistent use of `omitempty`.
ast-grep --lang go --pattern 'type $_ struct { $$$ }' -- 'pkg/api/speak/v1/websocket/interfaces/types.go'

Length of output: 1391

pkg/client/speak/v1/websocket/constants.go (1)

24-27: Clarify socket error messages.

The socket error messages are defined as constants. Ensure these messages are clear and accurately describe the error conditions they represent.

- // socket errors
+ // Socket error messages used for identifying specific WebSocket error conditions.
pkg/client/interfaces/v1/options.go (1)

Line range hint 55-85:
Parsing logic for environment variables is sound.

The logic for parsing environment variables and setting options is correct. Ensure that error handling for parsing integers is robust, and consider logging errors if parsing fails.

+		if err != nil {
+			klog.V(1).Infof("Error parsing DEEPGRAM_WEBSOCKET_REPLY_AUTO_FLUSH: %v", err)
+		}
examples/text-to-speech/websocket/interactive/main.go (1)

120-158: Interactive input handling and connection closure are well-implemented.

The main function handles interactive input, buffer reset, flushing, and connection closure correctly. Error handling is present, providing informative messages in case of failure. Consider replacing goto with a cleaner control structure for better readability.

-			goto EXIT
+			break // Use break to exit the loop cleanly
examples/speech-to-text/websocket/microphone/main.go (1)

153-153: Incomplete Update to NewWS Detected

The transition from NewWebSocket to NewWS is incomplete. The following files still contain references to NewWebSocket and should be updated to maintain consistency:

  • tests/edge_cases/reconnect_client/main.go
  • tests/edge_cases/keepalive/main.go
  • tests/edge_cases/failed_retry/main.go
  • tests/edge_cases/cancel/main.go
  • tests/edge_cases/timeout/main.go
  • pkg/client/listen/client.go

Please ensure these instances are updated to prevent potential issues.

Analysis chain

Change to NewWS approved.

The change from NewWebSocket to NewWS aligns with the updated naming conventions. Ensure all usages of the old method are updated to prevent inconsistencies.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old method `NewWebSocket` are updated to `NewWS`.

# Test: Search for any remaining instances of `NewWebSocket`. Expect: No results.
rg --type go 'NewWebSocket'

Length of output: 3504

pkg/client/speak/client.go (3)

125-127: Update all references to NewWebSocket

The renaming of the function to NewWS has not been fully applied across the codebase. The following files still contain references to NewWebSocket and should be updated:

  • tests/edge_cases/timeout/main.go
  • tests/edge_cases/reconnect_client/main.go
  • tests/edge_cases/keepalive/main.go
  • tests/edge_cases/cancel/main.go
  • pkg/client/speak/v1/websocket/client.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client.go

Please ensure all instances are updated to maintain consistency.

Analysis chain

Renaming to NewWS approved.

The function NewWebSocket has been renamed to NewWS. This change enhances consistency in naming. Ensure all references to the old function name are updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old function `NewWebSocket` are updated to `NewWS`.

# Test: Search for any remaining instances of `NewWebSocket`. Expect: No results.
rg --type go 'NewWebSocket'

Length of output: 3504


97-99: Update references to NewWebSocketForDemo.

The function NewWebSocketForDemo still exists in pkg/client/listen/client.go. Please update these instances to NewWSForDemo to ensure consistency across the codebase.

  • pkg/client/listen/client.go: Function definition and comments.
Analysis chain

Renaming to NewWSForDemo approved.

The function NewWebSocketForDemo has been renamed to NewWSForDemo. This change improves naming consistency. Ensure all references to the old function name are updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old function `NewWebSocketForDemo` are updated to `NewWSForDemo`.

# Test: Search for any remaining instances of `NewWebSocketForDemo`. Expect: No results.
rg --type go 'NewWebSocketForDemo'

Length of output: 589


107-109: References to NewWebSocketWithDefaults still exist in the codebase.

The function NewWebSocketWithDefaults is still present and used in several places, including:

  • tests/edge_cases/timeout/main.go
  • pkg/client/listen/client.go

Please review these occurrences to determine if they should be updated to NewWSWithDefaults or if they are intentionally retained.

Analysis chain

Renaming to NewWSWithDefaults approved.

The function NewWebSocketWithDefaults has been renamed to NewWSWithDefaults. This change aligns with the new naming convention. Ensure all references to the old function name are updated.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old function `NewWebSocketWithDefaults` are updated to `NewWSWithDefaults`.

# Test: Search for any remaining instances of `NewWebSocketWithDefaults`. Expect: No results.
rg --type go 'NewWebSocketWithDefaults'

Length of output: 777

README.md (1)

44-47: Remove redundancy in "Speak API Interfaces".

The term "API Interfaces" is redundant. Consider using just "API" or "Interfaces".

-  - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
+  - Speak Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d11c946 and 19be5f1.

Files selected for processing (22)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/http/main.go (1 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/default.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/router.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (2 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/listen/client.go (4 hunks)
  • pkg/client/listen/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/client.go (2 hunks)
  • pkg/client/speak/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/websocket/replay/main.go
Additional context used
Learnings (4)
pkg/api/speak/v1/websocket/interfaces/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/api/speak/v1/websocket/constants.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/live/constants.go:0-0
Timestamp: 2024-06-21T20:19:48.143Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused and confirmed removed by user dvonthenen.
pkg/client/speak/v1/websocket/types.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/client/speak/v1/websocket/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
GitHub Check: Lint
pkg/client/speak/v1/websocket/constants.go

[failure] 62-62:
pingPeriod is unused (deadcode)

LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (45)
pkg/api/speak/v1/websocket/interfaces/constants.go (1)

1-18: Constants for TTS message types are well-defined.

The constants for message types received from the TTS streaming API are clear and appropriately named.

pkg/api/speak/v1/websocket/constants.go (1)

1-25: Package version and error variables are well-defined.

The package version and error variables are clearly defined and descriptive, which will aid in debugging and maintaining the code.

pkg/api/speak/v1/websocket/interfaces/interfaces.go (1)

1-21: SpeakMessageCallback interface is well-structured.

The SpeakMessageCallback interface effectively covers the necessary message types for TTS operations, ensuring comprehensive handling of both text and binary messages.

pkg/client/interfaces/v1/types-client.go (1)

25-26: Addition of AutoFlushSpeakDelta option.

The AutoFlushSpeakDelta option is a welcome addition for enabling auto-flush based on a delta in milliseconds for text-to-speech operations. Ensure this new option is correctly integrated and utilized in the codebase.

Verification successful

AutoFlushSpeakDelta option is integrated and utilized.

The AutoFlushSpeakDelta option is correctly integrated and utilized in the codebase, particularly in the pkg/client/speak/v1/websocket/client.go file, where it is actively used to manage auto-flush behavior. Additionally, it is referenced in the pkg/client/interfaces/v1/options.go and mentioned in the example code, indicating its configurability.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `AutoFlushSpeakDelta` in the codebase.

# Test: Search for the usage of `AutoFlushSpeakDelta`. Expect: Relevant usage in TTS implementations.
rg --type go 'AutoFlushSpeakDelta'

Length of output: 813

pkg/client/speak/v1/websocket/types.go (1)

24-45: Structure of Client for WebSocket TTS.

The Client struct is well-structured, supporting WebSocket TTS functionality with appropriate fields for options, callbacks, and connection management. Ensure consistent and correct usage across the codebase.

docs.go (1)

33-33: Uncommenting WebSocket API import.

Uncommenting the WebSocket API import enables WebSocket features from the Deepgram SDK, aligning with the reintroduction of TTS WebSocket functionality. Ensure that this change is consistent with the overall feature implementation.

pkg/api/speak/v1/websocket/interfaces/types.go (2)

14-14: Verify the external type SpeakOptions.

The SpeakOptions type is an alias for interfaces.SpeakOptions. Ensure that the external type is defined correctly and is suitable for use in this context.

Verification successful

The SpeakOptions type is correctly defined. The SpeakOptions struct is properly defined in pkg/client/interfaces/v1/types-speak.go, with fields that are suitable for its intended use. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition of `SpeakOptions` in the external package.

# Test: Search for the `SpeakOptions` type definition. Expect: Properly defined struct.
ast-grep --lang go --pattern 'type SpeakOptions struct { $$$ }' -- 'pkg/client/interfaces'

Length of output: 1075


54-58: Verify external types DeepgramWarning and DeepgramError.

The WarningResponse and ErrorResponse types are aliases for interfaces.DeepgramWarning and interfaces.DeepgramError. Verify their definitions to ensure they are appropriate for this context.

Verification successful

External types DeepgramWarning and DeepgramError are properly defined.

The DeepgramWarning and DeepgramError types are well-structured with fields suitable for handling warnings and errors, respectively. They are defined in pkg/client/interfaces/v1/utils.go and appear appropriate for their intended use in the context of response handling.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definitions of `DeepgramWarning` and `DeepgramError` in the external package.

# Test: Search for the type definitions. Expect: Properly defined structs or interfaces.
ast-grep --lang go --pattern 'type DeepgramWarning struct { $$$ }' -- 'pkg/client/interfaces'
ast-grep --lang go --pattern 'type DeepgramError struct { $$$ }' -- 'pkg/client/interfaces'

Length of output: 1193

pkg/client/speak/v1/websocket/constants.go (1)

33-45: Ensure message type constants are used appropriately.

The message type constants (MessageTypeSpeak, MessageTypeFlush, etc.) are defined for WebSocket communication. Verify that they are used consistently and appropriately in the codebase.

Verification successful

Message type constants are used appropriately in WebSocket communication.

The message type constants (MessageTypeSpeak, MessageTypeFlush, MessageTypeReset, MessageTypeClose) are consistently used in the client.go file for WebSocket operations, such as in switch cases and WriteJSON calls. This confirms their appropriate usage in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of message type constants in the codebase.

# Test: Search for occurrences of message type constants. Expect: Consistent usage in WebSocket communication.
rg --type go 'MessageType(Speak|Flush|Reset|Close)'

Length of output: 1128

examples/speech-to-text/websocket/test/main.go (1)

58-58: Verify the new method NewWS.

The method NewWS is used to create a Deepgram client. Ensure that this method is defined correctly and that its usage in this example is appropriate.

pkg/client/interfaces/v1/options.go (2)

66-84: Ensure consistent environment variable handling.

The renaming of DEEPGRAM_WEBSOCKET_AUTO_FLUSH to DEEPGRAM_WEBSOCKET_REPLY_AUTO_FLUSH and the addition of DEEPGRAM_WEBSOCKET_SPEAK_AUTO_FLUSH are clear and specific. Ensure that these changes are reflected throughout the codebase where these variables are used.

Verification successful

Environment variable usage is localized.

The environment variables DEEPGRAM_WEBSOCKET_REPLY_AUTO_FLUSH and DEEPGRAM_WEBSOCKET_SPEAK_AUTO_FLUSH are only used in pkg/client/interfaces/v1/options.go. There are no other references in the codebase, indicating that the changes are correctly isolated to this file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the renamed and new environment variables in the codebase.

# Test: Search for the usage of the renamed and new environment variables. Expect: Consistent usage throughout the codebase.
rg --type go 'DEEPGRAM_WEBSOCKET_REPLY_AUTO_FLUSH|DEEPGRAM_WEBSOCKET_SPEAK_AUTO_FLUSH'

Length of output: 710


89-97: Method renaming and addition are clear and purposeful.

The renaming of InspectMessage to InspectListenMessage and the addition of InspectSpeakMessage enhance clarity by explicitly distinguishing between listen and speak message inspections. Ensure that these methods are used appropriately throughout the codebase.

Verification successful

Method usage is consistent and appropriate.

The methods InspectListenMessage and InspectSpeakMessage are used correctly within the codebase, aligning with their intended purposes in the respective contexts of listening and speaking.

  • InspectListenMessage is used in pkg/client/listen/v1/websocket/client.go.
  • InspectSpeakMessage is used in pkg/client/speak/v1/websocket/client.go.

This confirms that the renaming and addition of methods enhance clarity without introducing inconsistencies.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the renamed and new methods in the codebase.

# Test: Search for the usage of the renamed and new methods. Expect: Consistent usage throughout the codebase.
rg --type go 'InspectListenMessage|InspectSpeakMessage'

Length of output: 627

examples/text-to-speech/websocket/simple/main.go (4)

7-22: Imports and constants are well-defined.

The imports are necessary for the functionality, and the constants TTS_TEXT and AUDIO_FILE are appropriately defined for the example.


24-80: Callback methods are correctly implemented.

The MyCallback struct implements methods for handling various WebSocket responses. Error handling is present, and the methods provide informative logging.


82-116: Setup and initialization in main function are correct.

The main function correctly initializes the library, sets client and TTS options, and establishes a WebSocket connection. Ensure that the API key and other sensitive information are handled securely in a real-world scenario.


118-138: Text input handling and connection closure are well-implemented.

The main function handles text input, flushing, and connection closure correctly. Error handling is present, providing informative messages in case of failure.

examples/text-to-speech/websocket/interactive/main.go (3)

7-24: Imports and constants are well-defined.

The imports are necessary for the functionality, and the constants API_KEY, TTS_TEXT, and AUDIO_FILE are appropriately defined for the example. Ensure that the API_KEY is securely managed in a real-world scenario.


26-83: Callback methods are correctly implemented.

The MyCallback struct implements methods for handling various WebSocket responses. Error handling is present, and the methods provide informative logging.


85-118: Setup and initialization in main function are correct.

The main function correctly initializes the library, sets client and TTS options, and establishes a WebSocket connection. Ensure that the API key is handled securely in a real-world scenario.

pkg/client/speak/client.go (1)

144-146: Renaming to NewWSWithCancel approved.

The function NewWebSocketWithCancel has been renamed to NewWSWithCancel. This change reflects the updated naming conventions. Ensure all references to the old function name are updated.

Verification successful

Renaming in pkg/client/speak/client.go verified.

The function NewWebSocketWithCancel in the pkg/client/speak/client.go file has been correctly renamed to NewWSWithCancel. The occurrences of NewWebSocketWithCancel found are in a different package (pkg/client/listen/client.go) and are unrelated to this change. No issues found with the renaming in the speak package.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all occurrences of the old function `NewWebSocketWithCancel` are updated to `NewWSWithCancel`.

# Test: Search for any remaining instances of `NewWebSocketWithCancel`. Expect: No results.
rg --type go 'NewWebSocketWithCancel'

Length of output: 890

pkg/api/speak/v1/websocket/router.go (3)

18-22: Introduction of MessageRouter approved.

The MessageRouter provides a clear structure for handling WebSocket events, enhancing maintainability and readability.


122-158: Consider handling unknown message types in Message method.

The Message method lacks a specific handling mechanism for unknown message types. Consider adding a default case to log or handle these cases more explicitly.


53-68: Review processGeneric method for redundancy.

The processGeneric method is well-structured but could be improved by passing msgType as part of the data interface to reduce redundancy.

pkg/api/speak/v1/websocket/default.go (7)

58-87: Refactor debug logging in Metadata method.

Apply the same refactor as suggested for the Open method to maintain consistency and reduce code duplication.


89-118: Refactor debug logging in Flush method.

Apply the refactor suggestion for debug logging to maintain consistency and reduce redundancy.


120-124: LGTM for Binary method.

The method correctly logs the size of received binary data.


126-155: Refactor debug logging in Close method.

Apply the refactor suggestion for debug logging to maintain consistency and reduce redundancy.


157-188: Refactor debug logging in Warning method.

Apply the refactor suggestion for debug logging to maintain consistency and reduce redundancy.


190-223: Refactor debug logging in Error method.

Apply the refactor suggestion for debug logging to maintain consistency and reduce redundancy.


225-249: Refactor debug logging in UnhandledEvent method.

Apply the refactor suggestion for debug logging to maintain consistency and reduce redundancy.

pkg/client/listen/client.go (4)

86-88: LGTM for NewWSForDemo.

The alias correctly calls the intended function and maintains functionality.


89-91: LGTM for NewWebSocketForDemo.

The wrapper correctly calls the new alias and maintains backward compatibility.


110-112: LGTM for NewWSWithDefaults.

The alias correctly calls the intended function and maintains functionality.


113-115: LGTM for NewWebSocketWithDefaults.

The wrapper correctly calls the new alias and maintains backward compatibility.

README.md (1)

215-218: LGTM for Text-to-Speech WebSocket examples.

The entries are clear and provide direct links to the relevant examples.

pkg/client/listen/v1/websocket/client.go (1)

423-426: Change to InspectListenMessage looks good.

The change to use InspectListenMessage() instead of InspectMessage() appears to align with the focus on listening functionality. Ensure that InspectListenMessage() is correctly implemented and used throughout the codebase.

Verification successful

InspectListenMessage is correctly implemented and used.

The method InspectListenMessage is defined in pkg/client/interfaces/v1/options.go and used appropriately in pkg/client/listen/v1/websocket/client.go. This confirms that the change aligns with the intended functionality.

  • Implementation: pkg/client/interfaces/v1/options.go
  • Usage: pkg/client/listen/v1/websocket/client.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation and usage of `InspectListenMessage`.

# Test: Search for the function definition and usage. Expect: Correct implementation and usage.
ast-grep --lang go --pattern 'func InspectListenMessage() $$_'

Length of output: 64


Script:

#!/bin/bash
# Search for any occurrences of `InspectListenMessage` in the codebase to verify its implementation or usage.
rg 'InspectListenMessage'

Length of output: 312

pkg/client/speak/v1/websocket/client.go (9)

42-44: NewForDemo function looks good.

The function correctly initializes a WebSocket connection with default options.


52-54: NewWithDefaults function looks good.

The function initializes a WebSocket connection with default options and a default callback handler.


70-73: New function looks good.

The function initializes a WebSocket connection with specified options and handles errors appropriately.


90-128: NewWithCancel function looks good.

The function correctly initializes a WebSocket connection with specified options and a custom cancel function.


130-137: Connect function looks good.

The function correctly manages WebSocket connection attempts with retries.


141-143: ConnectWithCancel function looks good.

The function provides flexibility in managing WebSocket connections with retries and cancellation.


146-150: AttemptReconnect function looks good.

The function correctly handles reconnection attempts after failures.


153-156: AttemptReconnectWithCancel function looks good.

The function provides flexibility for reconnection attempts with a custom cancel function.


305-455: listen function looks good.

The function handles message reading, processing, and error handling for the WebSocket connection effectively.

pkg/client/speak/v1/websocket/constants.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
Copy link

@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, codebase verification and nitpick comments (1)
README.md (1)

44-47: Clarify the terminology for API Interfaces.

The phrase "Speak API Interfaces" is redundant since "I" in "API" already stands for "Interfaces". Consider simplifying it to "Speak API".

-  - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
+  - Speak API - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 19be5f1 and 21591a5.

Files selected for processing (22)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/http/main.go (1 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/default.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/router.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (2 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/listen/client.go (4 hunks)
  • pkg/client/listen/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/client.go (2 hunks)
  • pkg/client/speak/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
Files skipped from review as they are similar to previous changes (19)
  • docs.go
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/websocket/microphone/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/interactive/main.go
  • examples/text-to-speech/websocket/simple/main.go
  • pkg/api/speak/v1/websocket/default.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/router.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-client.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client.go
  • pkg/client/speak/client.go
  • pkg/client/speak/v1/websocket/client.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (2)
README.md (2)

Line range hint 1-219:
Overall consistency and completeness check.

The updates to the README.md file are consistent with the existing structure and enhance the documentation by providing clear links and descriptions for new WebSocket and REST functionalities. Ensure that all links are functional and that any new features are adequately documented elsewhere in the repository.

Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)


215-218: Ensure example links are correct and descriptive.

The links to the WebSocket Simple Example and Interactive Websocket should be verified to ensure they direct to the correct examples. The descriptions should also reflect the content accurately.

Verification successful

Example links are correct and descriptive.

The links to the WebSocket Simple Example and Interactive Websocket in the README.md file correctly point to the existing main.go files in their respective directories. No further action is needed.

  • examples/text-to-speech/websocket/simple/main.go
  • examples/text-to-speech/websocket/interactive/main.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the example links in the README.md file are correct.

# Test: Check if the example files exist at the specified paths.
fd --type f --exact-depth 3 --glob 'main.go' --exec echo "Found: {}" --search-path examples/text-to-speech/websocket

Length of output: 116


Script:

#!/bin/bash
# Description: List all files under the examples/text-to-speech/websocket directory to verify existence.

# List all files in the specified directory to check for any existing files.
fd --type f --search-path examples/text-to-speech/websocket

Length of output: 164

Copy link

@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: 8

Outside diff range, codebase verification and nitpick comments (2)
README.md (1)

47-47: Style improvement: Simplify phrase.

The phrase "Speak API Interfaces" is redundant. Consider simplifying it to "Speak APIInterfaces" to avoid tautology.

Apply this diff to simplify the phrase:

-  - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
+  - Speak APIInterfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

pkg/client/speak/v1/websocket/client.go (1)

470-487: Consider logging additional details in SpeakWithText.

The function logs the text being sent but could include more context, such as timestamps or message IDs, for better traceability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 21591a5 and 9d30e76.

Files selected for processing (25)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/http/main.go (1 hunks)
  • examples/speech-to-text/websocket/microphone/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/default.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/router.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (1 hunks)
  • pkg/client/listen/client.go (4 hunks)
  • pkg/client/listen/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/websocket/client.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • examples/speech-to-text/websocket/http/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
Additional context used
Learnings (4)
pkg/client/speak/v1/websocket/types.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/client/speak/v1/websocket/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
pkg/client/speak/client.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
pkg/api/speak/v1/websocket/router.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: pkg/api/speak/v1/websocket/router.go:122-158
Timestamp: 2024-08-09T02:05:04.822Z
Learning: In the `MessageRouter` class, the default case in the `Message` method's switch statement intentionally passes messages to the user via the `UnhandledMessage` method when an unknown message type is encountered.
LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (58)
pkg/client/interfaces/interfaces.go (1)

20-20: LGTM! The type alias WSSpeakOptions is well-defined.

The introduction of WSSpeakOptions as an alias for interfacesv1.WSSpeakOptions is a clear and non-breaking change.

pkg/api/speak/v1/websocket/interfaces/interfaces.go (1)

8-21: LGTM! The SpeakMessageCallback interface is well-structured.

The interface provides a comprehensive set of methods for handling WebSocket messages, aligning with standard callback patterns.

pkg/api/version/speakstream-version.go (1)

32-32: LGTM! But verify the function usage in the codebase.

The change to use *interfaces.WSSpeakOptions aligns with the new WebSocket-specific options. The function logic remains intact.

However, ensure that all function calls to GetSpeakStreamAPI are updated to use the new options type.

Run the following script to verify the function usage:

Verification successful

Function usage is correct and aligned with the updated type. The GetSpeakStreamAPI function is called with sOptions of type *interfaces.WSSpeakOptions, which matches the expected type. No further updates are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `GetSpeakStreamAPI` match the new options type.

# Test: Search for the function usage. Expect: Only occurrences of the new options type.
rg --type go -A 5 $'GetSpeakStreamAPI'

Length of output: 1420


Script:

#!/bin/bash
# Search for the definition of `c.sOptions` in the client.go file to verify its type.
rg --type go 'sOptions' pkg/client/speak/v1/websocket/client.go -A 3 -B 3

Length of output: 2462

pkg/client/interfaces/v1/types-client.go (1)

20-26: LGTM! The categorization of client options enhances clarity.

The addition of AutoFlushSpeakDelta and the categorization of AutoFlushReplyDelta improve the semantic clarity of the ClientOptions struct.

pkg/client/speak/v1/websocket/types.go (1)

1-45: LGTM! The Client struct is well-organized for WebSocket communication.

The introduction of the Client struct and associated fields provides a clear structure for managing WebSocket connections for TTS.

docs.go (1)

33-33: LGTM! The WebSocket API for speech processing is now enabled.

Uncommenting the import statement aligns with the PR objectives to reintroduce TTS WebSocket functionality.

pkg/client/interfaces/v1/types-speak.go (1)

31-36: Verify consistency between WSSpeakOptions and SpeakOptions.

The WSSpeakOptions struct is similar to SpeakOptions, but it omits fields like Container, Callback, and CallbackMethod. Ensure that this is intentional and consistent with the intended functionality.

Run the following script to verify the usage and consistency of these structs across the codebase:

pkg/client/speak/v1/websocket/constants.go (1)

1-64: LGTM! Constants and error variables are well-defined.

The constants and error variables introduced for WebSocket communication are well-structured and cover various aspects of the functionality.

pkg/api/speak/v1/websocket/interfaces/types.go (1)

1-58: LGTM! Types for WebSocket responses are well-defined.

The types introduced for handling WebSocket responses are well-structured and align with expected communication patterns. The use of existing interfaces for WarningResponse and ErrorResponse is consistent and efficient.

pkg/client/interfaces/v1/options.go (3)

89-91: LGTM!

The InspectListenMessage method correctly checks the AutoFlushReplyDelta value.


94-96: LGTM!

The InspectSpeakMessage method correctly checks the AutoFlushSpeakDelta value.


127-132: LGTM!

The Check method for WSSpeakOptions is consistent with other no-op methods in the file.

examples/text-to-speech/websocket/simple/main.go (3)

27-31: LGTM!

The Metadata function correctly logs the metadata information.


53-55: LGTM!

The Flush function correctly logs the flushed message.


65-69: LGTM!

The Error function correctly logs the error information.

examples/text-to-speech/websocket/interactive/main.go (5)

29-33: LGTM!

The Metadata function correctly logs the metadata information.


55-58: LGTM!

The Flush function correctly logs the flushed message and user instructions.


68-72: LGTM!

The Error function correctly logs the error information.


75-77: LGTM!

The Close function correctly logs the close message.


143-155: Consider replacing goto with a loop break.

Using goto can make the code harder to read and maintain. Consider using a loop break instead.

Apply this diff to replace goto with a loop break:

	case "":
-		goto EXIT
+		break
Skipped due to learnings
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:0-0
Timestamp: 2024-08-09T02:05:27.945Z
Learning: In example code, the use of `goto` is acceptable for demonstration purposes, as clarified by the user.
examples/speech-to-text/websocket/microphone/main.go (1)

153-153: Verify compatibility of NewWS.

The change from client.NewWebSocket to client.NewWS suggests a refactoring. Ensure that NewWS is fully compatible with the existing logic and that all necessary parameters are correctly handled.

Run the following script to confirm that NewWS is correctly implemented and compatible:

Verification successful

NewWS is compatible with existing logic.

The NewWS function in pkg/client/listen/client.go correctly handles the parameters and is compatible with the existing logic in examples/speech-to-text/websocket/microphone/main.go. The function creates a context with cancellation and passes the expected parameters to another function, ensuring proper functionality.

  • pkg/client/listen/client.go: Correct handling of parameters for live transcription.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `NewWS`.

# Test: Search for the implementation of `NewWS`. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func NewWS($_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 913

pkg/client/speak/client.go (8)

11-16: Import statements are well-organized.

The import statements are clear and well-organized, reflecting the new structure of the package.


56-58: WebSocket client section is well-structured.

The WebSocket client section is clearly separated from the REST client, enhancing readability and maintainability.


Line range hint 143-173: Deprecation notice is clear.

The deprecation notice for legacy functions and types is clear, guiding users towards the new implementations.


30-36: Verify usage of NewStream.

The NewStream function is introduced for creating a MessageRouter with a user-defined callback. Ensure that this function is used correctly throughout the codebase.

Run the following script to verify the usage of NewStream:

Verification successful

Verify NewStream Implementation and Usage

The NewStream function is used appropriately in the codebase to create a MessageRouter with a user-defined callback. It is directly utilized in the following files:

  • pkg/client/speak/v1/websocket/client.go: Used to create a MessageRouter.
  • pkg/api/speak/v1/websocket/router.go: Used to return a MessageRouter with a default callback handler.

The function appears to handle parameters correctly and is used in the intended context. No issues were found with its usage.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewStream`.

# Test: Search for the usage of `NewStream`. Expect: Correct handling of parameters.
rg --type go -A 5 $'NewStream'

Length of output: 2135


82-98: Verify implementation of NewWSWithDefaults.

The NewWSWithDefaults function is introduced for creating a WebSocket connection with default options. Ensure that the implementation aligns with its intended purpose.

Run the following script to verify the implementation of NewWSWithDefaults:

Verification successful

Implementation of NewWSWithDefaults is correct.

The NewWSWithDefaults function correctly creates a WebSocket connection with default options by delegating to NewUsingCallbackWithDefaults, which sets up the client appropriately. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `NewWSWithDefaults`.

# Test: Search for the implementation of `NewWSWithDefaults`. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func NewWSWithDefaults($_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 747


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallbackWithDefaults` to verify its behavior.
ast-grep --lang go --pattern $'func NewUsingCallbackWithDefaults($_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 465


121-141: Verify implementation of NewWSWithCancel.

The NewWSWithCancel function is introduced for creating a WebSocket connection with cancellation facilities. Ensure that the implementation aligns with its intended purpose.

Run the following script to verify the implementation of NewWSWithCancel:

Verification successful

Implementation of NewWSWithCancel is verified and correct.

The NewWSWithCancel function correctly delegates to NewUsingCallbackWithCancel, which handles the parameters as expected, ensuring proper initialization and cancellation facilities. No issues found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `NewWSWithCancel`.

# Test: Search for the implementation of `NewWSWithCancel`. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func NewWSWithCancel($_, $_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 953


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallbackWithCancel` in the `speakv1ws` package.
ast-grep --lang go --pattern $'func NewUsingCallbackWithCancel($_, $_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 2870


66-80: Verify implementation of NewWSUsingCallbackForDemo.

The NewWSUsingCallbackForDemo function is introduced for creating a WebSocket connection with default options. Ensure that the implementation aligns with its intended purpose.

Run the following script to verify the implementation of NewWSUsingCallbackForDemo:

Verification successful

Implementation of NewWSUsingCallbackForDemo is verified.

The function correctly wraps around NewUsingCallbackForDemo, which in turn uses NewUsingCallback to handle the WebSocket connection setup with default options. The implementation aligns with the intended purpose.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `NewWSUsingCallbackForDemo`.

# Test: Search for the implementation of `NewWSUsingCallbackForDemo`. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func NewWSUsingCallbackForDemo($_, $_) ($_, $_) {
  $$$
}'

Length of output: 355


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallbackForDemo` in the codebase.
ast-grep --lang go --pattern 'func NewUsingCallbackForDemo($_, $_) ($_, $_) {
  $$$
}'

Length of output: 401


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallback` in the codebase.
ast-grep --lang go --pattern 'func NewUsingCallback($_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 594


100-119: Verify implementation of NewWS.

The NewWS function is introduced for creating a WebSocket connection with specified options. Ensure that the implementation aligns with its intended purpose.

Run the following script to verify the implementation of NewWS:

Verification successful

Implementation of NewWS is verified and correct.

The NewWS function correctly delegates to NewUsingCallback, which properly handles the parameters and options required to establish a WebSocket connection. The implementation aligns with its intended purpose.

  • pkg/client/speak/v1/websocket/client.go: The handling of API keys, options parsing, and callback setup is correctly implemented.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of `NewWS`.

# Test: Search for the implementation of `NewWS`. Expect: Correct handling of parameters.
ast-grep --lang go --pattern $'func NewWS($_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 913


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallback` in the codebase.
ast-grep --lang go --pattern $'func NewUsingCallback($_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 594


Script:

#!/bin/bash
# Search for the implementation of `NewUsingCallbackWithCancel` in the codebase.
ast-grep --lang go --pattern $'func NewUsingCallbackWithCancel($_, $_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 2870

pkg/api/speak/v1/websocket/router.go (7)

5-16: Imports are well-organized.

The import statements are clear and well-organized, reflecting the dependencies of the package.


18-22: MessageRouter structure is clear.

The MessageRouter structure is well-defined with appropriate fields for callback handling and debugging.


53-68: Generic message processing is efficient.

The processGeneric method efficiently abstracts the handling of different message types, reducing code duplication.


122-158: Main Message Router Method

The Message method is the central routing logic that delegates messages based on their type. The implementation is straightforward and handles different message types effectively. The intentional use of UnhandledMessage for unknown message types is noted.


161-174: Binary message handling is clear.

The Binary method effectively handles binary messages, ensuring proper callback execution.


176-183: Unhandled message handling is intentional.

The UnhandledMessage method intentionally logs and handles unexpected message types, as noted in previous learnings.


24-36: Verify usage of NewStream.

The NewStream function is introduced for creating a MessageRouter with a user-defined callback. Ensure that this function is used correctly throughout the codebase.

Run the following script to verify the usage of NewStream:

Verification successful

NewStream is used correctly throughout the codebase.

The NewStream function is utilized appropriately in the codebase with the expected parameters. The callback parameter is correctly handled in its usage. No issues were found regarding its implementation or usage.

  • pkg/client/speak/v1/websocket/client.go: Directly calls NewStream with a callback, which aligns with its definition.
  • pkg/api/speak/v1/websocket/router.go: Used within NewWithDefault.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `NewStream`.

# Test: Search for the usage of `NewStream`. Expect: Correct handling of parameters.
rg --type go -A 5 $'NewStream'

Length of output: 2135

pkg/api/speak/v1/websocket/default.go (6)

58-87: Apply the same refactor to Metadata method.

The Metadata method uses the same debug logic. Apply the suggested refactor for consistency.


89-118: Apply the same refactor to Flush method.

The Flush method uses the same debug logic. Apply the suggested refactor for consistency.


126-155: Apply the same refactor to Close method.

The Close method uses the same debug logic. Apply the suggested refactor for consistency.


157-188: Apply the same refactor to Warning method.

The Warning method uses the same debug logic. Apply the suggested refactor for consistency.


190-223: Apply the same refactor to Error method.

The Error method uses the same debug logic. Apply the suggested refactor for consistency.


225-249: Apply the same refactor to UnhandledEvent method.

The UnhandledEvent method uses the same debug logic. Apply the suggested refactor for consistency.

pkg/client/listen/client.go (4)

86-91: LGTM! Ensure backward compatibility for NewWebSocketForDemo.

The introduction of NewWSForDemo improves readability while maintaining backward compatibility through the wrapper function.


110-115: LGTM! Ensure backward compatibility for NewWebSocketWithDefaults.

The introduction of NewWSWithDefaults improves readability while maintaining backward compatibility through the wrapper function.


136-142: LGTM! Ensure backward compatibility for NewWebSocket.

The introduction of NewWS improves readability while maintaining backward compatibility through the wrapper function.


164-169: LGTM! Ensure backward compatibility for NewWebSocketWithCancel.

The introduction of NewWSWithCancel improves readability while maintaining backward compatibility through the wrapper function.

README.md (2)

44-47: Great documentation update for WebSocket under Text-to-Speech.

The new entries improve clarity and accessibility for users looking to utilize WebSocket capabilities.

Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)


215-219: Great addition of examples for Text-to-Speech over WebSocket.

The new examples enhance the documentation, providing clear guidance for users.

pkg/client/listen/v1/websocket/client.go (1)

423-423: Ensure the correctness of InspectListenMessage() usage.

The method InspectListenMessage() is now used instead of InspectMessage(). Verify that this change aligns with the intended logic and that InspectListenMessage() is correctly implemented.

Run the following script to verify the implementation of InspectListenMessage():

pkg/client/speak/v1/websocket/client.go (9)

70-73: Ensure proper error handling in NewUsingCallback.

The function NewUsingCallback initializes a WebSocket connection. Ensure that errors from NewUsingCallbackWithCancel are handled appropriately.


90-128: Review the initialization logic in NewUsingCallbackWithCancel.

The function initializes the client with options and a callback. Ensure that the initialization logic aligns with the intended design and that all parameters are correctly set.


130-137: Verify retry logic in Connect.

The Connect function attempts to establish a connection with retries. Ensure that the retry logic correctly handles connection failures.


305-455: Review error handling in listen.

The listen function handles WebSocket messages and errors. Ensure that all error cases are covered and that the connection is closed gracefully when needed.


618-634: Ensure Flush operation is correctly implemented.

The Flush function sends a flush command to the server. Verify that the server correctly handles this command and that the function behaves as expected.


636-651: Ensure Reset operation is correctly implemented.

The Reset function sends a reset command to the server. Verify that the server correctly handles this command and that the function behaves as expected.


832-841: Review error conversion in sendError.

The sendError function converts and sends errors. Ensure that the conversion logic correctly maps errors to the expected response format.


843-869: Review regex pattern in errorToResponse.

The regex pattern in errorToResponse extracts error details. Ensure that the pattern correctly matches all expected error formats.


871-899: Ensure message inspection logic in inspect.

The inspect function processes messages based on their type. Verify that the logic correctly handles all message types and performs the necessary actions.

pkg/client/interfaces/v1/types-speak.go Outdated Show resolved Hide resolved
pkg/client/interfaces/v1/options.go Show resolved Hide resolved
pkg/client/interfaces/v1/options.go Show resolved Hide resolved
examples/text-to-speech/websocket/simple/main.go Outdated Show resolved Hide resolved
examples/text-to-speech/websocket/simple/main.go Outdated Show resolved Hide resolved
examples/text-to-speech/websocket/interactive/main.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/default.go Outdated Show resolved Hide resolved
pkg/client/speak/v1/websocket/client.go Outdated Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the reintroduce-tts-ws branch 2 times, most recently from 16f7f74 to d4c8d1f Compare August 23, 2024 02:33
Copy link

@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: 1

Outside diff range, codebase verification and nitpick comments (22)
pkg/api/speak/v1/websocket/types.go (3)

16-27: Document the purpose of DefaultChanHandler.

The DefaultChanHandler struct holds channels for different message types. Consider adding comments to clarify the purpose and usage of each channel.


49-52: Clarify the purpose of DefaultCallbackHandler.

The DefaultCallbackHandler struct is minimal. Ensure that its purpose is clear and consider adding functionality or documentation if needed.


60-62: Deprecation notice for MessageRouter.

The MessageRouter type alias is marked as deprecated. Ensure that this deprecation is communicated clearly in documentation and consider removing it in future versions.

pkg/api/speak/v1/websocket/callback_default.go (3)

19-35: Consider adding documentation for NewDefaultCallbackHandler.

The function creates a new DefaultCallbackHandler with debug options based on environment variables. Adding a comment would improve code readability and maintainability.


112-116: Consider handling binary data more effectively in Binary.

The Binary method currently logs the length of the received binary data. Consider adding more detailed handling or processing of the binary data if applicable.


199-217: Consider adding documentation for UnhandledEvent.

The UnhandledEvent method handles unknown messages. Adding a comment would improve code readability and maintainability.

pkg/client/speak/v1/websocket/client_callback.go (15)

24-28: Consider adding documentation for Connect.

The Connect method initiates a WebSocket connection with retries. Adding a comment would improve code readability and maintainability.


30-36: Consider adding documentation for ConnectWithCancel.

The ConnectWithCancel method provides a cancel function for stopping the connection. Adding a comment would improve code readability and maintainability.


38-42: Consider adding documentation for AttemptReconnect.

The AttemptReconnect method attempts to reconnect after failing retries. Adding a comment would improve code readability and maintainability.


44-49: Consider adding documentation for AttemptReconnectWithCancel.

The AttemptReconnectWithCancel method provides a cancel function for stopping the reconnection. Adding a comment would improve code readability and maintainability.


51-60: Consider adding documentation for GetURL.

The GetURL method returns the WebSocket URL. Adding a comment would improve code readability and maintainability.


62-67: Consider adding documentation for Start.

The Start method initiates the callback with optional flushing. Adding a comment would improve code readability and maintainability.


104-133: Consider adding documentation for SpeakWithText.

The SpeakWithText method sends text to the WebSocket server for audio conversion. Adding a comment would improve code readability and maintainability.


135-138: Consider adding documentation for Speak.

The Speak method is an alias for SpeakWithText. Adding a comment would improve code readability and maintainability.


140-156: Consider adding documentation for Flush.

The Flush method instructs the server to flush the current text buffer. Adding a comment would improve code readability and maintainability.


158-172: Consider adding documentation for Reset.

The Reset method instructs the server to reset the current buffer. Adding a comment would improve code readability and maintainability.


175-178: Consider adding documentation for GetCloseMsg.

The GetCloseMsg method sends a close message to Deepgram. Adding a comment would improve code readability and maintainability.


180-183: Consider adding documentation for Finish.

The Finish method finalizes the callback. Adding a comment would improve code readability and maintainability.


196-259: Consider adding documentation for flush.

The flush method manages the flushing process with error recovery. Adding a comment would improve code readability and maintainability.


261-287: Consider adding documentation for errorToResponse.

The errorToResponse method converts errors into Deepgram error responses. Adding a comment would improve code readability and maintainability.


289-317: Consider adding documentation for inspect.

The inspect method checks message types for actionable items. Adding a comment would improve code readability and maintainability.

README.md (1)

47-47: Avoid Redundant Phrasing in Documentation.

The phrase "Speak API Interfaces" is redundant since "I" in "API" stands for "Interfaces." Consider simplifying it to "Speak API" for clarity.

Apply this diff to address the redundancy:

-  - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
+  - Speak API - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d30e76 and d4c8d1f.

Files selected for processing (27)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple/main.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (4 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (2)
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/client/listen/v1/websocket/constants.go
Files skipped from review as they are similar to previous changes (14)
  • docs.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/text-to-speech/websocket/interactive/main.go
  • examples/text-to-speech/websocket/simple/main.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-client.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/speak/client.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (30)
pkg/api/speak/v1/websocket/interfaces/interfaces.go (2)

11-17: Ensure consistent error handling in Router interface.

The Router interface defines methods for handling different types of messages. Ensure that all methods consistently handle errors and edge cases, especially in a real-time WebSocket environment.


22-36: Clarify the purpose of SpeakMessageChan interface.

The SpeakMessageChan interface uses slices of channels, which might indicate a need for broadcasting messages. Ensure this design aligns with the intended use case and consider documenting the rationale.

pkg/api/speak/v1/websocket/types.go (1)

30-42: Review the use of slices of channels in ChanRouter.

The ChanRouter uses slices of channels, which might indicate a need for broadcasting. Ensure this design aligns with the intended use case and consider documenting the rationale.

examples/speech-to-text/websocket/test/main.go (1)

58-60: Verify the transition to NewWSUsingChan.

The method for creating a Deepgram client has been updated. Ensure that this change aligns with the new API and that all necessary adjustments have been made throughout the code.

pkg/client/speak/v1/websocket/new_using_callbacks.go (4)

26-28: LGTM!

The function correctly creates a WebSocket connection with default options.


36-38: LGTM!

The function correctly creates a WebSocket connection with default options and a default callback handler.


54-57: LGTM!

The function correctly creates a WebSocket connection with specified options and a callback handler.


74-117: LGTM!

The function correctly handles API key assignment, option parsing, callback initialization, and WebSocket client creation.

pkg/client/listen/v1/websocket/new_using_callbacks.go (3)

122-124: LGTM!

The function is correctly marked as deprecated and delegates to NewUsingCallbackForDemo.


135-137: LGTM!

The function is correctly marked as deprecated and delegates to NewUsingCallbackWithDefaults.


151-153: LGTM!

The function is correctly marked as deprecated and delegates to NewUsingCallback.

pkg/api/speak/v1/websocket/callback_router.go (9)

19-21: LGTM!

The function correctly creates a CallbackRouter with the default callback handler.


24-33: LGTM!

The function correctly creates a CallbackRouter with a user-defined callback and handles the debug setting.


37-39: LGTM!

The function correctly handles the OpenResponse message by delegating to the callback.


42-44: LGTM!

The function correctly handles the CloseResponse message by delegating to the callback.


47-49: LGTM!

The function correctly handles the ErrorResponse message by delegating to the callback.


52-66: LGTM!

The function correctly generalizes the handling of all message types and logs the process.


68-117: LGTM!

The functions correctly handle specific message types by unmarshalling and delegating processing to processGeneric.


120-157: LGTM!

The function correctly handles platform messages and routes them based on the MessageType.


159-193: LGTM!

The functions correctly handle binary messages, log unhandled messages, and format debug messages.

pkg/api/speak/v1/websocket/callback_default.go (6)

37-60: Ensure consistent error handling in Open.

The Open method logs and returns errors when JSON marshaling fails. Consider adding more context to the error messages or handling them consistently across different methods.


62-85: Ensure consistent error handling in Metadata.

Similar to the Open method, ensure that error handling is consistent and provides sufficient context in the Metadata method.


87-110: Ensure consistent error handling in Flush.

The Flush method follows the same pattern as Open and Metadata. Consistency in error handling and logging is crucial.


118-141: Ensure consistent error handling in Close.

The Close method should maintain consistency in error handling and logging, similar to other methods.


143-168: Ensure consistent error handling in Warning.

The Warning method should follow the same error handling and logging practices as other methods.


170-197: Ensure consistent error handling in Error.

The Error method should maintain consistency in error handling and logging, similar to other methods.

pkg/client/speak/v1/websocket/client_callback.go (2)

69-102: Ensure consistent error handling in ProcessMessage.

The ProcessMessage method processes incoming messages and logs errors. Ensure consistency in error handling and logging practices.


185-194: Ensure consistent error handling in ProcessError.

The ProcessError method processes errors and logs them. Ensure consistency in error handling and logging practices.

pkg/client/listen/v1/websocket/client_callback.go (1)

78-81: Ensure the change to InspectListenMessage is intentional.

The modification narrows the focus of message inspection. Verify that this change aligns with the intended functionality and does not affect other message types.

pkg/client/listen/v1/websocket/client_channel.go (1)

78-78: Ensure Consistency with Method Naming.

The renaming of InspectMessage() to InspectListenMessage() suggests a more specific focus on listening events. Ensure that this change is reflected consistently throughout the codebase where this method is used.

Run the following script to verify the usage of InspectListenMessage:

Verification successful

Method Naming Consistency Verified

The method InspectListenMessage is consistently used throughout the codebase. No discrepancies were found in its usage.

  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/interfaces/v1/options.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `InspectListenMessage` are consistent.

# Test: Search for the function usage. Expect: Only occurrences of the new name.
rg --type go -A 5 $'InspectListenMessage'

Length of output: 1513

pkg/api/speak/v1/websocket/interfaces/interfaces.go Outdated Show resolved Hide resolved
Copy link

@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, codebase verification and nitpick comments (4)
examples/text-to-speech/websocket/interactive/main.go (2)

42-47: Consider using os.Create for file creation.

Using os.Create simplifies file creation by automatically truncating the file if it exists. However, since this is an example, the current implementation is acceptable.

-	file, err := os.OpenFile(AUDIO_FILE, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0o666)
+	file, err := os.Create(AUDIO_FILE)

149-149: Consider replacing goto with break.

The use of goto is generally discouraged as it can make the code harder to read and maintain. However, since this is an example, the current implementation is acceptable.

-			goto EXIT
+			break // Use break to exit the loop cleanly
pkg/api/listen/v1/websocket/callback_router.go (1)

185-189: Consider implementing or documenting the Binary method.

The Binary method is currently a placeholder with no implementation. If it's intended for future use, consider adding a comment to clarify its purpose or expected implementation.

 func (r *CallbackRouter) Binary(byMsg []byte) error {
+  // Placeholder for future binary message handling
  // No implementation needed on STT
  return nil
}
pkg/api/listen/v1/websocket/chan_router.go (1)

289-293: Consider implementing or documenting the Binary method.

The Binary method is currently a placeholder with no implementation. If it's intended for future use, consider adding a comment to clarify its purpose or expected implementation.

func (r *ChanRouter) Binary(byMsg []byte) error {
+  // Placeholder for future binary message handling
  // No implementation needed on STT
  return nil
}
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d4c8d1f and 3ba1e76.

Files ignored due to path filters (1)
  • examples/text-to-speech/websocket/simple/output.mp3 is excluded by !**/*.mp3
Files selected for processing (20)
  • examples/text-to-speech/websocket/interactive/main.go (1 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (11 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (2 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (4)
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
Files skipped from review as they are similar to previous changes (4)
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
Learnings (1)
examples/text-to-speech/websocket/interactive/main.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#239
File: examples/speak/stream/http/main.go:124-127
Timestamp: 2024-06-19T14:42:20.980Z
Learning: The `Connect` method in the `pkg/client/speak/client_stream.go` returns a boolean, and any errors during the connection are handled through the `Error` method in the `MyCallback` struct.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
Additional comments not posted (24)
pkg/api/listen/v1/websocket/interfaces/constants.go (4)

12-12: Consistent use of shared type.

The change to use commoninterfaces.TypeResponse enhances consistency across the codebase.


16-16: Consistent use of shared constant.

The change to use commoninterfaces.TypeOpenResponse aligns with the common interfaces.


22-22: Consistent use of shared constant.

The change to use commoninterfaces.TypeCloseResponse aligns with the common interfaces.


24-24: Consistent use of shared constant.

The change to use commoninterfaces.TypeErrorResponse aligns with the common interfaces.

pkg/client/common/v1/types.go (1)

39-39: Enhancement with routing capabilities.

The addition of the router field enhances the functionality of WSClient by integrating routing capabilities.

Ensure that the router field is properly initialized and used in the codebase.

Run the following script to verify the usage of the router field in the codebase:

Verification successful

Router field is properly initialized and used.

The router field in the WSClient struct is properly initialized and used throughout the codebase. It is integrated into the workflow with various methods and logging for error monitoring.

  • Initialization occurs in functions like NewWS.
  • Usage includes methods like Message, Binary, Close, and Error.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and usage of the `router` field in `WSClient`.

# Test: Search for the usage of the `router` field. Expect: Proper initialization and usage.
rg --type go 'router'

Length of output: 7199

pkg/api/speak/v1/websocket/interfaces/interfaces.go (2)

11-25: Consider unifying callback and channel interfaces.

The SpeakMessageChan interface mirrors the SpeakMessageCallback interface in functionality. Consider unifying or abstracting common logic to reduce redundancy and improve maintainability.


30-43: Consider unifying callback and channel interfaces.

The SpeakMessageCallback interface mirrors the SpeakMessageChan interface in functionality. Consider unifying or abstracting common logic to reduce redundancy and improve maintainability.

pkg/client/listen/v1/websocket/types.go (2)

54-54: Verify the impact of router refactoring.

The router field in WSChannel has been changed to use *commoninterfaces.Router. Ensure that this change is consistent with the intended refactoring and verify its impact on the routing logic.

Run the following script to verify the usage of WSChannel and ensure that the new router type is compatible:


37-37: Verify the impact of router refactoring.

The router field in WSCallback has been changed to use *commoninterfaces.Router. Ensure that this change is consistent with the intended refactoring and verify its impact on the routing logic.

Run the following script to verify the usage of WSCallback and ensure that the new router type is compatible:

Verification successful

Refactoring of router field in WSCallback is consistent and compatible.

The router field in WSCallback has been changed to use *commoninterfaces.Router, which is an interface with the necessary methods (Close, Error). Implementations like CallbackRouter and ChanRouter provide these methods, ensuring compatibility with the existing routing logic.

  • Router interface is defined in pkg/client/common/v1/interfaces/interfaces.go.
  • Implementations of Close and Error are found in CallbackRouter and ChanRouter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of WSCallback and ensure compatibility with the new router type.

# Test: Search for the usage of WSCallback. Expect: Compatibility with commoninterfaces.Router.
rg --type go -A 5 'WSCallback'

Length of output: 20255


Script:

#!/bin/bash
# Verify if `*commoninterfaces.Router` has the necessary methods (`Close`, `Error`) used in `WSCallback`.

# Search for the implementation of `Router` in `commoninterfaces`.
ast-grep --lang go --pattern 'type Router struct { $$$ }'

# Search for methods `Close` and `Error` in `commoninterfaces.Router`.
ast-grep --lang go --pattern 'func ($_ *Router) Close($_) $_ { $$$ }'
ast-grep --lang go --pattern 'func ($_ *Router) Error($_) $_ { $$$ }'

Length of output: 203


Script:

#!/bin/bash
# Use ripgrep to search for the definition of `Router` and its methods in the `commoninterfaces` package.

# Search for the definition of `Router`.
rg --type go 'type Router' -A 5

# Search for the `Close` method in `commoninterfaces.Router`.
rg --type go 'func (.*Router.*) Close'

# Search for the `Error` method in `commoninterfaces.Router`.
rg --type go 'func (.*Router.*) Error'

Length of output: 1244

pkg/client/common/v1/interfaces/interfaces.go (3)

14-16: LGTM!

The OpenResponse type is correctly defined with appropriate JSON serialization options.


19-21: LGTM!

The CloseResponse type is correctly defined with appropriate JSON serialization options.


29-35: LGTM!

The Router interface is correctly defined and provides a clear structure for handling WebSocket events.

pkg/client/listen/v1/websocket/new_using_chan.go (2)

92-92: Ensure compatibility with commoninterfaces.Router.

The router variable type has been changed to commoninterfaces.Router. Verify that this change is compatible with the rest of the codebase and that the new router interface provides the necessary functionality.


106-106: Verify common.NewWS integration with commoninterfaces.WebSocketHandler.

The handler variable type has been changed to commoninterfaces.WebSocketHandler. Ensure that the common.NewWS function correctly utilizes this new handler type and that it aligns with the expected behavior.

pkg/api/listen/v1/websocket/interfaces/types.go (3)

8-8: Ensure correct import of commoninterfaces.

The import statement for commoninterfaces has been added. Verify that this import is necessary and correctly used in the file.


83-84: Validate OpenResponse type aliasing.

The OpenResponse type is now an alias for commoninterfaces.OpenResponse. Ensure that this change is correct and that the commoninterfaces type provides the necessary fields and functionality.


126-127: Validate CloseResponse type aliasing.

The CloseResponse type is now an alias for commoninterfaces.CloseResponse. Ensure that this change is correct and that the commoninterfaces type provides the necessary fields and functionality.

pkg/api/listen/v1/websocket/callback_router.go (1)

170-170: Clarify the wrapping of TypeErrorResponse.

The wrapping of TypeErrorResponse in TypeResponse within the Message method might be for consistency. Ensure this change aligns with the intended design and doesn't introduce any unexpected behavior.

pkg/api/listen/v1/websocket/chan_router.go (3)

96-96: Transition to string-based message types.

The transition to using string for message types in processGeneric improves flexibility and consistency across the codebase. Ensure all related components are updated accordingly.

Also applies to: 120-120, 144-144, 178-178, 195-195, 212-212, 229-229, 246-246


148-148: Refactor processGeneric to use string for msgType.

The change to use string for msgType in processGeneric aligns with the overall transition in the file. This change enhances consistency and simplifies the handling of message types.


310-310: Refactor printDebugMessages to use string for function.

Changing the function parameter to string in printDebugMessages aligns with the transition to string-based message types, improving consistency.

pkg/client/common/v1/websocket.go (3)

Line range hint 25-42: Enhance NewWS with router integration.

The addition of the router parameter in NewWS enhances the WebSocket client's routing capabilities. Ensure that all necessary documentation and usage examples are updated to reflect this change.


200-207: Verify router integration in internalConnectWithCancel.

The integration of the router in internalConnectWithCancel enhances connection management. Verify that the Open method on the router is correctly implemented and doesn't introduce side effects.


546-552: Verify router integration in closeWs.

The integration of the router in closeWs ensures proper disconnection handling. Verify that the Close method on the router is correctly implemented and doesn't introduce side effects.

Copy link

@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, codebase verification and nitpick comments (5)
examples/text-to-speech/websocket/simple_callback/main.go (2)

24-87: Callback implementation is correct. Consider enhancing error handling.

The MyCallback struct correctly implements methods for handling WebSocket events. Consider enhancing error handling by using a logger instead of fmt.Printf for better control over log levels and outputs.


89-177: Main function is well-structured. Remove redundant file operation.

The main function is well-structured and correctly manages the WebSocket connection. However, the file operation for "output.wav" is redundant and can be removed to avoid confusion.

examples/text-to-speech/websocket/simple_channel/main.go (2)

25-217: Handler implementation is correct. Consider enhancing error handling.

The MyHandler struct correctly implements methods for handling WebSocket events. Consider enhancing error handling by using a logger instead of fmt.Printf for better control over log levels and outputs.


219-299: Main function is well-structured. Remove redundant file operation.

The main function is well-structured and correctly manages the WebSocket connection. However, the file operation for "output.wav" is redundant and can be removed to avoid confusion.

pkg/api/speak/v1/websocket/chan_default.go (1)

99-314: Consider using a consistent logging approach.

The function uses fmt.Printf for some logging, which could be replaced with klog for consistency.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3ba1e76 and e9cdbb0.

Files selected for processing (26)
  • .golangci.yaml (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/client/common/v1/types.go (2 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/listen/client.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (3 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (3)
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/types.go
Files skipped from review as they are similar to previous changes (11)
  • pkg/api/listen/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/speak/client.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
Learnings (3)
examples/text-to-speech/websocket/interactive_callback/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
examples/text-to-speech/websocket/simple_callback/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
examples/text-to-speech/websocket/simple_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
Additional comments not posted (49)
go.mod (1)

6-6: Verify the necessity of the replace directive.

The replace directive switches back to github.com/dvonthenen/websocket. Ensure this is necessary for compatibility or stability reasons.

Please confirm that the replace directive is required. If not, consider removing it to simplify dependency management.

Also applies to: 29-29

pkg/api/listen/v1/websocket/types.go (1)

Line range hint 39-39: Verify the impact of removing defaultHandler.

The defaultHandler field has been removed from the ChanRouter struct. Ensure that this change does not break existing functionality or event handling logic.

Please confirm that the removal of defaultHandler is intentional and does not affect the existing codebase. If necessary, update the documentation or code comments to reflect this change.

.golangci.yaml (1)

121-126: LGTM! Enhanced linting for duplicate code.

The addition of entries for the dupl linter improves code quality by checking for duplicate code in the specified files.

These changes are beneficial for maintaining code quality and consistency.

pkg/client/listen/v1/websocket/new_using_chan.go (4)

36-36: LGTM: Simplified parameter type.

The change from a pointer to a direct type for the chans parameter simplifies the interface and is appropriate here.


50-50: LGTM: Simplified parameter type.

The change from a pointer to a direct type for the chans parameter simplifies the interface and is appropriate here.


66-66: LGTM: Simplified parameter type.

The change from a pointer to a direct type for the chans parameter simplifies the interface and is appropriate here.


Line range hint 89-103: LGTM: Updated interface types.

The router and handler types have been updated to use commoninterfaces, which aligns with the new architecture.

Ensure that all usages of these interfaces are consistent with the new types.

Run the following script to verify the usage of these interfaces:

Verification successful

Consistent Usage of Updated Interfaces Verified

The usage of commoninterfaces.Router and commoninterfaces.WebSocketHandler is consistent across the codebase, aligning with the new architecture. No inconsistencies were found in the implementation.

  • Files verified include new_using_chan.go, types.go, and new_using_callbacks.go for both listen and speak packages.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of the updated interfaces.

# Test: Search for the usage of `Router` and `WebSocketHandler`. Expect: Consistent usage with `commoninterfaces`.
rg --type go -A 5 'commoninterfaces.Router|commoninterfaces.WebSocketHandler'

Length of output: 5671

pkg/client/speak/v1/websocket/new_using_chan.go (3)

25-27: LGTM: Default WebSocket connection.

The function correctly initializes a WebSocket connection with default options.


36-38: LGTM: Default WebSocket connection with chans.

The function correctly initializes a WebSocket connection with default options and handles the chans parameter.


66-109: LGTM: WebSocket connection with specified options.

The function correctly initializes a WebSocket connection with specified options and handles the chans parameter and context cancellation.

examples/text-to-speech/websocket/interactive_callback/main.go (5)

7-23: LGTM: Imports and constants.

The imports and constants are appropriate for the TTS functionality demonstrated in this example.


25-89: LGTM: Callback implementation.

The MyCallback type and its methods are correctly implemented, providing clear logging for each WebSocket event type.


91-110: LGTM: Initialization.

The main function correctly initializes the library, context, and options for TTS functionality.


111-159: LGTM: WebSocket connection and input handling.

The main function correctly establishes a WebSocket connection and handles user input for various actions.


161-167: LGTM: Connection closure and program exit.

The main function correctly closes the WebSocket connection and exits the program.

examples/text-to-speech/websocket/simple_callback/main.go (1)

7-22: Imports and constants are appropriate.

The imported packages and defined constants align with the functionality provided in this example.

examples/speech-to-text/websocket/microphone_channel/main.go (1)

251-251: Callback handling change is appropriate. Verify function signature.

Passing the callback directly to NewWSUsingChan simplifies the code and aligns with Go practices. Verify that NewWSUsingChan is designed to accept the callback in this manner.

Run the following script to verify the function signature of NewWSUsingChan:

Verification successful

Callback handling is correctly implemented.

The function NewWSUsingChan in pkg/client/listen/client.go accepts the callback as an argument, confirming that the change aligns with the function's design.

  • Location: pkg/client/listen/client.go, line 209
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function signature of NewWSUsingChan to ensure it accepts the callback directly.

# Test: Search for the function definition. Expect: The function accepts the callback as an argument.
ast-grep --lang go --pattern 'func NewWSUsingChan($_, $_, $_, $_, $_) $_' 

Length of output: 921

examples/text-to-speech/websocket/simple_channel/main.go (1)

7-23: Imports and constants are appropriate.

The imported packages and defined constants align with the functionality provided in this example.

pkg/api/speak/v1/websocket/chan_default.go (7)

20-54: LGTM: Initialization and environment variable checks.

The initialization of DefaultChanHandler and the use of environment variables for debugging are well-implemented.


56-59: LGTM: Channel retrieval.

The function correctly returns the binary channel.


61-64: LGTM: Channel retrieval.

The function correctly returns the open channel.


66-69: LGTM: Channel retrieval.

The function correctly returns the metadata channel.


71-74: LGTM: Channel retrieval.

The function correctly returns the flush channel.


76-79: LGTM: Channel retrieval.

The function correctly returns the close channel.


81-84: LGTM: Channel retrieval.

The function correctly returns the warning channel.

pkg/api/speak/v1/websocket/chan_router.go (11)

19-30: LGTM: Router initialization with default handler.

The function correctly initializes and starts the router with a default handler.


32-65: LGTM: Router initialization with user-defined channels.

The function correctly initializes the router with user-defined channels.


67-89: LGTM: OpenResponse processing.

The function correctly processes OpenResponse messages and handles errors.


91-113: LGTM: CloseResponse processing.

The function correctly processes CloseResponse messages and handles errors.


115-137: LGTM: ErrorResponse processing.

The function correctly processes ErrorResponse messages and handles errors.


139-154: LGTM: Generic message processing.

The function correctly abstracts message processing and includes logging for debugging.


156-171: LGTM: MetadataResponse processing.

The function correctly processes MetadataResponse messages and handles errors.


173-188: LGTM: FlushedResponse processing.

The function correctly processes FlushedResponse messages and handles errors.


190-205: LGTM: WarningResponse processing.

The function correctly processes WarningResponse messages and handles errors.


207-222: LGTM: ErrorResponse processing.

The function correctly processes ErrorResponse messages and handles errors.


224-260: LGTM: Message routing.

The function correctly routes messages based on their type and includes error handling and logging.

pkg/client/speak/v1/websocket/client_channel.go (13)

24-28: LGTM: WebSocket connection setup.

The function correctly sets up the context and calls ConnectWithCancel.


30-36: LGTM: WebSocket connection with cancel support.

The function correctly sets up the context and calls the underlying client's connection method.


38-42: LGTM: WebSocket reconnect setup.

The function correctly sets up the context and calls AttemptReconnectWithCancel.


44-49: LGTM: WebSocket reconnect with cancel support.

The function correctly sets up the context and calls the underlying client's reconnect method.


51-60: LGTM: WebSocket URL retrieval.

The function correctly retrieves and logs the WebSocket URL. Error handling is present.


62-67: LGTM: Thread management.

The function correctly starts the flush thread based on the configuration.


69-101: LGTM: Message processing and routing.

The function correctly routes messages and handles errors. Logging is appropriately used.


104-133: LGTM: Text-to-speech request.

The function correctly wraps the text in JSON and sends it. Error handling and logging are present.


135-138: LGTM: Alias for SpeakWithText.

The function correctly calls SpeakWithText.


140-150: LGTM: JSON message writing.

The function correctly writes the message and updates the flush count. Locking is used appropriately.


152-168: LGTM: Flush command.

The function correctly sends a flush command and handles errors. Logging is present.


170-185: LGTM: Reset command.

The function correctly sends a reset command and handles errors. Logging is present.


197-206: LGTM: Error processing.

The function correctly converts the error to a response and sends it. Error handling is present.

Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e9cdbb0 and e18b2d3.

Files selected for processing (49)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (2 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (1 hunks)
  • pkg/client/listen/client.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (3 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
Files skipped from review due to trivial changes (7)
  • docs.go
  • go.mod
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/listen/v1/websocket/constants.go
Files skipped from review as they are similar to previous changes (36)
  • .golangci.yaml
  • examples/speech-to-text/websocket/microphone_channel/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • examples/text-to-speech/websocket/simple_callback/main.go
  • examples/text-to-speech/websocket/simple_channel/main.go
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/chan_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/listen/v1/websocket/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-client.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
Learnings (2)
examples/text-to-speech/websocket/interactive_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
pkg/client/speak/client.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (38)
pkg/api/listen/v1/websocket/interfaces/interfaces.go (2)

Line range hint 9-17: LGTM!

The LiveMessageChan interface is correctly defined.

The code changes are approved.


Line range hint 21-30: LGTM!

The LiveMessageCallback interface is correctly defined.

The code changes are approved.

pkg/api/speak/v1/websocket/chan_default.go (10)

20-54: LGTM!

The NewDefaultChanHandler method is correctly implemented.

The code changes are approved.


56-59: LGTM!

The GetBinary method is correctly implemented.

The code changes are approved.


61-64: LGTM!

The GetOpen method is correctly implemented.

The code changes are approved.


66-69: LGTM!

The GetMetadata method is correctly implemented.

The code changes are approved.


71-74: LGTM!

The GetFlush method is correctly implemented.

The code changes are approved.


76-79: LGTM!

The GetClose method is correctly implemented.

The code changes are approved.


81-84: LGTM!

The GetWarning method is correctly implemented.

The code changes are approved.


86-89: LGTM!

The GetError method is correctly implemented.

The code changes are approved.


91-94: LGTM!

The GetUnhandled method is correctly implemented.

The code changes are approved.


96-315: LGTM!

The Run method is correctly implemented, although it is quite large and complex. Consider breaking it down into smaller functions for better readability and maintainability.

The code changes are approved.

examples/text-to-speech/websocket/interactive_channel/main.go (11)

37-54: LGTM!

The NewMyHandler method is correctly implemented.

The code changes are approved.


56-59: LGTM!

The GetBinary method is correctly implemented.

The code changes are approved.


61-64: LGTM!

The GetOpen method is correctly implemented.

The code changes are approved.


66-69: LGTM!

The GetMetadata method is correctly implemented.

The code changes are approved.


71-74: LGTM!

The GetFlush method is correctly implemented.

The code changes are approved.


76-79: LGTM!

The GetClose method is correctly implemented.

The code changes are approved.


81-84: LGTM!

The GetWarning method is correctly implemented.

The code changes are approved.


86-89: LGTM!

The GetError method is correctly implemented.

The code changes are approved.


91-94: LGTM!

The GetUnhandled method is correctly implemented.

The code changes are approved.


96-209: LGTM!

The Run method is correctly implemented, although it is quite large and complex. Consider breaking it down into smaller functions for better readability and maintainability.

The code changes are approved.


212-324: LGTM!

The main method is correctly implemented.

The code changes are approved.

pkg/client/speak/client.go (11)

38-38: LGTM!

The function correctly calls speakv1rest.NewWithDefaults() to create a new REST client.

The code changes are approved.


52-52: LGTM!

The function correctly calls speakv1rest.New() with the provided apiKey and options to create a new REST client.

The code changes are approved.


81-83: LGTM!

The function correctly calls speakv1ws.NewUsingCallbackForDemo() with the provided ctx and options to create a new WebSocket client.

The code changes are approved.


99-101: LGTM!

The function correctly calls speakv1ws.NewUsingCallbackWithDefaults() with the provided ctx, options, and callback to create a new WebSocket client.

The code changes are approved.


120-122: LGTM!

The function correctly calls speakv1ws.NewUsingCallback() with the provided ctx, apiKey, cOptions, sOptions, and callback to create a new WebSocket client.

The code changes are approved.


142-144: LGTM!

The function correctly calls speakv1ws.NewUsingCallbackWithCancel() with the provided ctx, ctxCancel, apiKey, cOptions, sOptions, and callback to create a new WebSocket client.

The code changes are approved.


162-164: LGTM!

The function correctly calls speakv1ws.NewUsingChanForDemo() with the provided ctx and options to create a new WebSocket client.

The code changes are approved.


180-182: LGTM!

The function correctly calls speakv1ws.NewUsingChanWithDefaults() with the provided ctx, options, and callback to create a new WebSocket client.

The code changes are approved.


201-203: LGTM!

The function correctly calls speakv1ws.NewUsingChan() with the provided ctx, apiKey, cOptions, sOptions, and callback to create a new WebSocket client.

The code changes are approved.


223-225: LGTM!

The function correctly calls speakv1ws.NewUsingChanWithCancel() with the provided ctx, ctxCancel, apiKey, cOptions, sOptions, and callback to create a new WebSocket client.

The code changes are approved.


Line range hint 227-257: LGTM!

The deprecation notices are clear and guide users towards the new implementations.

The code changes are approved.

pkg/client/listen/v1/websocket/client_channel.go (2)

78-78: LGTM!

The function correctly calls c.inspect(byMsg) if c.cOptions.InspectListenMessage() returns true. The renaming improves clarity.

The code changes are approved.


126-129: LGTM!

The new case correctly checks for the condition of a closed socket and logs a graceful closure, improving the robustness of the WebSocket stream handling.

The code changes are approved.

README.md (2)

44-48: LGTM!

The new documentation entries provide clear and direct links to the relevant resources for the WebSocket functionality.

The documentation changes are approved.

Tools
LanguageTool

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)


215-219: LGTM!

The new examples provide practical guidance on using the WebSocket capabilities for Text-to-Speech.

The documentation changes are approved.

Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e18b2d3 and 64000e7.

Files selected for processing (52)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (2 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (1 hunks)
  • pkg/client/listen/client.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (3 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (3 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/daily_test/prerecorded_test.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
Files skipped from review due to trivial changes (12)
  • docs.go
  • examples/text-to-speech/websocket/simple_callback/main.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • tests/daily_test/prerecorded_test.go
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Files skipped from review as they are similar to previous changes (36)
  • .golangci.yaml
  • examples/speech-to-text/websocket/microphone_channel/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • examples/text-to-speech/websocket/interactive_channel/main.go
  • examples/text-to-speech/websocket/simple_channel/main.go
  • go.mod
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/chan_router.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/listen/v1/websocket/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/chan_default.go
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-client.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/client.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
Additional context used
LanguageTool
README.md

[style] ~47-~47: This phrase is redundant (‘I’ stands for ‘Interfaces’). Use simply “APIInterfaces”.
Context: ...n/pkg/api/speak/v1/websocket) - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgr...

(ACRONYM_TAUTOLOGY)

Additional comments not posted (6)
pkg/api/listen/v1/websocket/interfaces/interfaces.go (1)

Line range hint 1-1: Verify the impact of removing the Router interface.

The removal of the Router interface suggests a significant change in how the API manages websocket interactions. Ensure that all client code relying on this interface has been updated accordingly.

Run the following script to verify the usage of the Router interface in the codebase:

tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (2)

1-1: LGTM!

The changes in the metadata section reflect a new transaction and request. These updates are typical for response data.

The code changes are approved.


1-1: LGTM!

The changes in the confidence values suggest an update in the backend processing or model evaluation. These adjustments are typical and do not indicate any issues with the response data structure.

The code changes are approved.

pkg/client/listen/v1/websocket/client_channel.go (2)

78-78: LGTM!

The change in the method call to InspectListenMessage() suggests a shift in focus towards handling messages specifically related to listening events. This update is appropriate and does not indicate any issues with the method's functionality.

The code changes are approved.


126-129: LGTM!

The addition of the new case to check for a closed socket improves the robustness of the WebSocket stream handling by explicitly managing closed socket scenarios. This update enhances the error handling logic.

The code changes are approved.

README.md (1)

215-218: LGTM!

The examples provide useful guidance for users to utilize the WebSocket capabilities of the Text-to-Speech service.

The code changes are approved.

README.md Outdated Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the reintroduce-tts-ws branch 9 times, most recently from e8ab795 to 91608b3 Compare August 30, 2024 15:48
Copy link

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 64000e7 and 91608b3.

Files ignored due to path filters (1)
  • hack/check/tools/go.sum is excluded by !**/*.sum
Files selected for processing (54)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • hack/check/tools/go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (1 hunks)
  • pkg/client/listen/client.go (13 hunks)
  • pkg/client/listen/v1/rest/types.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (2 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (2 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/rest/types.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
  • tests/unit_test/prerecorded_test.go (1 hunks)
Files skipped from review due to trivial changes (9)
  • .golangci.yaml
  • examples/text-to-speech/websocket/interactive_channel/main.go
  • pkg/api/speak/v1/websocket/chan_default.go
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/speak/v1/rest/types.go
  • tests/unit_test/prerecorded_test.go
Files skipped from review as they are similar to previous changes (35)
  • examples/speech-to-text/websocket/microphone_channel/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/simple_callback/main.go
  • examples/text-to-speech/websocket/simple_channel/main.go
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/chan_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-client.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Additional context used
Learnings (2)
examples/text-to-speech/websocket/interactive_callback/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
pkg/client/speak/client.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: examples/manage/scopes/main.go:14-14
Timestamp: 2024-06-25T18:05:47.921Z
Learning: The `pkg/client/rest/v1` directory in the deepgram-go-sdk is not deprecated, only the direct use of `pkg/client/rest/client.go` is affected. This distinction is important for accurate codebase analysis and comments.
Additional comments not posted (27)
pkg/client/listen/v1/rest/types.go (2)

11-12: Clarification through renaming.

Renaming Client to RESTClient clarifies its specific use for the Prerecorded API, enhancing code readability and maintainability.

The change is approved as it improves semantic clarity without altering functionality.


16-17: Maintaining backward compatibility through aliasing.

Creating an alias Client for RESTClient ensures that existing code relying on the old Client name will continue to function without modification.

This approach cleverly maintains backward compatibility while promoting the new naming convention.

pkg/client/common/v1/types.go (1)

39-39: Enhancement through integration of routing capabilities.

Adding the router field to the WSClient struct enhances its capabilities in processing or managing WebSocket connections. This change reflects a positive expansion of the WSClient's functionality.

The addition is approved as it potentially allows for more sophisticated message routing or handling strategies.

docs.go (1)

33-33: Approved: WebSocket API import enabled.

The uncommenting of the WebSocket API import is a straightforward change that aligns with the PR's objective to enhance TTS functionality.

pkg/api/listen/v1/websocket/types.go (1)

32-32: Refactor: Removal of defaultHandler from ChanRouter.

The removal of defaultHandler from ChanRouter could significantly impact how default events are managed. Ensure that this change is integrated properly across all usages of ChanRouter to maintain the desired event handling behavior.

Run the following script to verify the integration of this change:

Verification successful

Verification Successful: Default Handling Mechanism Maintained

The removal of defaultHandler from ChanRouter has been integrated properly. The default handling mechanism is still present through the use of NewDefaultChanHandler() in functions like NewChanRouterWithDefault and NewChanWithDefault. No issues were found regarding the management of default events.

  • The defaultHandler was not found, indicating its removal or renaming.
  • Default handling is still managed through NewDefaultChanHandler().
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of the removal of `defaultHandler` from `ChanRouter`.

# Test: Search for the usage of `ChanRouter`. Expect: No references to `defaultHandler`.
rg --type go -A 5 $'ChanRouter'

Length of output: 17941


Script:

#!/bin/bash
# Search for the definition and usage of `defaultHandler` to confirm its removal.
rg --type go 'defaultHandler'

# Examine the implementation of `NewChanRouterWithDefault` and `NewChanWithDefault`.
ast-grep --lang go --pattern 'func NewChanRouterWithDefault() $_' -A 10
ast-grep --lang go --pattern 'func NewChanWithDefault() $_' -A 10

Length of output: 2988

examples/text-to-speech/websocket/interactive_callback/main.go (1)

1-203: Approved: Comprehensive example implementation for TTS WebSocket.

This new file provides a detailed and practical example of using the TTS WebSocket functionality. The implementation covers various aspects of WebSocket communication and event handling, demonstrating the feature effectively.

hack/check/tools/go.mod (2)

1-1: Module path updated appropriately.

The change from github.com/vmware-tanzu/community-edition/hack/tools to github.com/deepgram/deepgram-go-sdk/hack/tools aligns with the PR's objectives and the reorganization of the module.


175-175: Verify compatibility and functionality of the new WebSocket library.

The replacement of github.com/gorilla/websocket with github.com/dvonthenen/websocket v1.5.1-dyv.2 needs careful evaluation to ensure it meets the SDK's requirements and maintains functionality.

Run the following script to verify the compatibility and functionality:

pkg/client/speak/client.go (5)

27-27: Type renaming enhances clarity.

Renaming Client to RESTClient clarifies its specific use for REST functionalities, aligning with the PR's objectives to distinguish between REST and WebSocket clients.


38-38: Function renaming is appropriate.

Renaming NewWithDefaults to NewRESTWithDefaults is consistent with the renaming of the Client type to RESTClient and clarifies the function's purpose.


52-52: Function renaming aligns with REST focus.

Renaming New to NewREST clarifies its purpose for creating REST clients, aligning with the overall restructuring to distinguish between REST and WebSocket functionalities.


85-85: New WebSocket functions enhance functionality.

The introduction of new functions such as NewWSUsingCallbackForDemo, NewWSUsingCallbackWithDefaults, and others, significantly enhances the SDK's WebSocket capabilities, providing more options for real-time audio generation from text.

Also applies to: 103-103, 124-124, 146-146, 166-166, 184-184, 205-205, 227-227


240-240: Deprecation handled appropriately.

Marking old functions and types as deprecated while guiding users towards new implementations ensures backward compatibility and smooth transition to the updated API.

Also applies to: 247-247, 261-261

README.md (2)

44-47: Documentation enhancements approved.

The addition of new documentation entries for the Speak REST Client, Speak REST API, and Speak API Interfaces under the WebSocket section improves clarity and accessibility.


217-218: New WebSocket examples enhance documentation.

The addition of new examples for Text-to-Speech over WebSocket, including a Simple Example and an Interactive WebSocket, provides practical, accessible examples that enhance the documentation.

pkg/client/listen/client.go (12)

27-27: Type Change Approved: RESTClient

Renaming RestClient to RESTClient aligns with Go's conventions for acronyms, enhancing readability and consistency.


35-35: Function Update Approved: NewRESTWithDefaults

Updating the return type to *listenv1rest.RESTClient is consistent with the renaming and maintains the function's behavior.


46-46: Function Update Approved: NewREST

The return type change to *listenv1rest.RESTClient is appropriate and aligns with the new type naming convention.


57-59: Type Change Approved: WSCallback

Introducing WSCallback as an alias for listenv1ws.WSCallback clarifies its usage and purpose in WebSocket operations.


76-76: Function Update Approved: NewWSUsingCallbackForDemo

Updating the return type to *listenv1ws.WSCallback enhances clarity regarding the callback functionality of the WebSocket client.


82-82: Function Update Approved: NewWebSocketUsingCallbackForDemo

Aligning this function with NewWSUsingCallbackForDemo by updating the return type to *listenv1ws.WSCallback maintains consistency and clarity.


98-98: Function Update Approved: NewWSUsingCallbackWithDefaults

The return type change to *listenv1ws.WSCallback is appropriate and enhances the clarity of the WebSocket callback functionality.


104-104: Function Update Approved: NewWebSocketUsingCallbackWithDefaults

Aligning this function with NewWSUsingCallbackWithDefaults by updating the return type to *listenv1ws.WSCallback maintains consistency and clarity.


122-122: Function Update Approved: NewWSUsingCallback

Updating the return type to *listenv1ws.WSCallback enhances clarity regarding the callback functionality of the WebSocket client.


129-129: Function Update Approved: NewWebSocketUsingCallback

Aligning this function with NewWSUsingCallback by updating the return type to *listenv1ws.WSCallback maintains consistency and clarity.


148-148: Function Update Approved: NewWSUsingCallbackWithCancel

Updating the return type to *listenv1ws.WSCallback enhances clarity regarding the callback functionality of the WebSocket client.


154-154: Function Update Approved: NewWebSocketUsingCallbackWithCancel

Aligning this function with NewWSUsingCallbackWithCancel by updating the return type to *listenv1ws.WSCallback maintains consistency and clarity.

Copy link

@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: 1

Outside diff range, codebase verification and nitpick comments (1)
examples/text-to-speech/websocket/simple_channel/main.go (1)

1-299: Consider excluding the example code from automated checks.

Based on the learning from dvonthenen, it is preferred to exclude example code from automated checks in the Deepgram Go SDK repository. This allows for more flexibility in the implementation and focuses the checks on the core SDK code.

Consider adding a comment or configuration to exclude this file from automated checks.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 91608b3 and 5ba8c99.

Files ignored due to path filters (1)
  • hack/check/tools/go.sum is excluded by !**/*.sum
Files selected for processing (54)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • hack/check/tools/go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (2 hunks)
  • pkg/client/listen/client.go (13 hunks)
  • pkg/client/listen/v1/rest/types.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (2 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (2 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/rest/types.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
  • tests/unit_test/prerecorded_test.go (1 hunks)
Files skipped from review due to trivial changes (5)
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/client/listen/v1/websocket/constants.go
  • tests/unit_test/prerecorded_test.go
Files skipped from review as they are similar to previous changes (31)
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • examples/text-to-speech/websocket/interactive_channel/main.go
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/chan_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/rest/types.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Additional context used
Learnings (4)
pkg/api/speak/v1/websocket/constants.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#247
File: pkg/client/speak/constants.go:0-0
Timestamp: 2024-06-21T20:19:28.004Z
Learning: The constant `invalidWebSocketMsgType` was removed from `pkg/client/speak/constants.go` as it was unused.
examples/text-to-speech/websocket/simple_callback/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
examples/text-to-speech/websocket/simple_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
pkg/client/speak/client.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: examples/manage/scopes/main.go:14-14
Timestamp: 2024-06-25T18:05:47.921Z
Learning: The `pkg/client/rest/v1` directory in the deepgram-go-sdk is not deprecated, only the direct use of `pkg/client/rest/client.go` is affected. This distinction is important for accurate codebase analysis and comments.
Additional comments not posted (36)
pkg/client/listen/v1/rest/types.go (2)

11-14: LGTM!

The renaming of the struct from Client to RESTClient improves clarity by indicating that it is specifically related to the REST API. The struct embeds *common.RESTClient, which suggests that it inherits functionality from a common REST client. The comment above the struct provides a brief description of its purpose.


16-17: LGTM!

The type alias allows the RESTClient struct to be referenced as Client, which maintains backward compatibility for existing code. The comment above the type alias provides a brief description of its purpose.

pkg/api/speak/v1/websocket/constants.go (3)

5-5: LGTM!

The package declaration is approved.


11-13: LGTM!

The package-level constants are approved.


16-25: Verify the usage of the ErrInvalidMessageType error variable.

The learnings indicate that a similar constant invalidWebSocketMsgType was removed from another file as it was unused. Please ensure that the ErrInvalidMessageType error variable is actually used in the package to avoid introducing unused code.

Run the following script to verify the usage of the ErrInvalidMessageType error variable:

Verification successful

The ErrInvalidMessageType error variable is actively used in the codebase.

The error variable ErrInvalidMessageType is utilized in multiple files, confirming its relevance and usage in the websocket implementation. Therefore, there is no issue with unused code in this context.

  • Usage confirmed in:
    • pkg/api/speak/v1/websocket/chan_router.go
    • pkg/api/speak/v1/websocket/callback_router.go
    • pkg/api/listen/v1/websocket/chan_router.go
    • pkg/api/listen/v1/websocket/callback_router.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `ErrInvalidMessageType` error variable.

# Test: Search for the usage of the `ErrInvalidMessageType` error variable.
# Expect: At least one occurrence of the error variable being used.
rg --type go -A 5 $'ErrInvalidMessageType'

Length of output: 3131

pkg/api/version/speakstream-version.go (1)

32-32: Verify the impact of the function signature change and update the documentation.

The type of the options parameter has been changed from *interfaces.SpeakOptions to *interfaces.WSSpeakOptions. This change suggests a shift to a new or revised set of options specifically tailored for WebSocket interactions.

Verify that all calls to GetSpeakStreamAPI have been updated to pass the new *interfaces.WSSpeakOptions type.

Run the following script to verify the function usage:

Ensure that the documentation is updated to reflect the new *interfaces.WSSpeakOptions type for the options parameter.

Verification successful

Function usage is correct and type change is properly handled.

The sOptions field in both WSChannel and WSCallback structs is of type *interfaces.WSSpeakOptions, confirming that the calls to GetSpeakStreamAPI are using the correct type. The change in the function signature has been properly accommodated in the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `GetSpeakStreamAPI` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'GetSpeakStreamAPI'

Length of output: 2179


Script:

#!/bin/bash
# Description: Verify the type of `c.sOptions` in the identified files to ensure it matches `*interfaces.WSSpeakOptions`.

# Check the type of `c.sOptions` in `client_channel.go`
rg --type go 'c.sOptions' -A 5 pkg/client/speak/v1/websocket/client_channel.go

# Check the type of `c.sOptions` in `client_callback.go`
rg --type go 'c.sOptions' -A 5 pkg/client/speak/v1/websocket/client_callback.go

Length of output: 690


Script:

#!/bin/bash
# Description: Find the declaration of `c.sOptions` to verify its type.

# Search for the declaration of `c.sOptions` in `client_channel.go`
rg --type go 'sOptions' -A 5 pkg/client/speak/v1/websocket/client_channel.go

# Search for the declaration of `c.sOptions` in `client_callback.go`
rg --type go 'sOptions' -A 5 pkg/client/speak/v1/websocket/client_callback.go

Length of output: 686


Script:

#!/bin/bash
# Description: Search for the declaration of `c.sOptions` by looking for struct or variable definitions.

# Search for struct or variable definitions that include `sOptions` in `client_channel.go`
rg --type go 'struct|var' -A 10 pkg/client/speak/v1/websocket/client_channel.go

# Search for struct or variable definitions that include `sOptions` in `client_callback.go`
rg --type go 'struct|var' -A 10 pkg/client/speak/v1/websocket/client_callback.go

Length of output: 3487


Script:

#!/bin/bash
# Description: Search for the definition of `WSChannel` and `WSCallback` structs to locate the `sOptions` field and verify its type.

# Search for the definition of `WSChannel` struct
rg --type go 'type WSChannel struct' -A 10 pkg/client/speak/v1/websocket/

# Search for the definition of `WSCallback` struct
rg --type go 'type WSCallback struct' -A 10 pkg/client/speak/v1/websocket/

Length of output: 1514

pkg/client/interfaces/v1/types-client.go (2)

20-23: LGTM!

The code changes are approved. Moving the AutoFlushReplyDelta field under the speech-to-text category improves the semantic organization of the options.


25-26: LGTM!

The code changes are approved. Introducing a new category for text-to-speech client options and adding the AutoFlushSpeakDelta field is consistent with the existing code structure and naming conventions.

pkg/api/listen/v1/websocket/interfaces/interfaces.go (1)

Line range hint 1-35: Verify the impact of removing the Router interface.

The Router interface has been removed from the interfacesv1 package. This is a significant change that may impact the API's structure and client code.

Run the following script to verify the impact of this change:

If there are any results, please update the affected code to handle the removal of the Router interface.

docs.go (1)

33-33: LGTM! The uncommented import statement enables the TTS WebSocket functionality.

Uncommenting the import statement for the WebSocket API is a valid way to enable its functionality within the codebase. This change is consistent with the PR objective of reintroducing the TTS WebSocket feature.

Note that this change may impact the overall control flow of the application, as it suggests that the application can now handle real-time audio streaming or interactions through WebSocket connections, enhancing its functionality.

pkg/client/interfaces/v1/types-speak.go (1)

31-36: LGTM!

The code changes are approved.

examples/speech-to-text/websocket/replay/main.go (1)

40-40: LGTM!

The code change is approved for the following reasons:

  • The change in the method for creating the Deepgram client suggests a shift in the underlying implementation, potentially indicating a change in how the WebSocket connection is managed.
  • The change is non-breaking and aims to achieve the same functional outcome of establishing a connection for demo purposes.
  • The error handling mechanism remains intact, ensuring that any issues during the client creation process are logged appropriately.
pkg/api/listen/v1/websocket/types.go (1)

Line range hint 33-41: Verify the impact of removing the defaultHandler field.

The removal of the defaultHandler field from the ChanRouter struct suggests a significant restructuring of the event handling mechanism. This change could affect the control flow of event routing in the websocket implementation.

Run the following script to verify the usage of the defaultHandler field in the codebase:

Verification successful

Removal of defaultHandler Field Verified

The defaultHandler field has been completely removed from the codebase, and there are no remaining references to it. The ChanRouter struct continues to be used without issues, indicating that the removal does not negatively impact the codebase. The functionality previously associated with defaultHandler has likely been refactored or is no longer necessary.

  • No occurrences of defaultHandler found in the codebase.
  • ChanRouter struct usage is intact and functional.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `defaultHandler` field in the codebase.

# Test 1: Search for the field usage. Expect: No occurrences.
rg --type go -A 5 $'defaultHandler'

# Test 2: Search for the `ChanRouter` struct usage. Expect: Analyze the usage to ensure that the removal of the `defaultHandler` field does not break the code.
rg --type go -A 5 $'ChanRouter'

Length of output: 17976

.golangci.yaml (1)

121-126: LGTM!

The code changes are approved.

examples/text-to-speech/websocket/simple_callback/main.go (5)

1-3: LGTM!

The copyright and license header is consistent with the repository standards.


5-17: LGTM!

The package declaration and imports are correct and follow the Go conventions.


19-22: LGTM!

The constants are appropriately named and serve their purpose in the example code.


24-87: LGTM!

The MyCallback struct and its methods provide a clean and modular way to handle WebSocket events. The methods follow the expected signatures and provide appropriate functionality. The Binary method correctly saves the received audio data to a file.


89-179: LGTM!

The main function provides a clear and concise example of using the Deepgram Go SDK for TTS functionality with WebSocket connections. The code follows best practices and is well-structured. The addition of the WAV audio container header allows the output file to be played using media players.

examples/speech-to-text/websocket/microphone_channel/main.go (1)

251-251: Verify the NewWSUsingChan function signature and implementation.

The change removes the dereferencing of the callback variable when passing it to the NewWSUsingChan function. This suggests that the NewWSUsingChan function now expects the callback argument to be passed by value instead of by reference.

To ensure this change is correct, please verify the signature and implementation of the NewWSUsingChan function. Run the following script to retrieve the function definition:

Verification successful

Change verified: NewWSUsingChan function accepts callback by value.

The NewWSUsingChan function in pkg/client/listen/client.go accepts the chans parameter (formerly callback) by value, confirming that the change in the code snippet is correct. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the signature and implementation of the `NewWSUsingChan` function.

# Test: Search for the function definition. 
# Expect: The function should accept the `callback` argument by value.
ast-grep --lang go --pattern $'func NewWSUsingChan($_, $_, $_, $_, callback msginterfaces.LiveMessageChan) ($_, $_) {
  $$$
}'

Length of output: 127


Script:

#!/bin/bash
# Description: Search for the `NewWSUsingChan` function definition by name to verify its signature and implementation.

# Search for the function definition by name.
ast-grep --lang go --pattern $'func NewWSUsingChan($_, $_, $_, $_, $_) ($_, $_) {
  $$$
}'

Length of output: 937

examples/text-to-speech/websocket/simple_channel/main.go (2)

25-208: LGTM!

The MyHandler struct and its methods are implemented correctly, following the expected pattern for a custom WebSocket handler. The channels are properly initialized, and the Run method ensures concurrent handling of events.


210-299: LGTM!

The main function correctly sets up the WebSocket connection, sends text input, and saves the generated audio to a file with a WAV header. The manual flushing of the input is handled properly when AutoFlushSpeakDelta is not set.

hack/check/tools/go.mod (2)

1-1: LGTM!

The module path change is approved as it reflects the transition of the module to the Deepgram Go SDK.


175-175: Verify the impact of the dependency replacement.

Ensure that replacing github.com/gorilla/websocket with github.com/dvonthenen/websocket v1.5.1-dyv.2 does not introduce any breaking changes or compatibility issues in the module.

Run the following script to verify the dependency replacement:

pkg/api/speak/v1/websocket/chan_default.go (3)

1-18: LGTM!

The copyright notice and package declaration are standard and approved.


20-54: LGTM!

The NewDefaultChanHandler function is correctly implemented and follows best practices:

  • It uses environment variables for configuration.
  • It initializes the struct fields and channels.
  • It starts a goroutine to run the Run method in the background.

The code changes are approved.


56-94: LGTM!

The getter methods for the event channels are correctly implemented and follow a consistent naming convention. The code changes are approved.

pkg/client/speak/client.go (5)

11-16: LGTM!

The changes to the import statements are approved.


27-27: LGTM!

The renaming of the Client type to RESTClient is approved.


38-40: LGTM!

The renaming of the NewWithDefaults function to NewRESTWithDefaults is approved.


52-54: LGTM!

The renaming of the New function to NewREST is approved.


56-229: LGTM!

The new WebSocket client functions are approved. They provide enhanced functionality for WebSocket connections, including options for callbacks and cancellation, and improve the API's design by providing a more intuitive interface and better documentation of the available methods.

README.md (1)

215-218: LGTM!

The code changes are approved.

pkg/client/common/v1/websocket.go (3)

25-25: LGTM!

The changes to the NewWS function are approved. The addition of the router parameter and its assignment to the WSClient struct enhance the functionality by integrating routing capabilities into the WebSocket client.

Also applies to: 42-42


200-207: LGTM!

The changes to the internalConnectWithCancel method are approved. Invoking the Open method on the router after establishing a WebSocket connection improves the interaction between the WebSocket client and the routing mechanism.


545-552: LGTM!

The changes to the closeWs method are approved. Calling the router's Close method when closing the WebSocket connection ensures that the router is informed of the disconnection.

pkg/api/speak/v1/websocket/chan_default.go Outdated Show resolved Hide resolved
Copy link

@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: 4

Outside diff range, codebase verification and nitpick comments (4)
pkg/api/listen/v1/websocket/chan_router.go (1)

280-285: Consider removing the placeholder method.

If binary message handling is not needed for the current use case (STT), consider removing the placeholder Binary method to keep the code concise and avoid confusion.

examples/text-to-speech/websocket/simple_channel/main.go (1)

227-316: The main function provides a complete and well-structured example.

The main function demonstrates how to use the Deepgram Go SDK for Text-to-Speech (TTS) using WebSocket. It initializes the SDK, sets up the client, connects to the WebSocket, sends text input, and saves the generated audio to a file with a WAV header. The example is easy to follow and understand.

Consider adding a comment to explain the purpose of the sleep statement before closing the connection:

// Wait for a few seconds to allow the audio to be generated and processed
time.Sleep(5 * time.Second)
examples/text-to-speech/websocket/interactive_channel/main.go (1)

1-341: Exclude example code from automated checks.

Based on the learning retrieved from long-term memory, dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository. Consider adding this file to the exclusion list of the relevant automated checks to align with this preference.

pkg/api/speak/v1/websocket/chan_default.go (1)

105-346: Consider refactoring the Run method to improve maintainability and reduce complexity.

The Run method is quite long and complex, as indicated by the nolint directives for function length and cyclomatic complexity. While the current structure is consistent and easy to follow, refactoring the method into smaller, more focused functions can improve maintainability and make the code easier to understand and modify.

Consider the following refactoring suggestions:

  1. Extract the event processing logic for each event type into separate methods. For example:
func (dch *DefaultChanHandler) processBinaryEvent(br *[]byte) {
    // Binary event processing logic
}

func (dch *DefaultChanHandler) processOpenEvent(or *interfaces.OpenResponse) {
    // Open event processing logic
}

// ... similar methods for other event types
  1. Update the Run method to call these new methods:
func (dch *DefaultChanHandler) Run() error {
    // ...

    go func() {
        defer wgReceivers.Done()

        for br := range dch.binaryChan {
            dch.processBinaryEvent(br)
        }
    }()

    // ... similar changes for other event types

    // ...
}

This refactoring will make the Run method shorter and easier to understand while keeping the event processing logic separate and maintainable. It will also eliminate the need for the nolint directives.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5ba8c99 and fd50fe4.

Files ignored due to path filters (1)
  • hack/check/tools/go.sum is excluded by !**/*.sum
Files selected for processing (55)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • hack/check/tools/go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (4 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (2 hunks)
  • pkg/client/listen/client.go (13 hunks)
  • pkg/client/listen/v1/rest/types.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (2 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (2 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/rest/types.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
  • tests/unit_test/prerecorded_test.go (1 hunks)
Files skipped from review due to trivial changes (8)
  • pkg/api/listen/v1/websocket/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/constants.go
  • tests/unit_test/prerecorded_test.go
Files skipped from review as they are similar to previous changes (29)
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • hack/check/tools/go.mod
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/rest/types.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Additional context used
Learnings (4)
examples/text-to-speech/websocket/simple_callback/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
examples/text-to-speech/websocket/simple_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
pkg/client/speak/client.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: examples/manage/scopes/main.go:14-14
Timestamp: 2024-06-25T18:05:47.921Z
Learning: The `pkg/client/rest/v1` directory in the deepgram-go-sdk is not deprecated, only the direct use of `pkg/client/rest/client.go` is affected. This distinction is important for accurate codebase analysis and comments.
examples/text-to-speech/websocket/interactive_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
GitHub Check: Lint
pkg/api/speak/v1/websocket/chan_default.go

[failure] 58-58:
hugeParam: dch is heavy (80 bytes); consider passing it by pointer (gocritic)


[failure] 63-63:
hugeParam: dch is heavy (80 bytes); consider passing it by pointer (gocritic)


[failure] 68-68:
hugeParam: dch is heavy (80 bytes); consider passing it by pointer (gocritic)

Additional comments not posted (99)
pkg/client/listen/v1/rest/types.go (2)

11-14: LGTM!

The code changes are approved for the following reasons:

  • The renaming of Client to RESTClient improves clarity by indicating that the struct is specific to the REST API.
  • Embedding the common.RESTClient struct allows the RESTClient to inherit its functionality.

16-17: LGTM!

The code changes are approved for the following reason:

  • The type alias Client maintains backward compatibility for existing code that relies on the Client name.
pkg/client/interfaces/v1/types-client.go (2)

20-23: LGTM!

The code changes are approved. Categorizing the speech-to-text client options improves the semantic organization of the ClientOptions struct.


25-26: Verify the usage of the new field AutoFlushSpeakDelta.

Ensure that the new field is being used correctly in the codebase.

Run the following script to verify the field usage:

Verification successful

The AutoFlushSpeakDelta field is used correctly in the codebase.

The field is utilized in the client_callback.go file to control client behavior and is referenced in example files to guide users on its usage. No issues were found regarding its implementation.

  • pkg/client/speak/v1/websocket/client_callback.go: Used to determine if a flush should occur.
  • pkg/client/interfaces/v1/options.go: Set and checked for non-zero values.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new field `AutoFlushSpeakDelta`.

# Test 1: Search for the field usage. Expect: At least one occurrence.
rg --type go -A 5 $'AutoFlushSpeakDelta'

# Test 2: Search for the field initialization. Expect: At least one occurrence.
ast-grep --lang go --pattern $'&ClientOptions{
  $$$
  AutoFlushSpeakDelta: $_,
  $$$
}'

Length of output: 4967

pkg/api/listen/v1/websocket/interfaces/interfaces.go (1)

Line range hint 1-34: Verify the impact of the Router interface removal on the codebase.

The entire Router interface definition has been removed from the interfacesv1 package. This interface previously defined methods for handling various operations such as opening connections, sending messages, closing connections, and handling errors.

The removal of this interface suggests a potential shift in how the API manages these functionalities, possibly indicating a redesign or refactoring of the websocket handling logic.

It's important to ensure that the necessary adjustments are made in the client code that relied on this interface for websocket interactions.

Run the following script to verify the impact of the Router interface removal:

Verification successful

No Impact from Router Interface Removal

The Router interface was not found to be used or implemented anywhere else in the codebase. Its removal does not impact the rest of the codebase, indicating that it was likely deprecated or unused. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the `Router` interface removal on the codebase.

# Test 1: Search for the `Router` interface usage in the codebase.
# Expect: No occurrences of the `Router` interface usage.
rg --type go -A 5 $'interfacesv1\.Router'

# Test 2: Search for the implementation of the `Router` interface methods in the codebase.
# Expect: No occurrences of the `Router` interface method implementations.
ast-grep --lang go --pattern $'func ($$$) Open($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) Message($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) Metadata($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) SpeechStarted($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) UtteranceEnd($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) Close($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) Error($$$) {
  $$$
}'

ast-grep --lang go --pattern $'func ($$$) UnhandledEvent($$$) {
  $$$
}'

Length of output: 590

docs.go (1)

33-33: LGTM!

The code change is approved.

Uncommenting the import statement for the WebSocket API is a necessary step to enable the functionality of the WebSocket API within the codebase. This change is consistent with the PR objective of reintroducing the TTS WebSocket feature.

The change may impact the overall control flow of the application, as it suggests that the application can now handle real-time audio streaming or interactions through WebSocket connections, enhancing its functionality.

Please ensure that the necessary tests and documentation are added to verify the effectiveness of the new feature and provide guidance on how to use it.

examples/text-to-speech/rest/file/hello-world/main.go (4)

22-22: Verify the reason for changing the output file format from MP3 to WAV.

The filePath constant has been changed from "./test.mp3" to "./test.wav", indicating a change in the output file format from MP3 to WAV.

WAV is an uncompressed audio format, while MP3 is a compressed format. The change may affect the audio quality and file size.

Please ensure that the change is intentional and consider the following:

  • Is the change in line with the desired audio quality and file size requirements?
  • Are there any downstream dependencies or systems that may be affected by the change in file format?

36-36: LGTM!

The code segment is approved.


37-37: Verify the reason for choosing the linear16 encoding.

The Encoding field in the SpeakOptions struct is set to "linear16", indicating that the generated audio will be encoded in 16-bit linear PCM format.

Linear PCM is an uncompressed audio format that provides high audio quality but results in larger file sizes compared to compressed formats like MP3.

Please ensure that the choice of linear16 encoding aligns with the desired audio quality and file size requirements. Consider the following:

  • Is the high audio quality provided by linear16 necessary for the use case?
  • Are the larger file sizes resulting from the uncompressed format acceptable?
  • Are there any storage or bandwidth constraints that may be impacted by the choice of encoding?

38-38: Verify the reason for choosing the 48 kHz sample rate.

The SampleRate field in the SpeakOptions struct is set to 48000, indicating a sample rate of 48 kHz for the generated audio.

A sample rate of 48 kHz is a high-quality setting commonly used in professional audio applications. Higher sample rates provide better audio quality but also result in larger file sizes.

Please ensure that the choice of 48 kHz sample rate aligns with the desired audio quality and file size requirements. Consider the following:

  • Is the high audio quality provided by the 48 kHz sample rate necessary for the use case?
  • Are the larger file sizes resulting from the high sample rate acceptable?
  • Are there any compatibility considerations with downstream systems or playback devices that may not support the 48 kHz sample rate?
.golangci.yaml (1)

121-126: LGTM!

The code changes are approved.

examples/text-to-speech/websocket/simple_callback/main.go (2)

1-4: LGTM!

The code changes are approved.


5-184: LGTM!

The code changes are approved.

Based on the learning from the user dvonthenen, example code should be excluded from automated checks. Therefore, skipping further review of this code segment.

examples/speech-to-text/websocket/microphone_channel/main.go (1)

251-251: Verify the intended behavior of the callback argument change.

The callback variable is no longer dereferenced when passed to NewWSUsingChan. This change affects how the callback is processed within NewWSUsingChan.

Please verify that this change aligns with the intended behavior and does not introduce any undesired side effects in the interaction between the Deepgram client and the callback mechanism.

To aid the verification, consider running the following script to analyze the usage of callback in NewWSUsingChan:

The script searches for:

  1. The function definition of NewWSUsingChan to understand the type of the callback parameter.
  2. The usage of callback within NewWSUsingChan to understand how it's being processed.

Please provide the results of running this script and confirm if the change aligns with the expected behavior. If not, please suggest the necessary modifications.

Verification successful

Verification successful: No issues found with the callback argument change.

The callback variable is an interface, which does not require dereferencing when passed to NewWSUsingChan. This change aligns with the intended behavior and does not introduce any undesired side effects. The code is consistent with Go's handling of interfaces.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze the usage of `callback` in `NewWSUsingChan`.

# Test: Search for the function definition.
ast-grep --lang go --pattern $'func NewWSUsingChan($_, $_, $_, $_, callback $_) {
  $$$
}'

# Test: Search for the usage of `callback` within the function.
rg --type go -A 5 $'callback\\.' $(fd NewWSUsingChan)

Length of output: 10460


Script:

#!/bin/bash
# Search for the definition of the NewWSUsingChan function across the codebase.
rg --type go 'func NewWSUsingChan' -A 10

Length of output: 7166


Script:

#!/bin/bash
# Search for the definition of msginterfaces.SpeakMessageChan and msginterfaces.LiveMessageChan.
rg --type go 'type SpeakMessageChan' -A 5
rg --type go 'type LiveMessageChan' -A 5

Length of output: 1197

pkg/api/listen/v1/websocket/chan_router.go (8)

87-87: LGTM!

The code change is approved.


111-111: LGTM!

The code change is approved.


135-135: LGTM!

The code change is approved.


139-139: LGTM!

The code change is approved.


169-169: LGTM!

The code change is approved.


186-186: LGTM!

The code changes are approved.

Also applies to: 203-203, 220-220, 237-237


265-265: Verify the type assertion change.

Ensure that treating TypeErrorResponse as interfaces.TypeResponse(interfaces.TypeErrorResponse) is the intended behavior and does not introduce any issues in error response handling.


301-301: LGTM!

The code change is approved.

examples/text-to-speech/websocket/simple_channel/main.go (3)

1-6: License header and package declaration look good.

The file includes the standard MIT license header and declares the package as main, which is appropriate for a standalone example.


25-100: MyHandler struct and its methods are well-implemented.

The MyHandler struct is properly defined to handle various WebSocket events using channels. The struct methods provide a clean and idiomatic way to access these channels. This design allows for asynchronous processing of events, which is a good practice.


1-316: Skipping further review of the example file.

Based on the learning provided, example code should be excluded from automated checks in the Deepgram Go SDK repository. Therefore, no further review is necessary for this file.

pkg/client/speak/client.go (12)

38-40: LGTM!

The code changes are approved.


52-54: LGTM!

The code changes are approved.


85-87: LGTM!

The code changes are approved.


103-105: LGTM!

The code changes are approved.


124-126: LGTM!

The code changes are approved.


146-148: LGTM!

The code changes are approved.


166-168: LGTM!

The code changes are approved.


184-186: LGTM!

The code changes are approved.


205-207: LGTM!

The code changes are approved.


227-229: LGTM!

The code changes are approved.


247-249: LGTM!

The code changes are approved.


261-263: LGTM!

The code changes are approved.

examples/text-to-speech/websocket/interactive_channel/main.go (5)

1-6: LGTM!

The license header and package declaration are correct and consistent with the repository standards.


7-19: LGTM!

The import statements are correct and follow the standard Go conventions.


21-24: LGTM!

The constant declarations are appropriate and serve their purpose in the example implementation.


26-227: LGTM!

The MyHandler struct and its associated methods provide a structured way to handle WebSocket events. The event channels are properly initialized and exposed through getter methods, and the Run method correctly sets up goroutines to process the events concurrently.


229-341: LGTM!

The main function provides a clear example of how to use the Deepgram Go SDK for Text-to-Speech functionality using WebSocket. The user interaction and error handling are implemented correctly, and the generated audio is saved to a file with a WAV header, allowing it to be played using media players.

pkg/api/speak/v1/websocket/chan_default.go (1)

33-45: LGTM!

The DefaultChanHandler struct is well-structured and follows a consistent naming convention for the fields. The initialization function NewDefaultChanHandler sets up the event channels and reads the debug flags from environment variables appropriately.

pkg/client/speak/v1/websocket/client_callback.go (19)

1-22: LGTM!

The code changes are approved.


25-28: LGTM!

The code changes are approved.


32-36: LGTM!

The code changes are approved.


39-42: LGTM!

The code changes are approved.


45-49: LGTM!

The code changes are approved.


52-60: LGTM!

The code changes are approved.


63-67: LGTM!

The code changes are approved.


70-102: LGTM!

The code changes are approved.


116-133: LGTM!

The code changes are approved.


136-138: LGTM!

The code changes are approved.


141-150: LGTM!

The code changes are approved.


153-169: LGTM!

The code changes are approved.


172-186: LGTM!

The code changes are approved.


189-191: LGTM!

The code changes are approved.


194-196: LGTM!

The code changes are approved.


199-207: LGTM!

The code changes are approved.


210-272: LGTM!

The code changes are approved.


275-300: LGTM!

The code changes are approved.


304-330: LGTM!

The code changes are approved.

pkg/api/speak/v1/websocket/chan_router.go (15)

20-30: LGTM!

The code changes are approved.


32-67: LGTM!

The code changes are approved.


70-91: LGTM!

The code changes are approved.


94-115: LGTM!

The code changes are approved.


118-139: LGTM!

The code changes are approved.


142-156: LGTM!

The code changes are approved.


158-173: LGTM!

The code changes are approved.


175-190: LGTM!

The code changes are approved.


192-207: LGTM!

The code changes are approved.


209-224: LGTM!

The code changes are approved.


226-241: LGTM!

The code changes are approved.


244-281: LGTM!

The code changes are approved.


284-294: LGTM!

The code changes are approved.


297-309: LGTM!

The code changes are approved.


312-321: LGTM!

The code changes are approved.

README.md (2)

47-47: Address the previous review comment to remove the redundant term "Interfaces" from the link text.

The link text "Speak API Interfaces" is still redundant. Please apply the suggested change from the previous review comment:

-  - Speak API Interfaces - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)
+  - Speak API - [https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main/pkg/api/speak/v1/websocket/interfaces)

215-218: LGTM!

The examples for Text-to-Speech over WebSocket are a great addition to the documentation. The links are correctly formatted and point to the relevant example files in the repository.

pkg/client/listen/client.go (20)

27-27: LGTM!

The type alias renaming improves code clarity.


35-35: LGTM!

The return type update is consistent with the RESTClient type alias change.


46-46: LGTM!

The return type update is consistent with the RESTClient type alias change.


57-58: LGTM!

The new type alias improves code clarity and maintainability.


60-61: LGTM!

The new type alias improves code clarity and maintainability.


76-76: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


82-82: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


98-98: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


104-104: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


122-122: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


129-129: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


148-148: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


154-154: LGTM!

The return type update is consistent with the WSCallback type alias introduction.


192-192: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


198-198: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


212-212: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


219-219: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


234-234: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


240-240: LGTM!

The parameter type and return type updates are consistent with the WSChannel type alias introduction and the removal of the pointer for the chans parameter.


Line range hint 298-349: LGTM!

The updates to the deprecated functions and type aliases are consistent with the previously reviewed changes. The deprecation comments provide clear guidance for users to transition to the new naming conventions and types.

pkg/api/speak/v1/websocket/chan_default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/chan_default.go Show resolved Hide resolved
pkg/api/speak/v1/websocket/chan_default.go Outdated Show resolved Hide resolved
pkg/api/speak/v1/websocket/chan_router.go Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the reintroduce-tts-ws branch 2 times, most recently from 46a25fe to c7977f3 Compare September 9, 2024 16:35
Copy link

@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: 11

Outside diff range, codebase verification and nitpick comments (5)
pkg/api/listen/v1/websocket/interfaces/interfaces.go (1)

Router Interface Still Present in Codebase

The Router interface has not been removed and is still being referenced in multiple files across the codebase. Please review the following locations to ensure that the removal is intentional and complete:

  • pkg/client/speak/v1/websocket/types.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/common/v1/websocket.go
  • pkg/client/common/v1/types.go
  • pkg/client/common/v1/interfaces/interfaces.go
Analysis chain

Line range hint 1-1: Verify the removal of the Router interface.

The removal of the Router interface from the interfacesv1 package is a significant change. This interface previously managed WebSocket connections, which is crucial for the functionality of the SDK. Ensure that this change is intentional and that alternative implementations or adjustments are provided to handle the functionalities previously covered by the Router interface.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the Router interface on the rest of the codebase.

# Test: Search for references to the Router interface. Expect: No remaining references that are unhandled.
rg --type python -A 5 $'Router'

Length of output: 61


Script:

#!/bin/bash
# Description: Verify the impact of removing the Router interface on the rest of the codebase.

# Test: Search for references to the Router interface in Go files. Expect: No remaining references that are unhandled.
rg --type go -A 5 $'Router'

Length of output: 40743

pkg/audio/speaker/speaker.go (1)

68-86: Audio data writing function is effectively implemented.

The method for converting byte data and handling the stream write operation is well done. Consider removing the commented-out code if it is no longer needed.

pkg/client/common/v1/websocket.go (2)

Line range hint 25-42: Review the integration of the router parameter in NewWS.

The addition of the router parameter to the NewWS function is a significant change. It's crucial to ensure that the router is not null before using it to avoid potential runtime errors. Consider adding a null check:

+ if router == nil {
+     return nil, errors.New("router cannot be nil")
+ }

This will safeguard against null pointer exceptions and ensure the function's robustness.


Line range hint 1-544: Suggest improvements in error handling and structure.

The file is well-structured and follows good practices in managing WebSocket connections. However, there are areas where error handling could be improved to ensure more robust operation. Consider reviewing the error handling throughout the file to ensure that all potential issues are adequately addressed and logged. Additionally, some methods could benefit from more detailed comments explaining their operation and the implications of the errors they handle.

This will enhance the maintainability and reliability of the WebSocket connection management.

pkg/client/listen/client.go (1)

27-27: Issues Found: Old Type Names Still Present in Codebase

The verification process has revealed that the old type names listenv1rest.Client and listenv1ws.Client are still present in the codebase. These references were found in the following files:

  • pkg/client/live/legacy.go
  • pkg/client/prerecorded/legacy.go
  • pkg/client/listen/client.go

Some of these references are marked as deprecated, indicating an intention to replace them. However, to ensure consistency and avoid potential integration issues, it is recommended to update these references to the new type aliases throughout the codebase.

Analysis chain

Type aliases and function signature updates approved.

The updates to type aliases and function signatures in the listen package are well-executed and enhance the clarity and consistency of the code. The use of more descriptive names for type aliases and the alignment of function signatures with these names are good practices.

Please ensure that these changes are reflected throughout the codebase and that there are no remaining references to the old type names or function signatures that could lead to integration issues.

Run the following script to verify the impact of these changes on the rest of the codebase:

Also applies to: 35-35, 46-46, 57-57, 58-58, 60-60, 76-76, 82-82, 98-98, 104-104, 122-122, 129-129, 148-148, 154-154, 192-192, 198-198, 212-212, 219-219, 234-234, 240-240, 298-298, 303-303, 310-310, 319-319, 328-328, 335-335, 342-342, 349-349

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that there are no remaining references to the old type names or function signatures.

# Test: Search for old type names and function signatures. Expect: No occurrences.
rg --type go -A 5 $'listenv1rest.Client|listenv1ws.Client'

Length of output: 4047

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fd50fe4 and c7977f3.

Files ignored due to path filters (1)
  • hack/check/tools/go.sum is excluded by !**/*.sum
Files selected for processing (61)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/speaker_channel/main.go (1 hunks)
  • hack/check/tools/go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/audio/common/common.go (1 hunks)
  • pkg/audio/speaker/constants.go (1 hunks)
  • pkg/audio/speaker/interfaces/interfaces.go (1 hunks)
  • pkg/audio/speaker/speaker.go (1 hunks)
  • pkg/audio/speaker/types.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (12 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (2 hunks)
  • pkg/client/listen/client.go (13 hunks)
  • pkg/client/listen/v1/rest/types.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (2 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (2 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/rest/types.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
  • tests/unit_test/prerecorded_test.go (1 hunks)
Files skipped from review due to trivial changes (8)
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/audio/speaker/constants.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/listen/v1/websocket/constants.go
  • tests/unit_test/prerecorded_test.go
Files skipped from review as they are similar to previous changes (39)
  • .golangci.yaml
  • examples/speech-to-text/websocket/microphone_channel/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/rest/file/hello-world/main.go
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • examples/text-to-speech/websocket/interactive_channel/main.go
  • examples/text-to-speech/websocket/simple_callback/main.go
  • hack/check/tools/go.mod
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/listen/v1/websocket/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/chan_default.go
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/v1/rest/types.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/rest/types.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Additional context used
Learnings (2)
examples/text-to-speech/websocket/simple_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/interactive/main.go:35-43
Timestamp: 2024-08-22T03:05:19.486Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository.
pkg/client/speak/client.go (2)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: pkg/client/speak/client.go:66-67
Timestamp: 2024-06-26T16:09:10.173Z
Learning: The `analyze` and `manage` clients in the Deepgram SDK are exclusively REST-based and do not utilize or require a separate `NewRESTWithDefaults` function.
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#252
File: examples/manage/scopes/main.go:14-14
Timestamp: 2024-06-25T18:05:47.921Z
Learning: The `pkg/client/rest/v1` directory in the deepgram-go-sdk is not deprecated, only the direct use of `pkg/client/rest/client.go` is affected. This distinction is important for accurate codebase analysis and comments.
golangci-lint
pkg/audio/common/common.go

9-9: could not import github.com/gordonklaus/portaudio (-: # github.com/gordonklaus/portaudio

[pkg-config --cflags -- portaudio-2.0]

Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'portaudio-2.0', required by 'virtual:world', not found)

(typecheck)

pkg/audio/speaker/speaker.go

13-13: could not import github.com/gordonklaus/portaudio (-: # github.com/gordonklaus/portaudio

[pkg-config --cflags -- portaudio-2.0]

Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'portaudio-2.0', required by 'virtual:world', not found)

(typecheck)

GitHub Check: Lint
pkg/audio/common/common.go

[failure] 9-9:
could not import github.com/gordonklaus/portaudio (-: go build github.com/gordonklaus/portaudio:

pkg/audio/speaker/speaker.go

[failure] 13-13:
could not import github.com/gordonklaus/portaudio (-: go build github.com/gordonklaus/portaudio:

Additional comments not posted (33)
pkg/audio/speaker/interfaces/interfaces.go (1)

10-18: Well-designed Speaker interface.

The Speaker interface is well-constructed with clear method signatures and appropriate functionalities. It effectively encapsulates the operations needed for a speaker system in Go, adhering to good design principles.

pkg/audio/speaker/types.go (1)

13-17: Clear and concise AudioConfig struct.

The AudioConfig struct is well-defined with clear fields for configuring audio output. It serves its purpose effectively without unnecessary complexity.

pkg/client/interfaces/v1/types-client.go (1)

20-26: Enhanced ClientOptions struct for better categorization.

The modifications to the ClientOptions struct enhance clarity and usability by clearly separating speech-to-text and text-to-speech options. The addition of the AutoFlushSpeakDelta field is well-integrated and appropriately documented, supporting the new text-to-speech functionality effectively.

pkg/audio/common/common.go (1)

17-49: Initialization and teardown functions are well-implemented.

The Initialize and Teardown functions for portaudio are implemented correctly, with proper checks and logging. Once the import issue is resolved, these functions should work as expected.

docs.go (1)

33-33: Approval of the uncommented import statement for WebSocket API.

Uncommenting the import statement for the WebSocket API (pkg/api/speak/v1/websocket) is a direct and effective way to enable its functionality within the SDK. This change aligns with the PR's objectives to enhance the TTS features by integrating WebSocket connections for real-time audio generation.

pkg/audio/speaker/speaker.go (7)

19-22: Initialization function is well-implemented.

The delegation to common.Initialize() is appropriate for setting up any required state or configurations.


24-27: Proper cleanup function.

Using common.Teardown() ensures that resources are appropriately released.


29-53: Speaker creation function is robust and well-handled.

The error handling and logging provide clear feedback on the operation's success or failure, which is crucial for debugging and maintenance.


56-66: Stream start function is correctly implemented.

The function effectively handles potential errors during the stream start, which is essential for reliable operation.


88-108: Streaming function is well-implemented for continuous audio handling.

The use of a loop with a select statement for handling stop signals is a good practice in Go for managing long-running operations.


110-122: Mute and Unmute functions are correctly implemented.

The use of mutexes ensures thread safety when changing the mute state, which is crucial in a multi-threaded environment.


124-136: Stop function is effectively implemented.

The function correctly handles the stream stop and ensures that all operations are completed before returning, which is essential for clean resource management.

pkg/client/speak/client.go (10)

27-27: Type alias for RESTClient is appropriate.

The renaming to RESTClient helps clarify the distinction between REST and WebSocket functionalities in the SDK.


38-38: Function NewRESTWithDefaults is correctly implemented.

This function appropriately creates a REST client with default settings, aligning with the SDK's structure.


52-52: Function NewREST is implemented correctly.

This function correctly initializes a REST client with specified options, which is consistent with the SDK's design principles.


85-85: Function NewWSUsingCallbackForDemo is correctly implemented for demonstration purposes.

This function provides a straightforward way to create a WebSocket client with default settings for demonstration, aligning with the SDK's expanded WebSocket support.


103-103: Function NewWSUsingCallbackWithDefaults is correctly implemented.

This function effectively initializes a WebSocket client with default settings and a custom callback, enhancing the SDK's WebSocket capabilities.


124-124: Function NewWSUsingCallback is implemented correctly.

This function provides a comprehensive method to initialize a WebSocket client with specific configurations and a callback, aligning with the SDK's design for flexible WebSocket support.


146-146: Function NewWSUsingCallbackWithCancel is implemented correctly.

This function effectively initializes a WebSocket client with specific configurations, a callback, and cancellation capabilities, providing advanced control over WebSocket connections.


166-166: Function NewWSUsingChanForDemo is correctly implemented for demonstration purposes.

This function provides a straightforward way to create a WebSocket client using channels with default settings for demonstration, aligning with the SDK's expanded WebSocket support.


184-184: Function NewWSUsingChanWithDefaults is correctly implemented.

This function effectively initializes a WebSocket client using channels with default settings and a custom callback, enhancing the SDK's WebSocket capabilities.


205-205: Function NewWSUsingChan is implemented correctly.

This function provides a comprehensive method to initialize a WebSocket client using channels with specific configurations and a callback, aligning with the SDK's design for flexible WebSocket support.

pkg/api/listen/v1/websocket/chan_router.go (10)

20-28: Function NewChanWithDefault is well-implemented.

The initialization of ChanRouter with default settings and the handling of errors within the goroutine are correctly implemented.


Line range hint 33-60: Function NewChanRouter is correctly implemented.

The initialization of ChanRouter with user-defined channels and the conditional debug logging based on an environment variable are well-handled.


87-87: Method Open effectively uses shared processing logic.

The method correctly handles JSON operations and utilizes processGeneric for consistent message processing.


111-111: Method Close maintains a consistent and effective pattern.

Like the Open method, it handles JSON operations and uses processGeneric for message processing, enhancing maintainability.


135-135: Method Error correctly uses established patterns for error handling.

The method is consistent with other message handling methods, using processGeneric to process the ErrorResponse.


139-139: Method processGeneric centralizes message processing effectively.

The method reduces code duplication by handling all message types in a single location and provides detailed logging for debugging.


169-169: Method processMessage is consistently implemented with other message handlers.

The method uses processGeneric to handle MessageResponse messages, maintaining consistency with the router's design pattern.


186-186: Method processMetadata follows the established pattern effectively.

The method handles MetadataResponse messages using processGeneric, consistent with the router's design.


203-203: Method processSpeechStartedResponse is correctly implemented.

The method handles SpeechStartedResponse messages using processGeneric, maintaining consistency with the router's design pattern.


220-220: Method processUtteranceEndResponse maintains consistent handling of message types.

The method uses processGeneric to process UtteranceEndResponse messages, consistent with the router's design pattern.

README.md (1)

44-48: Documentation updates approved with a suggestion.

The documentation changes for the Text-to-Speech WebSocket functionality are clear and enhance the accessibility of the information. The new links and examples are well-placed and provide valuable resources to the users.

However, please apply the previous review suggestion to refine the term "Speak API Interfaces" to "Speak API" to avoid redundancy.

Also applies to: 215-219

pkg/audio/speaker/types.go Outdated Show resolved Hide resolved
pkg/audio/common/common.go Show resolved Hide resolved
pkg/audio/speaker/speaker.go Outdated Show resolved Hide resolved
pkg/client/common/v1/websocket.go Show resolved Hide resolved
pkg/client/common/v1/websocket.go Show resolved Hide resolved
examples/text-to-speech/websocket/speaker_channel/main.go Outdated Show resolved Hide resolved
examples/text-to-speech/websocket/speaker_channel/main.go Outdated Show resolved Hide resolved
examples/text-to-speech/websocket/speaker_channel/main.go Outdated Show resolved Hide resolved
@dvonthenen dvonthenen force-pushed the reintroduce-tts-ws branch 2 times, most recently from b4cd96e to a0d17fe Compare September 10, 2024 18:46
Copy link

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c7977f3 and 2a09468.

Files ignored due to path filters (1)
  • hack/check/tools/go.sum is excluded by !**/*.sum
Files selected for processing (56)
  • .golangci.yaml (1 hunks)
  • README.md (2 hunks)
  • docs.go (1 hunks)
  • examples/speech-to-text/websocket/microphone_channel/main.go (1 hunks)
  • examples/speech-to-text/websocket/replay/main.go (1 hunks)
  • examples/speech-to-text/websocket/test/main.go (1 hunks)
  • examples/text-to-speech/rest/file/hello-world/main.go (2 hunks)
  • examples/text-to-speech/websocket/interactive_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/interactive_channel/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_callback/main.go (1 hunks)
  • examples/text-to-speech/websocket/simple_channel/main.go (1 hunks)
  • hack/check/tools/go.mod (2 hunks)
  • pkg/api/listen/v1/websocket/callback_router.go (2 hunks)
  • pkg/api/listen/v1/websocket/chan_router.go (13 hunks)
  • pkg/api/listen/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/listen/v1/websocket/interfaces/types.go (3 hunks)
  • pkg/api/listen/v1/websocket/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/callback_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_default.go (1 hunks)
  • pkg/api/speak/v1/websocket/chan_router.go (1 hunks)
  • pkg/api/speak/v1/websocket/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/constants.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go (1 hunks)
  • pkg/api/speak/v1/websocket/interfaces/types.go (1 hunks)
  • pkg/api/speak/v1/websocket/types.go (1 hunks)
  • pkg/api/version/speakstream-version.go (1 hunks)
  • pkg/audio/common/common.go (1 hunks)
  • pkg/client/common/v1/interfaces/constants.go (1 hunks)
  • pkg/client/common/v1/interfaces/interfaces.go (1 hunks)
  • pkg/client/common/v1/types.go (1 hunks)
  • pkg/client/common/v1/websocket.go (17 hunks)
  • pkg/client/interfaces/interfaces.go (1 hunks)
  • pkg/client/interfaces/v1/options.go (3 hunks)
  • pkg/client/interfaces/v1/types-client.go (1 hunks)
  • pkg/client/interfaces/v1/types-speak.go (2 hunks)
  • pkg/client/listen/client.go (13 hunks)
  • pkg/client/listen/v1/rest/types.go (1 hunks)
  • pkg/client/listen/v1/websocket/client_callback.go (2 hunks)
  • pkg/client/listen/v1/websocket/client_channel.go (2 hunks)
  • pkg/client/listen/v1/websocket/constants.go (2 hunks)
  • pkg/client/listen/v1/websocket/new_using_callbacks.go (5 hunks)
  • pkg/client/listen/v1/websocket/new_using_chan.go (5 hunks)
  • pkg/client/listen/v1/websocket/types.go (3 hunks)
  • pkg/client/speak/client.go (3 hunks)
  • pkg/client/speak/v1/rest/types.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_callback.go (1 hunks)
  • pkg/client/speak/v1/websocket/client_channel.go (1 hunks)
  • pkg/client/speak/v1/websocket/constants.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_callbacks.go (1 hunks)
  • pkg/client/speak/v1/websocket/new_using_chan.go (1 hunks)
  • pkg/client/speak/v1/websocket/types.go (1 hunks)
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json (1 hunks)
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json (1 hunks)
  • tests/unit_test/prerecorded_test.go (1 hunks)
Files skipped from review due to trivial changes (8)
  • examples/text-to-speech/websocket/interactive_callback/main.go
  • pkg/api/speak/v1/websocket/callback_router.go
  • pkg/api/speak/v1/websocket/constants.go
  • pkg/api/speak/v1/websocket/interfaces/constants.go
  • pkg/api/speak/v1/websocket/types.go
  • pkg/client/interfaces/interfaces.go
  • pkg/client/speak/v1/websocket/new_using_callbacks.go
  • tests/unit_test/prerecorded_test.go
Files skipped from review as they are similar to previous changes (38)
  • .golangci.yaml
  • examples/speech-to-text/websocket/microphone_channel/main.go
  • examples/speech-to-text/websocket/replay/main.go
  • examples/speech-to-text/websocket/test/main.go
  • examples/text-to-speech/rest/file/hello-world/main.go
  • examples/text-to-speech/websocket/interactive_channel/main.go
  • examples/text-to-speech/websocket/simple_callback/main.go
  • hack/check/tools/go.mod
  • pkg/api/listen/v1/websocket/callback_router.go
  • pkg/api/listen/v1/websocket/interfaces/constants.go
  • pkg/api/listen/v1/websocket/interfaces/types.go
  • pkg/api/speak/v1/websocket/callback_default.go
  • pkg/api/speak/v1/websocket/chan_default.go
  • pkg/api/speak/v1/websocket/chan_router.go
  • pkg/api/speak/v1/websocket/interfaces/interfaces.go
  • pkg/api/speak/v1/websocket/interfaces/types.go
  • pkg/api/version/speakstream-version.go
  • pkg/client/common/v1/interfaces/constants.go
  • pkg/client/common/v1/interfaces/interfaces.go
  • pkg/client/common/v1/types.go
  • pkg/client/interfaces/v1/options.go
  • pkg/client/interfaces/v1/types-speak.go
  • pkg/client/listen/client.go
  • pkg/client/listen/v1/rest/types.go
  • pkg/client/listen/v1/websocket/client_callback.go
  • pkg/client/listen/v1/websocket/client_channel.go
  • pkg/client/listen/v1/websocket/constants.go
  • pkg/client/listen/v1/websocket/new_using_callbacks.go
  • pkg/client/listen/v1/websocket/new_using_chan.go
  • pkg/client/listen/v1/websocket/types.go
  • pkg/client/speak/v1/rest/types.go
  • pkg/client/speak/v1/websocket/client_callback.go
  • pkg/client/speak/v1/websocket/client_channel.go
  • pkg/client/speak/v1/websocket/constants.go
  • pkg/client/speak/v1/websocket/new_using_chan.go
  • pkg/client/speak/v1/websocket/types.go
  • tests/response_data/642c86c60eedbc4af873632b86d68164149599cf97131d81a63a2711f0563d37-response.json
  • tests/response_data/bfae00d50d521f470ff9d1943f32225fcfeffe51eff47984886930b71fae0929-response.json
Additional context used
Learnings (1)
examples/text-to-speech/websocket/simple_channel/main.go (1)
Learnt from: dvonthenen
PR: deepgram/deepgram-go-sdk#258
File: examples/text-to-speech/websocket/simple_channel/main.go:227-316
Timestamp: 2024-09-09T16:59:02.244Z
Learning: dvonthenen prefers to exclude example code from automated checks in the Deepgram Go SDK repository, as confirmed in PR #258.
golangci-lint
pkg/audio/common/common.go

9-9: could not import github.com/gordonklaus/portaudio (-: # github.com/gordonklaus/portaudio

[pkg-config --cflags -- portaudio-2.0]

Package portaudio-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `portaudio-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'portaudio-2.0', required by 'virtual:world', not found)

(typecheck)

GitHub Check: Lint
pkg/audio/common/common.go

[failure] 9-9:
could not import github.com/gordonklaus/portaudio (-: go build github.com/gordonklaus/portaudio:

Additional comments not posted (32)
pkg/client/interfaces/v1/types-client.go (2)

20-23: LGTM!

The changes improve the semantic organization of the options by explicitly categorizing the fields under speech-to-text options.


25-26: LGTM!

The new field AutoFlushSpeakDelta is appropriately added to support the auto flush feature for text-to-speech functionality.

pkg/api/listen/v1/websocket/interfaces/interfaces.go (2)

Line range hint 10-20: LGTM!

The LiveMessageChan interface looks good. No changes needed.


Line range hint 25-34: LGTM!

The LiveMessageCallback interface looks good. No changes needed.

docs.go (1)

33-33: LGTM!

The change to uncomment the import statement for the WebSocket API in the speak module is approved. This enables the usage of the WebSocket API for real-time text-to-speech functionality, which is consistent with the PR objective of reintroducing the TTS WebSocket feature.

pkg/api/listen/v1/websocket/types.go (4)

Line range hint 15-27:


Line range hint 44-48:


Line range hint 50-54:


Line range hint 29-40: Verify the impact of removing the defaultHandler field.

The removal of the defaultHandler field from the ChanRouter struct suggests a significant change in the event handling mechanism. This could affect the control flow of event routing in the websocket implementation.

Please ensure that:

  1. The removal of this field does not break any existing functionality.
  2. The new event handling mechanism is thoroughly tested.
  3. The documentation is updated to reflect these changes.

Run the following script to verify the usage of the defaultHandler field:

Verification successful

Removal of defaultHandler Field Verified

The defaultHandler field was removed from the ChanRouter struct, and no occurrences of this field were found in the codebase or documentation. This suggests that the field was not actively used, and its removal does not impact existing functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `defaultHandler` field in the codebase.

# Test 1: Search for read accesses to the `defaultHandler` field.
# Expect: No occurrences of read accesses to the field.
rg --type go $'\.defaultHandler'

# Test 2: Search for assignments to the `defaultHandler` field.
# Expect: No occurrences of assignments to the field.
rg --type go $'defaultHandler\s*='

Length of output: 69


Script:

#!/bin/bash
# Description: Search for any documentation or comments referencing `defaultHandler`.

# Test 3: Search for comments or documentation mentioning `defaultHandler`.
# Expect: No occurrences of `defaultHandler` in comments or documentation.
rg --type go --type md --type txt 'defaultHandler'

Length of output: 50

pkg/api/listen/v1/websocket/chan_router.go (12)

87-87: LGTM!

The change from interfaces.TypeOpenResponse to string(interfaces.TypeOpenResponse) is approved as it aligns with the overall transition to string-based handling of message types.


111-111: LGTM!

The change from interfaces.TypeCloseResponse to string(interfaces.TypeCloseResponse) is approved as it aligns with the overall transition to string-based handling of message types.


135-135: LGTM!

The change from interfaces.TypeErrorResponse to string(interfaces.TypeErrorResponse) is approved as it aligns with the overall transition to string-based handling of message types.


139-139: LGTM!

The change of the msgType parameter from interfaces.TypeResponse to string is approved as it aligns with the overall transition to string-based handling of message types.


169-169: LGTM!

The change from interfaces.TypeMessageResponse to string(interfaces.TypeMessageResponse) is approved as it aligns with the overall transition to string-based handling of message types.


186-186: LGTM!

The change from interfaces.TypeMetadataResponse to string(interfaces.TypeMetadataResponse) is approved as it aligns with the overall transition to string-based handling of message types.


203-203: LGTM!

The change from interfaces.TypeSpeechStartedResponse to string(interfaces.TypeSpeechStartedResponse) is approved as it aligns with the overall transition to string-based handling of message types.


220-220: LGTM!

The change from interfaces.TypeUtteranceEndResponse to string(interfaces.TypeUtteranceEndResponse) is approved as it aligns with the overall transition to string-based handling of message types.


237-237: LGTM!

The change from interfaces.TypeErrorResponse to string(interfaces.TypeErrorResponse) is approved as it aligns with the overall transition to string-based handling of message types.


265-265: Verify the change in the TypeErrorResponse case handling.

The TypeErrorResponse case is now treated as interfaces.TypeResponse(interfaces.TypeErrorResponse), which may indicate a shift in how error responses are categorized or processed.

Please provide more context on the implications of this change and ensure that it aligns with the intended behavior for handling error responses.


280-284: LGTM!

The addition of the Binary function as a placeholder for handling binary messages is approved. It can be implemented when the functionality is needed.


301-301: LGTM!

The change of the function parameter from interfaces.TypeResponse to string is approved as it aligns with the overall transition to string-based handling of message types.

examples/text-to-speech/websocket/simple_channel/main.go (1)

227-316: LGTM! The example code demonstrates the usage of the TTS WebSocket functionality effectively.

The main function sets up the TTS client, connects to Deepgram, sends text input, and saves the audio response to a file. Considering that this is an example and not production code, the implementation looks good.

pkg/client/speak/client.go (5)

27-27: Renaming Client type to RESTClient improves clarity.

The renaming of the Client type to RESTClient is a good change as it clearly distinguishes between REST and WebSocket clients, making the code more readable and maintainable.


38-40: Renaming NewWithDefaults to NewRESTWithDefaults is consistent with the RESTClient type.

The renaming of the NewWithDefaults function to NewRESTWithDefaults is a good change as it maintains consistency with the RESTClient type and clearly indicates its association with the REST client.


52-54: Renaming New to NewREST is consistent with the RESTClient type.

The renaming of the New function to NewREST is a good change as it maintains consistency with the RESTClient type and clearly indicates its association with the REST client.


85-87: New functions for WebSocket client creation improve usability and flexibility.

The introduction of new functions for WebSocket client creation, such as NewWSUsingCallbackForDemo, NewWSUsingCallbackWithDefaults, NewWSUsingCallback, and NewWSUsingCallbackWithCancel, is a great addition to the package. These functions provide developers with various options to create WebSocket connections based on their specific requirements, such as using callbacks, default options, or custom cancellation. This improves the usability and flexibility of the WebSocket client.

Also applies to: 103-105, 124-126, 146-148, 166-168, 184-186, 205-207, 227-229


238-240: Handling of deprecated functions and types is well-documented and allows for a smooth transition.

The handling of deprecated functions and types in the package is well-done. Keeping the deprecated entities while marking them for future removal allows for a smooth transition for developers who may still be using the old functions and types. The clear documentation and suggestions for alternatives provide guidance for developers to migrate to the new functions and types.

Also applies to: 245-247, 258-263

README.md (2)

44-47: The previous review comment suggesting to refine the term "Speak API Interfaces" is still valid and applicable to this code segment. Skipping generation of a similar comment.


215-218: LGTM!

The new examples for Text-to-Speech over WebSocket are a great addition to the documentation. The links to the example code are correct and the descriptions are clear.

pkg/client/common/v1/websocket.go (3)

25-25: LGTM!

The changes to the NewWS function are approved. The addition of the router parameter and its assignment to the WSClient instance enhance the functionality of the WebSocket client by integrating routing capabilities.

Also applies to: 42-42


204-210: LGTM, but consider the previous suggestion for error handling.

The addition of the router's Open method invocation after establishing the WebSocket connection is approved. This change enhances the interaction between the WebSocket client and the routing mechanism.

However, please consider the previous suggestion for improving the error handling in this code segment.


537-543: LGTM, but consider the previous suggestion for error handling.

The addition of the router's Close method invocation when closing the WebSocket connection is approved. This change ensures that the router is properly notified of the disconnection.

However, please consider the previous suggestion for improving the error handling in this code segment.

pkg/audio/common/common.go Show resolved Hide resolved
Copy link

@naomi-lgbt naomi-lgbt left a comment

Choose a reason for hiding this comment

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

Looks good

hack/check/tools/go.mod Show resolved Hide resolved
@dvonthenen dvonthenen changed the title [HOLD] Reintroduce TTS WS Reintroduce TTS WS Sep 18, 2024
@dvonthenen dvonthenen merged commit 3a0a4d2 into deepgram:main Sep 18, 2024
4 checks passed
@dvonthenen dvonthenen deleted the reintroduce-tts-ws branch September 18, 2024 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants