@vapi-ai/web 2.6.2 → 2.7.0

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.
Files changed (8) hide show
  1. package/README.md +60 -0
  2. package/api.ts +25665 -11101
  3. package/dist/api.d.ts +22973 -13375
  4. package/dist/api.js +2171 -697
  5. package/dist/vapi.d.ts +82 -1
  6. package/dist/vapi.js +295 -88
  7. package/package.json +1 -1
  8. package/vapi.ts +339 -95
package/README.md CHANGED
@@ -105,6 +105,61 @@ The `say(message: string, endCallAfterSpoken?: boolean)` can be used to invoke s
105
105
  vapi.say("Our time's up, goodbye!", true)
106
106
  ```
107
107
 
108
+ The `setVolume(volume: number)` controls how loudly the assistant plays, from
109
+ `0` to `1`. This is playback only: it does not change what the assistant hears,
110
+ and it does not affect the levels reported by the `volume-level` event.
111
+
112
+ ```javascript
113
+ vapi.setVolume(0.5);
114
+ ```
115
+
116
+ The setting is remembered, so you can call it before a call has started and it
117
+ will be applied as soon as the assistant's audio arrives. It also persists
118
+ across calls, so a volume your user picked once is not reset by hanging up.
119
+ Values outside `0` to `1` are clamped, and non-finite values are ignored.
120
+
121
+ The `getAudioPlayer()` returns the `<audio>` element the SDK uses to play the
122
+ assistant, or `null` before its track has arrived. Use it for anything the
123
+ setter doesn't cover, such as driving a waveform visualizer.
124
+
125
+ ```javascript
126
+ const player = vapi.getAudioPlayer();
127
+ ```
128
+
129
+ Pair it with the `audio` event when you need the element the moment it exists:
130
+
131
+ ```javascript
132
+ vapi.on('audio', (player) => {
133
+ // e.g. new AudioContext().createMediaElementSource(player)
134
+ });
135
+ ```
136
+
137
+ If the browser blocks playback, usually its autoplay policy when the call was
138
+ not started from a user gesture, no player is attached and an `error` is
139
+ emitted instead. Listen for it to prompt the user:
140
+
141
+ ```javascript
142
+ vapi.on('error', (e) => {
143
+ if (e.type === 'audio-start-failed') {
144
+ // show a "tap to enable audio" affordance
145
+ }
146
+ });
147
+ ```
148
+
149
+ ## Recording
150
+
151
+ When video recording is enabled on the call's artifact plan, Vapi starts a recording automatically when the call begins. When the server provides a meeting token for the call (`call.transport.callToken`), the SDK joins with it and Daily auto-starts the cloud recording, which is more reliable on weak networks. Otherwise the SDK starts the recording from the client after joining. Recording start is asynchronous: success is signaled by the `recording-started` event and failure by the `recording-error` event.
152
+
153
+ A failed recording start is not retried automatically. Use `startRecording()` and `stopRecording()` to control the recording yourself. For example, to retry after a failure:
154
+
155
+ ```javascript
156
+ vapi.on('recording-error', (e) => {
157
+ console.error('Recording failed', e);
158
+ // Retry after a short delay
159
+ setTimeout(() => vapi.startRecording(), 5000);
160
+ });
161
+ ```
162
+
108
163
  ## Events
109
164
 
110
165
  You can listen to the following events:
@@ -130,6 +185,11 @@ vapi.on('volume-level', (volume) => {
130
185
  console.log(`Assistant volume level: ${volume}`);
131
186
  });
132
187
 
188
+ // The <audio> element playing the assistant, as soon as it exists
189
+ vapi.on('audio', (player) => {
190
+ console.log(`Assistant audio attached at volume ${player.volume}`);
191
+ });
192
+
133
193
  // Function calls and transcripts will be sent via messages
134
194
  vapi.on('message', (message) => {
135
195
  console.log(message);