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```
2724npm 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
5043console .log (" Running..." );
5144await job .awaitCompletion ();
5245
53- const predictions = await client .getJobPredictions (job .jobId );
46+
47+ const predictions = await hume .expressionMeasurement .batch .getJobPredictions (job .jobId );
5448console .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:
105125import { HumeError , HumeTimeoutError } from " hume" ;
106126
107127try {
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 {
124144You 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
135155this behavior
136156
137157``` typescript
138- await hume .submitJob (... , {
158+ await hume .expressionMeasurement . batch . startInferenceJob (... , {
139159 timeoutInSeconds: 10 , // timeout after 10 seconds
140160});
141161```
0 commit comments