-
Notifications
You must be signed in to change notification settings - Fork 45
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
base: main
Are you sure you want to change the base?
Conversation
}) | ||
); | ||
} | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
/** |
}) | ||
); | ||
} | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
/** |
src/packages/SpeakLiveClient.ts
Outdated
} | ||
} | ||
|
||
export { SpeakLiveClient as Liveclient }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export { SpeakLiveClient as Liveclient }; |
src/packages/SpeakLiveClient.ts
Outdated
/** | ||
* Sends a text input message to the server. | ||
* | ||
* @param text - The text to convert to speech. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @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. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* |
* | ||
* | ||
* The `requestClose` method requests the server to close the connection. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* |
/** | ||
* 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 | ||
} |
There was a problem hiding this comment.
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?
ce206d1
to
9134fb0
Compare
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" } } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
Introduce live speak functionality to existing
speak
client. Maintain existing interface for batch.