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 category is namespaced:
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 expression measurement SDK supports a request-reply pattern,
75
+ where you can send text and wait till the model provides a result.
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 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
+ }
95
112
});
96
- console .log (response );
113
+
114
+ await socket .sendTextInput (" Hello, how are you?" );
97
115
```
98
116
99
117
## Errors
@@ -105,7 +123,7 @@ a subclass of [HumeError](./src/errors/HumeError.ts) will be thrown:
105
123
import { HumeError , HumeTimeoutError } from " hume" ;
106
124
107
125
try {
108
- await hume .submitJob (/* ... */ );
126
+ await hume .expressionMeasurement . batch . submitJob (/* ... */ );
109
127
} catch (err ) {
110
128
if (err instanceof HumeTimeoutError ) {
111
129
console .log (" Request timed out" , err );
@@ -124,7 +142,7 @@ try {
124
142
You can use the maxRetries option to configure this behavior:
125
143
126
144
``` typescript
127
- await hume .submitJob (... , {
145
+ await hume .expressionMeasurement . batch . submitJob (... , {
128
146
maxRetries: 0 , // disable retries
129
147
});
130
148
```
@@ -135,7 +153,7 @@ By default, the SDK has a timeout of 60s. You can use the `timeoutInSeconds` opt
135
153
this behavior
136
154
137
155
``` typescript
138
- await hume .submitJob (... , {
156
+ await hume .expressionMeasurement . batch . submitJob (... , {
139
157
timeoutInSeconds: 10 , // timeout after 10 seconds
140
158
});
141
159
```
0 commit comments