Skip to content

Commit 6d12413

Browse files
(feat): regenerate with custom models, expression measurement, and empathic voice (#16)
1 parent 4091a52 commit 6d12413

File tree

929 files changed

+17668
-3024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

929 files changed

+17668
-3024
lines changed

.fernignore

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
README.md
44
CITATIONS.md
55
LICENSE
6+
src/core/fetcher/Fetcher.ts
67
src/wrapper/
78
src/index.ts
9+
tests/empathicVoice
10+
tests/expressionMeasurement
811
tsconfig.json

README.md

+66-46
Original file line numberDiff line numberDiff line change
@@ -14,86 +14,106 @@
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 API is namespaced accordingly:
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 SDK supports a request-reply pattern for the streaming expression measurement API.
75+
You'll be able to pass an inference request and `await` till the response is received.
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 SDK supports sending and receiving audio from Empathic Voice. If you're
96+
running with Node.js you can also import our `ffplay` function which will
97+
play the audio for you.
98+
99+
```typescript
100+
import { HumeClient, ffplay } from "hume";
101+
102+
const hume = new HumeClient({
103+
apiKey: "<>",
104+
clientSecret: "<>",
105+
});
106+
107+
const socket = await hume.empathicVoice.chat.connect({
108+
async onMessage(message): Promise<void> {
109+
if (message.type === "audio_output") {
110+
const decoded = Buffer.from(message.data, "base64");
111+
await ffplay(decoded);
112+
}
113+
}
95114
});
96-
console.log(response);
115+
116+
await socket.sendTextInput("Hello, how are you?");
97117
```
98118

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

107127
try {
108-
await hume.submitJob(/* ... */);
128+
await hume.expressionMeasurement.batch.startInferenceJob(/* ... */);
109129
} catch (err) {
110130
if (err instanceof HumeTimeoutError) {
111131
console.log("Request timed out", err);
@@ -124,7 +144,7 @@ try {
124144
You can use the maxRetries option to configure this behavior:
125145

126146
```typescript
127-
await hume.submitJob(..., {
147+
await hume.expressionMeasurement.batch.startInferenceJob(..., {
128148
maxRetries: 0, // disable retries
129149
});
130150
```
@@ -135,7 +155,7 @@ By default, the SDK has a timeout of 60s. You can use the `timeoutInSeconds` opt
135155
this behavior
136156

137157
```typescript
138-
await hume.submitJob(..., {
158+
await hume.expressionMeasurement.batch.startInferenceJob(..., {
139159
timeoutInSeconds: 10, // timeout after 10 seconds
140160
});
141161
```

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hume",
3-
"version": "0.4.2",
3+
"version": "0.0.9",
44
"private": false,
55
"repository": "https://github.com/HumeAI/hume-typescript-sdk",
66
"main": "./index.js",
@@ -17,9 +17,9 @@
1717
"node-fetch": "2.7.0",
1818
"qs": "6.11.2",
1919
"ws": "^8.14.2",
20-
"@types/ws": "^8.5.9",
2120
"uuid": "9.0.1",
22-
"@types/uuid": "9.0.7"
21+
"command-exists": "^1.2.9",
22+
"execa": "^5.1.1"
2323
},
2424
"devDependencies": {
2525
"@types/url-join": "4.0.1",
@@ -30,6 +30,9 @@
3030
"ts-jest": "^29.1.1",
3131
"@types/node": "17.0.33",
3232
"prettier": "2.7.1",
33-
"typescript": "4.6.4"
33+
"typescript": "4.6.4",
34+
"@types/ws": "^8.5.9",
35+
"@types/uuid": "9.0.7",
36+
"@types/command-exists": "^1.2.3"
3437
}
3538
}

0 commit comments

Comments
 (0)