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

feat: add SpeakLiveClient and LiveTTSEvents #306

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

SandraRodgers
Copy link
Contributor

@SandraRodgers SandraRodgers commented Jul 3, 2024

Introduce live speak functionality to existing speak client. Maintain existing interface for batch.

})
);
}
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
/**

})
);
}
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/**
/**

}
}

export { SpeakLiveClient as Liveclient };
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export { SpeakLiveClient as Liveclient };

/**
* Sends a text input message to the server.
*
* @param text - The text to convert to speech.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @param text - The text to convert to speech.
* @param {string} text - The text to convert to speech.

* The `setupConnection` method is responsible for handling the various events that can occur on the WebSocket connection, such as opening, closing, and receiving messages. It sets up event handlers for these events and emits the appropriate events based on the message type.
*
* The `configure` method allows you to send additional configuration options to the connected session.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
*

*
*
* The `requestClose` method requests the server to close the connection.
*
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
*

Comment on lines +289 to +303
/**
* Handles text messages received from the WebSocket connection.
* @param data - The parsed JSON data.
*/
protected handleTextMessage(data: any): void {
// To be implemented by subclasses
}

/**
* Handles binary messages received from the WebSocket connection.
* @param data - The binary data.
*/
protected handleBinaryMessage(data: ArrayBuffer): void {
// To be implemented by subclasses
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this appears to be incomplete? what are subclasses?

const text = "Hello, how can I help you today?";

const deepgram = createClient(process.env.DEEPGRAM_API_KEY, {
global: { fetch: { options: { url: "https://api.beta.deepgram.com" } } },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
global: { fetch: { options: { url: "https://api.beta.deepgram.com" } } },
global: { websocket: { options: { url: "wss://api.beta.deepgram.com" } } },

It seems to look for a websocket override, not a fetch override.

global: { fetch: { options: { url: "https://api.beta.deepgram.com" } } },
});

const connection = deepgram.speak.live({ text }, { model: "aura-asteria-en" });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const connection = deepgram.speak.live({ text }, { model: "aura-asteria-en" });
const connection = deepgram.speak.live({ model: "aura-asteria-en" });

The function definition for this expects SpeakSchema, endpoint - passing the model object as the second argument broke the function.

@@ -2,6 +2,7 @@ import { AbstractClient, noop } from "./AbstractClient";
import { CONNECTION_STATE, SOCKET_STATES } from "../lib/constants";
import type { DeepgramClientOptions, LiveSchema } from "../lib/types";
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need to make any changes to the Abstract client for this work. These edits should instead live inside SpeakLiveClient.ts

@@ -7,4 +7,4 @@ export * from "./ListenRestClient";
export * from "./ManageRestClient";
export * from "./ReadRestClient";
export * from "./SelfHostedRestClient";
export * from "./SpeakRestClient";
Copy link
Contributor

Choose a reason for hiding this comment

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

this file is called a barrel file. it should export all clients that exist in the directory. please export SpeakRestClient, SpeakLiveClient, and SpeakClient

Copy link
Contributor

Choose a reason for hiding this comment

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

For this, I use a tool called auto-barrel which allows you to right-click on a directory and click on "update barrel file", which does it all for you.

* Returns a `SpeakRestClient` instance for interacting with the rest speak API.
*/
get request() {
return new SpeakRestClient(this.options);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good, I assume to provide backwards compatibility with the dot notation we set up for TTS REST

Copy link
Contributor

@lukeocodes lukeocodes Jul 4, 2024

Choose a reason for hiding this comment

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

however I think for this one, there is a slight gotcha with how we initially set it up, and how to maintain the compatibility of it.

If you make get request(){} look like this...

  public request(
    source: TextSource,
    options?: SpeakSchema,
    endpoint = ":version/speak"
  ) {
    const client = new SpeakRestClient(this.options);
 
    return client.request(source, options, endpoint);
  }

it should maintain the interface that exists now to do deepgram.speak.request(...etc), despite adding a class between so we can also do deepgram.speak.live(...etc)

How you have it now looks to me like it would end up being like this deepgram.speak.request.request(...etc)

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.

None yet

3 participants