generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 87
Open
Description
Summary
SpeakRestClient only exposes getStream() and getHeaders(). To get the audio as bytes (e.g. to save to file), users must manually consume the stream and buffer chunks. The Python SDK exposes convenience methods (response.stream.getvalue(), .save()) for this. Adding similar methods to the JS SDK would improve parity and reduce boilerplate.
Current usage (from examples/node-speak/index.js):
const stream = await response.getStream();
if (stream) {
const buffer = await new Promise((resolve, reject) => {
const chunks = [];
stream.on("data", (chunk) => chunks.push(chunk));
stream.on("end", () => resolve(Buffer.concat(chunks)));
stream.on("error", reject);
});
writeFileSync(filePath, buffer);
}Proposed API
Add three methods on SpeakRestClient that delegate to the stored Response:
getArrayBuffer(): Promise<ArrayBuffer>–this.result.arrayBuffer()getBlob(): Promise<Blob>–this.result.blob()getBuffer(): Promise<Buffer>– Node.js convenience:Buffer.from(await this.getArrayBuffer())
Same precondition as existing accessors: throw if no request has been made yet (e.g. "Tried to get buffer before making request").
Why
- Matches the convenience the Python SDK provides.
- Reduces repeated stream-to-buffer code.
- Uses standard
ResponseAPIs; small, low-risk change.
Scope
- Implementation in
SpeakRestClient.ts - Tests in the existing speak E2E test file (success path + "no request" error)
- Optional: simplify
examples/node-speak/index.jsto usegetBuffer()
Happy to implement this once maintainers are okay with the direction.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels