14
14
<br >
15
15
</div >
16
16
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
-
20
17
## Documentation
21
18
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/ ) .
23
20
24
21
## Installation
25
22
26
23
```
27
24
npm i hume
28
25
```
29
26
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
35
28
36
29
``` typescript
37
- import { HumeBatchClient } from " hume" ;
30
+ import { HumeClient } from " hume" ;
38
31
39
- const client = new HumeBatchClient ({
40
- apiKey: " YOUR_API_KEY" ,
32
+ const hume = new HumeClient ({
33
+ apiKey: " YOUR_API_KEY"
41
34
});
42
35
43
- const job = await client .submitJob ({
44
- urls: [" https://tinyurl.com/hume-img" ],
36
+ const job = await hume .expressionMeasurement .batch .startInferenceJob ({
45
37
models: {
46
- face: {},
38
+ face: {}
47
39
},
40
+ urls: [" https://hume-tutorials.s3.amazonaws.com/faces.zip" ]
48
41
});
49
42
50
43
console .log (" Running..." );
51
44
await job .awaitCompletion ();
52
45
53
- const predictions = await client .getJobPredictions (job .jobId );
46
+
47
+ const predictions = await hume .expressionMeasurement .batch .getJobPredictions (job .jobId );
54
48
console .log (predictions )
55
49
```
56
50
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.
58
55
59
- The SDK exports a streaming client which you can use to hit our WebSocket APIs.
56
+ Each API is namespaced accordingly:
60
57
61
58
``` typescript
62
- import { HumeStreamingClient } from " hume" ;
59
+ import { HumeClient } from " hume" ;
63
60
64
- const client = new HumeStreamingClient ({
65
- apiKey: " YOUR_API_KEY" ,
61
+ const hume = new HumeClient ({
62
+ apiKey: " YOUR_API_KEY"
66
63
});
67
64
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
77
66
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
82
68
```
83
69
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.
86
76
87
77
``` 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 ({
90
84
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
+ }
95
114
});
96
- console .log (response );
115
+
116
+ await socket .sendTextInput (" Hello, how are you?" );
97
117
```
98
118
99
119
## Errors
@@ -105,7 +125,7 @@ a subclass of [HumeError](./src/errors/HumeError.ts) will be thrown:
105
125
import { HumeError , HumeTimeoutError } from " hume" ;
106
126
107
127
try {
108
- await hume .submitJob (/* ... */ );
128
+ await hume .expressionMeasurement . batch . startInferenceJob (/* ... */ );
109
129
} catch (err ) {
110
130
if (err instanceof HumeTimeoutError ) {
111
131
console .log (" Request timed out" , err );
@@ -124,7 +144,7 @@ try {
124
144
You can use the maxRetries option to configure this behavior:
125
145
126
146
``` typescript
127
- await hume .submitJob (... , {
147
+ await hume .expressionMeasurement . batch . startInferenceJob (... , {
128
148
maxRetries: 0 , // disable retries
129
149
});
130
150
```
@@ -135,7 +155,7 @@ By default, the SDK has a timeout of 60s. You can use the `timeoutInSeconds` opt
135
155
this behavior
136
156
137
157
``` typescript
138
- await hume .submitJob (... , {
158
+ await hume .expressionMeasurement . batch . startInferenceJob (... , {
139
159
timeoutInSeconds: 10 , // timeout after 10 seconds
140
160
});
141
161
```
0 commit comments