@unith-ai/core-client 2.0.4 → 2.0.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/lib.js +1 -1
- package/dist/lib.js.map +1 -1
- package/dist/lib.modern.js +2 -0
- package/dist/lib.modern.js.map +1 -0
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.web.js +185 -24306
- package/dist/lib.web.js.map +1 -1
- package/dist/microsoft.cognitiveservices.speech.sdk-aac6c80f.js +2 -0
- package/dist/microsoft.cognitiveservices.speech.sdk-aac6c80f.js.map +1 -0
- package/dist/modules/microphone.d.ts +0 -1
- package/dist/modules/microphone.d.ts.map +1 -1
- package/dist/modules/video.d.ts +3 -1
- package/dist/modules/video.d.ts.map +1 -1
- package/dist/modules/vp8.d.ts +0 -2
- package/dist/modules/vp8.d.ts.map +1 -1
- package/dist/types/Conversation.d.ts +1 -0
- package/dist/types/Conversation.d.ts.map +1 -1
- package/dist/types/event.d.ts +6 -4
- package/dist/types/event.d.ts.map +1 -1
- package/dist/types/microphone.d.ts +4 -0
- package/dist/types/microphone.d.ts.map +1 -1
- package/dist/utils/microphone.d.ts +2 -7
- package/dist/utils/microphone.d.ts.map +1 -1
- package/package.json +15 -7
package/README.md
CHANGED
|
@@ -18,6 +18,16 @@ yarn add @unith-ai/core-client
|
|
|
18
18
|
pnpm install @unith-ai/core-client
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
### Azure Speech SDK (Optional)
|
|
22
|
+
|
|
23
|
+
If using `microphoneProvider: "azure"`, install the Azure Speech SDK:
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
npm install microsoft-cognitiveservices-speech-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The SDK is dynamically imported only when the Azure provider is used, so it won't affect bundle size if you use a different provider like `eleven_labs`.
|
|
30
|
+
|
|
21
31
|
## Usage
|
|
22
32
|
|
|
23
33
|
This library is designed for use in plain JavaScript applications or to serve as a foundation for framework-specific implementations. Before integrating it, verify if a dedicated library exists for your particular framework. That said, it's compatible with any project built on JavaScript.
|
|
@@ -62,6 +72,7 @@ const conversation = await Conversation.startDigitalHuman({
|
|
|
62
72
|
- **microphoneProvider** - Provider for the microphone - `"azure" | "eleven_labs"`
|
|
63
73
|
- **microphoneOptions** - Callbacks for microphone events
|
|
64
74
|
- **onMicrophoneSpeechRecognitionResult ({ transcript: string })** - Called when microphone recognizes your user's speech. This returns a transcript. Ideal behavior is to call the `.sendMessage` method with your transcript as microphone doesn't automatically commit / send users text to our AI.
|
|
75
|
+
- **onMicrophonePartialSpeechRecognitionResult ()** - Called when microphone recognizes that the user is trying to speak. This **doesn't** returns a transcript. Ideal behavior is to check if digital human is currently responding (`speaking`) and trigger the stop response method (`.stopResponse`).
|
|
65
76
|
- **onMicrophoneStatusChange ({status})** Called when microphone status changes
|
|
66
77
|
- **status** `"ON" | "OFF" | "PROCESSING"` Shows current status of microphone.
|
|
67
78
|
- **onMicrophoneError ({ message: string })** - Called when microphone has an error with the error message.
|
|
@@ -71,6 +82,7 @@ const conversation = await Conversation.startDigitalHuman({
|
|
|
71
82
|
- **vadThreshold `Number`**
|
|
72
83
|
- **minSpeechDurationMs `Number`**
|
|
73
84
|
- **minSilenceDurationMs `Number`**
|
|
85
|
+
- **disableDynamicSpeechRecognition `Boolean`** - This disables ElevenLabs dynamic speech recognition language detection and uses the language specified during digital human creation.
|
|
74
86
|
|
|
75
87
|
#### Callbacks
|
|
76
88
|
|
|
@@ -101,6 +113,8 @@ Register callbacks to handle various events:
|
|
|
101
113
|
- **onTimeoutWarning** - Called before the session times out. This event warns you that the customers session is going to end in a bit. You can call the `keepSession` method to extend the customers session.
|
|
102
114
|
- **onKeepSession** - Called when a keep-alive request is processed
|
|
103
115
|
- **onError** - Called when an error occurs
|
|
116
|
+
- **onStoppingStart** - Called immediately when a stop request is initiated
|
|
117
|
+
- **onStoppingEnd** - Called once the current response stops playing
|
|
104
118
|
|
|
105
119
|
### Getting Background Video
|
|
106
120
|
|
|
@@ -135,7 +149,7 @@ conversation.sendMessage("Hello, how are you?");
|
|
|
135
149
|
|
|
136
150
|
#### toggleMicrophone()
|
|
137
151
|
|
|
138
|
-
|
|
152
|
+
Toggles microphone status between ON/OFF.
|
|
139
153
|
|
|
140
154
|
```js
|
|
141
155
|
conversation.toggleMicrophone();
|
|
@@ -176,6 +190,17 @@ Get the current user's ID:
|
|
|
176
190
|
const userId = conversation.getUserId();
|
|
177
191
|
```
|
|
178
192
|
|
|
193
|
+
#### stopResponse()
|
|
194
|
+
|
|
195
|
+
Stops the ongoing response and notifies you via two callbacks:
|
|
196
|
+
|
|
197
|
+
- `onStoppingStart()` - Called immediately when stop is initiated.
|
|
198
|
+
- `onStoppingEnd()` - Called once the current response is stopped.
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
await conversation.stopResponse();
|
|
202
|
+
```
|
|
203
|
+
|
|
179
204
|
#### endSession()
|
|
180
205
|
|
|
181
206
|
End the conversation session and clean up resources:
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export declare class Conversation {
|
|
|
29
29
|
private status;
|
|
30
30
|
protected volume: number;
|
|
31
31
|
private sessionStarted;
|
|
32
|
+
private isStoppingLastResponse;
|
|
32
33
|
private messageCounter;
|
|
33
34
|
private syncController;
|
|
34
35
|
private avController;
|
|
@@ -71,12 +72,11 @@ export declare class Conversation {
|
|
|
71
72
|
private handleEndSession;
|
|
72
73
|
private updateStatus;
|
|
73
74
|
/**
|
|
74
|
-
* To stop
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* 3. clear audio queue
|
|
78
|
-
* 4. send an event if all expected response from BE has been received. If not, FE will keep status in 'stopping' mode
|
|
75
|
+
* To stop streaming response, we'll send a stop message to the BE. The BE will then stop sending audio and video frames, which will naturally end the response. This is more efficient and leads to a better user experience as it allows for a smoother transition when stopping the response.
|
|
76
|
+
*
|
|
77
|
+
* To stop cached response, we just stop the video and fade to idle.
|
|
79
78
|
*/
|
|
79
|
+
stopResponse(): Promise<void>;
|
|
80
80
|
toggleMute(): Promise<number>;
|
|
81
81
|
startSession(): Promise<Connection>;
|
|
82
82
|
toggleMicrophone(): Promise<void>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAEhB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAElB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAEhB,cAAc,EACf,MAAM,sBAAsB,CAAC;AAC9B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