-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
48 lines (42 loc) · 1.37 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import 'dotenv/config';
import {
InworldClient,
InworldPacket,
} from '@inworld/nodejs-sdk';
async function sayHello() {
const client = new InworldClient()
// Get key and secret from the integrations page.
.setApiKey({
key: process.env.INWORLD_KEY!,
secret: process.env.INWORLD_SECRET!,
})
// Setup a user name.
// It allows character to call you by name.
.setUser({ fullName: 'Marco' })
// Setup required capabilities.
// In this case you can receive character emotions.
.setConfiguration({
capabilities: { audio: true, emotions: true, phonemes: true },
})
// Use a full character name.
// It should be like workspaces/{WORKSPACE_NAME}/characters/{CHARACTER_NAME}.
// Or like workspaces/{WORKSPACE_NAME}/scenes/{SCENE_NAME}.
.setScene(process.env.INWORLD_SCENE!)
// Attach handlers
.setOnError((err: Error) => console.error(err))
.setOnMessage((packet: InworldPacket) => {
//console.log(packet);
if (packet.isAudio()) {
packet.audio.additionalPhonemeInfo?.forEach(phoneme => console.log(phoneme));
}
if (packet.isInteractionEnd()) {
// Close connection.
connection.close();
}
});
// Finish connection configuration.
const connection = client.build();
// Send your message to a character.
await connection.sendText('Hello');
}
sayHello();