@bevyra/avatar 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.d.ts +1 -1
- package/index.js +16 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ const client = new AvatarClient({ apiKey: process.env.BEVYRA_API_KEY });
|
|
|
19
19
|
client.activate();
|
|
20
20
|
client.download('noora');
|
|
21
21
|
const { url, token } = await client.start();
|
|
22
|
-
const session = await client.connect('noora');
|
|
22
|
+
const session = await client.connect('noora'); // Off-white background by default.
|
|
23
23
|
const clauseId = session.sendAudio(pcm16At16kHz);
|
|
24
24
|
for await (const event of session.events()) {
|
|
25
25
|
// clause.audio precedes binary PCM; clause.frame precedes binary JPEG.
|
|
@@ -36,4 +36,4 @@ for await (const event of session.events()) {
|
|
|
36
36
|
session.close(); client.close();
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
Other local processes can use `url` and `token` to connect to the loopback WebSocket. Keep the token private. `npx bevyra-avatar serve` prints them as JSON. Send complete speech units with natural pauses; `session.interrupt` cancels the current generation. See the [Python package protocol](../avatar-python/README.md).
|
|
39
|
+
Speech and idle JPEGs are composited over off-white `#F5F3EE` by default. Pass `{ background: '#FFFFFF' }` for a solid color, or `{ background: readFileSync('background.gif'), width: 720, height: 1280 }` for an image. JPEG, PNG, GIF and WebP buffers or data URLs are accepted; animated GIF and WebP loop through speech and idle. Images fill the requested dimensions by center cropping while the avatar keeps its aspect ratio. Images must be 64–4096 pixels per side and at most 8 MiB; animation is limited to 300 frames and 30 seconds. Output dimensions must be 160–1920 pixels per side and at most 2.07 megapixels. Other local processes can use `url` and `token` to connect to the loopback WebSocket. Keep the token private. `npx bevyra-avatar serve` prints them as JSON. Send complete speech units with natural pauses; `session.interrupt` cancels the current generation. See the [Python package protocol](../avatar-python/README.md).
|
package/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class AvatarClient {
|
|
|
7
7
|
assign(slot: number, avatar: string, replace?: boolean): Record<string, unknown>;
|
|
8
8
|
download(avatar: string): { avatar: string; path: string };
|
|
9
9
|
start(options?: { port?: number }): Promise<{ url: string; token: string }>;
|
|
10
|
-
connect(avatar: string): Promise<AvatarSession>;
|
|
10
|
+
connect(avatar: string, options?: { background?: string | Uint8Array; width?: number; height?: number }): Promise<AvatarSession>;
|
|
11
11
|
close(): void;
|
|
12
12
|
}
|
|
13
13
|
export declare class AvatarSession {
|
package/index.js
CHANGED
|
@@ -6,7 +6,18 @@ import path from "node:path";
|
|
|
6
6
|
import readline from "node:readline";
|
|
7
7
|
import WebSocket from "ws";
|
|
8
8
|
|
|
9
|
-
const VERSION = "1.0.
|
|
9
|
+
const VERSION = "1.0.8";
|
|
10
|
+
|
|
11
|
+
function backgroundValue(value) {
|
|
12
|
+
if (value == null || typeof value === "string") return value;
|
|
13
|
+
const bytes = Buffer.from(value);
|
|
14
|
+
const mime = bytes.subarray(0, 3).equals(Buffer.from("GIF")) ? "image/gif"
|
|
15
|
+
: bytes.subarray(0, 4).equals(Buffer.from([0x52, 0x49, 0x46, 0x46])) && bytes.subarray(8, 12).toString() === "WEBP" ? "image/webp"
|
|
16
|
+
: bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) ? "image/png"
|
|
17
|
+
: bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255])) ? "image/jpeg" : null;
|
|
18
|
+
if (!mime) throw new TypeError("Background must be JPEG, PNG, GIF, WebP, a data URL, or #RRGGBB");
|
|
19
|
+
return `data:${mime};base64,${bytes.toString("base64")}`;
|
|
20
|
+
}
|
|
10
21
|
|
|
11
22
|
function python() {
|
|
12
23
|
if (process.env.BEVYRA_PYTHON) return { executable: process.env.BEVYRA_PYTHON, prefix: [] };
|
|
@@ -63,12 +74,14 @@ export class AvatarClient {
|
|
|
63
74
|
this.server = { ...ready, child };
|
|
64
75
|
return { url: ready.url, token: ready.token };
|
|
65
76
|
}
|
|
66
|
-
connect(avatar) {
|
|
77
|
+
connect(avatar, { background, width, height } = {}) {
|
|
67
78
|
if (!this.server) throw new Error("Start the local renderer first");
|
|
68
79
|
return new Promise((resolve, reject) => {
|
|
69
80
|
const url = new URL("/v1/stream", this.server.url); url.protocol = "ws:";
|
|
70
81
|
const socket = new WebSocket(url, { headers: { Authorization: `Bearer ${this.server.token}` } });
|
|
71
|
-
socket.once("open", () => { socket.send(JSON.stringify({ type: "session.setup", avatar
|
|
82
|
+
socket.once("open", () => { socket.send(JSON.stringify({ type: "session.setup", avatar,
|
|
83
|
+
...(background != null ? { background: backgroundValue(background) } : {}),
|
|
84
|
+
...(width != null ? { width } : {}), ...(height != null ? { height } : {}) })); resolve(new AvatarSession(socket)); });
|
|
72
85
|
socket.once("error", reject);
|
|
73
86
|
});
|
|
74
87
|
}
|