Skip to content

Commit c974e04

Browse files
committed
(fix): README
1 parent e9e8d68 commit c974e04

File tree

3 files changed

+71
-59
lines changed

3 files changed

+71
-59
lines changed

README.md

+64-46
Original file line numberDiff line numberDiff line change
@@ -14,86 +14,104 @@
1414
<br>
1515
</div>
1616

17-
> **Note**
18-
> This TypeScript SDK is under heavy development. It is NOT recommended that anyone uses this SDK in their production workloads. We will continue to publish updates to this SDK and hope to ensure a more stable and reliable release in the future. We encourage you to keep up with our [API changelog](https://dev.hume.ai/changelog) and mailing list to stay up to date with the latest changes.
19-
2017
## Documentation
2118

22-
API reference documentation is available [here](https://docs.hume.ai/doc/batch-api).
19+
API reference documentation is available [here](https://dev.hume.ai/reference/).
2320

2421
## Installation
2522

2623
```
2724
npm i hume
2825
```
2926

30-
## Batch Client
31-
32-
The SDK exports a batch client which you can use to hit our REST APIs.
33-
34-
<a href="https://stackblitz.com/edit/typescript-example-using-sdk-built-with-fern-jlhehr?file=app.ts&view=editor"><img src="https://developer.stackblitz.com/img/open_in_stackblitz.svg">
27+
## Usage
3528

3629
```typescript
37-
import { HumeBatchClient } from "hume";
30+
import { HumeClient } from "hume";
3831

39-
const client = new HumeBatchClient({
40-
apiKey: "YOUR_API_KEY",
32+
const hume = new HumeClient({
33+
apiKey: "YOUR_API_KEY"
4134
});
4235

43-
const job = await client.submitJob({
44-
urls: ["https://tinyurl.com/hume-img"],
36+
const job = await hume.expressionMeasurement.batch.startInferenceJob({
4537
models: {
46-
face: {},
38+
face: {}
4739
},
40+
urls: ["https://hume-tutorials.s3.amazonaws.com/faces.zip"]
4841
});
4942

5043
console.log("Running...");
5144
await job.awaitCompletion();
5245

53-
const predictions = await client.getJobPredictions(job.jobId);
46+
47+
const predictions = await hume.expressionMeasurement.batch.getJobPredictions(job.jobId);
5448
console.log(predictions)
5549
```
5650

57-
## Streaming Client
51+
## Namespaces
52+
This SDK contains the APIs for expression measurement, empathic voice and custom models. Even
53+
if you do not plan on using more than one API to start, the SDK provides easy access in
54+
case you find additional APIs in the future.
5855

59-
The SDK exports a streaming client which you can use to hit our WebSocket APIs.
56+
Each category is namespaced:
6057

6158
```typescript
62-
import { HumeStreamingClient } from "hume";
59+
import { HumeClient } from "hume";
6360

64-
const client = new HumeStreamingClient({
65-
apiKey: "YOUR_API_KEY",
61+
const hume = new HumeClient({
62+
apiKey: "YOUR_API_KEY"
6663
});
6764

68-
const stream = client.connect({
69-
config: {
70-
language: {},
71-
},
72-
onMessage: (response) => { console.log("Socket opened") },
73-
onWarning: (warning) => { console.log(warning)},
74-
onError: (error) => { console.log(error)},
75-
onClose: () => { console.log("Socket closed")},
76-
});
65+
hume.expressionMeasurement. // APIs specific to Expression Measurement
7766

78-
const response = await stream.sendText({
79-
text: "Mary had a little lamb,"
80-
});
81-
console.log(response);
67+
hume.emapthicVoice. // APIs specific to Empathic Voice
8268
```
8369

84-
### Sending Files
85-
You can use the `sendFile` method to upload files.
70+
## Websockets
71+
The SDK supports interacting with both WebSocket and REST APIs.
72+
73+
### Request-Reply
74+
The expression measurement SDK supports a request-reply pattern,
75+
where you can send text and wait till the model provides a result.
8676

8777
```typescript
88-
const response = await socket.sendFile({
89-
file: fs.createReadStream(path.join(__dirname, "obama.png")),
78+
import { HumeClient } from "hume";
79+
80+
const hume = new HumeClient({
81+
apiKey: "YOUR_API_KEY"
82+
});
83+
const socket = hume.expressionMeasurement.stream.connect({
9084
config: {
91-
face: {
92-
identifyFaces: true,
93-
},
94-
},
85+
language: {}
86+
}
87+
});
88+
for (const sample of samples) {
89+
const result = await socket.sendText({ text: sample })
90+
console.log(result)
91+
}
92+
```
93+
94+
### Empathic Voice
95+
The empathic voice API is also accessible via the SDK.
96+
97+
```typescript
98+
import { HumeClient, ffplay } from "hume";
99+
100+
const hume = new HumeClient({
101+
apiKey: "<>",
102+
clientSecret: "<>",
103+
});
104+
105+
const socket = await hume.empathicVoice.chat.connect({
106+
async onMessage(message): Promise<void> {
107+
if (message.type === "audio_output") {
108+
const decoded = Buffer.from(message.data, "base64");
109+
await ffplay(decoded);
110+
}
111+
}
95112
});
96-
console.log(response);
113+
114+
await socket.sendTextInput("Hello, how are you?");
97115
```
98116

99117
## Errors
@@ -105,7 +123,7 @@ a subclass of [HumeError](./src/errors/HumeError.ts) will be thrown:
105123
import { HumeError, HumeTimeoutError } from "hume";
106124

107125
try {
108-
await hume.submitJob(/* ... */);
126+
await hume.expressionMeasurement.batch.submitJob(/* ... */);
109127
} catch (err) {
110128
if (err instanceof HumeTimeoutError) {
111129
console.log("Request timed out", err);
@@ -124,7 +142,7 @@ try {
124142
You can use the maxRetries option to configure this behavior:
125143

126144
```typescript
127-
await hume.submitJob(..., {
145+
await hume.expressionMeasurement.batch.submitJob(..., {
128146
maxRetries: 0, // disable retries
129147
});
130148
```
@@ -135,7 +153,7 @@ By default, the SDK has a timeout of 60s. You can use the `timeoutInSeconds` opt
135153
this behavior
136154

137155
```typescript
138-
await hume.submitJob(..., {
156+
await hume.expressionMeasurement.batch.submitJob(..., {
139157
timeoutInSeconds: 10, // timeout after 10 seconds
140158
});
141159
```

src/wrapper/empathicVoice/chat/StreamSocket.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export class StreamSocket {
3232
/**
3333
* Send text input
3434
*/
35-
public async sendTextInput(message: Hume.empathicVoice.TextInput): Promise<void> {
36-
console.log("sendTextInput", message);
37-
await this.send(message);
35+
public async sendTextInput(text: string): Promise<void> {
36+
await this.send({
37+
type: "user_input",
38+
text,
39+
});
3840
}
3941

4042
/**
@@ -61,11 +63,6 @@ export class StreamSocket {
6163
this.websocket.send(JSON.stringify(jsonPayload));
6264
}
6365

64-
public async sendRaw(value: any): Promise<void> {
65-
await this.tillSocketOpen();
66-
this.websocket.send(JSON.stringify(value));
67-
}
68-
6966
private async tillSocketOpen(): Promise<WebSocket> {
7067
if (this.websocket.readyState === WebSocket.OPEN) {
7168
return this.websocket;

tests/empathicVoice/chat.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HumeClient, ffplay, base64Decode } from "../../src/";
1+
import { HumeClient, ffplay } from "../../src/";
22

33
describe("Empathic Voice Interface", () => {
44
it.skip("Chat", async () => {
@@ -16,10 +16,7 @@ describe("Empathic Voice Interface", () => {
1616
}
1717
});
1818

19-
await socket.sendRaw({
20-
type: "user_input",
21-
text: "Hello, how are you?",
22-
});
19+
await socket.sendTextInput("Hello, how are you?");
2320

2421
}, 100000);
2522
});

0 commit comments

Comments
 (0)