@elevenlabs/client 0.12.2 → 0.13.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.
@@ -73,7 +73,7 @@ export interface AudioOptions extends BaseOptions {
73
73
  */
74
74
  export interface MicrophoneOptions extends BaseOptions {
75
75
  microphone?: {
76
- deviceId?: string;
76
+ deviceId?: ConstrainDOMString;
77
77
  echoCancellation?: boolean;
78
78
  noiseSuppression?: boolean;
79
79
  autoGainControl?: boolean;
@@ -30,6 +30,8 @@ export type BaseSessionConfig = {
30
30
  tts?: {
31
31
  voiceId?: string;
32
32
  speed?: number;
33
+ stability?: number;
34
+ similarityBoost?: number;
33
35
  };
34
36
  conversation?: {
35
37
  textOnly?: boolean;
@@ -0,0 +1,8 @@
1
+ export declare class SessionConnectionError extends Error {
2
+ readonly closeCode?: number;
3
+ readonly closeReason?: string;
4
+ constructor(message: string, options?: {
5
+ closeCode?: number;
6
+ closeReason?: string;
7
+ });
8
+ }
@@ -1,4 +1,5 @@
1
1
  import { Outgoing } from "@elevenlabs/types";
2
+ import type { AudioAlignmentEvent } from "@elevenlabs/types";
2
3
  import { AgentChatResponsePartClientEvent, AgentResponse, AgentResponseCorrection, AgentToolResponseClientEvent, AsrInitiationMetadataEvent as AsrMetadataEvent, Audio, AgentToolRequestClientEvent, ClientToolCallMessage, ConversationMetadata, ErrorMessage, Interruption, McpConnectionStatusClientEvent, McpToolCall, Ping, InternalTentativeAgentResponse as TentativeAgentResponseInternal, UserTranscript, VadScore } from "@elevenlabs/types/generated/types/asyncapi-types";
3
4
  export type UserTranscriptionEvent = UserTranscript;
4
5
  export type AgentResponseEvent = AgentResponse;
@@ -18,6 +19,7 @@ export type AsrInitiationMetadataEvent = AsrMetadataEvent;
18
19
  export type MCPConnectionStatusEvent = McpConnectionStatusClientEvent;
19
20
  export type AgentChatResponsePartEvent = AgentChatResponsePartClientEvent;
20
21
  export type ErrorMessageEvent = ErrorMessage;
22
+ export type { AudioAlignmentEvent };
21
23
  export type IncomingSocketEvent = UserTranscriptionEvent | AgentResponseEvent | AgentResponseCorrectionEvent | AgentAudioEvent | InterruptionEvent | InternalTentativeAgentResponseEvent | ConfigEvent | PingEvent | ClientToolCallEvent | VadScoreEvent | MCPToolCallClientEvent | AgentToolRequestEvent | AgentToolResponseEvent | ConversationMetadataEvent | AsrInitiationMetadataEvent | MCPConnectionStatusEvent | AgentChatResponsePartEvent | ErrorMessageEvent;
22
24
  export type PongEvent = Outgoing.PongClientToOrchestratorEvent;
23
25
  export type UserAudioEvent = Outgoing.UserAudio;
@@ -3,6 +3,7 @@ import type { AudioWorkletConfig } from "../BaseConversation";
3
3
  export type InputConfig = {
4
4
  preferHeadphonesForIosDevices?: boolean;
5
5
  inputDeviceId?: string;
6
+ onError?(message: string, context?: unknown): void;
6
7
  };
7
8
  export declare class Input {
8
9
  readonly context: AudioContext;
@@ -10,10 +11,15 @@ export declare class Input {
10
11
  readonly worklet: AudioWorkletNode;
11
12
  inputStream: MediaStream;
12
13
  private mediaStreamSource;
13
- static create({ sampleRate, format, preferHeadphonesForIosDevices, inputDeviceId, workletPaths, libsampleratePath, }: FormatConfig & InputConfig & AudioWorkletConfig): Promise<Input>;
14
+ private permissions;
15
+ private onError;
16
+ static create({ sampleRate, format, preferHeadphonesForIosDevices, inputDeviceId, workletPaths, libsampleratePath, onError, }: FormatConfig & InputConfig & AudioWorkletConfig): Promise<Input>;
14
17
  private static getDeviceIdConstraint;
15
18
  private constructor();
19
+ private forgetInputStreamAndSource;
16
20
  close(): Promise<void>;
17
21
  setMuted(isMuted: boolean): void;
22
+ private settingInput;
18
23
  setInputDevice(inputDeviceId?: string): Promise<void>;
24
+ private handlePermissionsChange;
19
25
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const PACKAGE_VERSION = "0.12.2";
1
+ export declare const PACKAGE_VERSION = "0.13.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevenlabs/client",
3
- "version": "0.12.2",
3
+ "version": "0.13.1",
4
4
  "description": "ElevenLabs JavaScript Client Library",
5
5
  "main": "./dist/lib.umd.js",
6
6
  "module": "./dist/lib.module.js",
@@ -1,5 +1,7 @@
1
1
  /*
2
2
  * Scribe Audio Processor for converting microphone audio to PCM16 format
3
+ * Supports resampling for browsers like Firefox that don't support
4
+ * AudioContext sample rate constraints.
3
5
  * USED BY @elevenlabs/client
4
6
  */
5
7
 
@@ -8,15 +10,67 @@ class ScribeAudioProcessor extends AudioWorkletProcessor {
8
10
  super();
9
11
  this.buffer = [];
10
12
  this.bufferSize = 4096; // Buffer size for optimal chunk transmission
13
+
14
+ // Resampling state
15
+ this.inputSampleRate = null;
16
+ this.outputSampleRate = null;
17
+ this.resampleRatio = 1;
18
+ this.lastSample = 0;
19
+ this.resampleAccumulator = 0;
20
+
21
+ this.port.onmessage = ({ data }) => {
22
+ if (data.type === "configure") {
23
+ this.inputSampleRate = data.inputSampleRate;
24
+ this.outputSampleRate = data.outputSampleRate;
25
+ if (this.inputSampleRate && this.outputSampleRate) {
26
+ this.resampleRatio = this.inputSampleRate / this.outputSampleRate;
27
+ }
28
+ }
29
+ };
30
+ }
31
+
32
+ // Linear interpolation resampling
33
+ resample(inputData) {
34
+ if (this.resampleRatio === 1 || !this.inputSampleRate) {
35
+ return inputData;
36
+ }
37
+
38
+ const outputSamples = [];
39
+
40
+ for (let i = 0; i < inputData.length; i++) {
41
+ const currentSample = inputData[i];
42
+
43
+ // Generate output samples using linear interpolation
44
+ while (this.resampleAccumulator < 1) {
45
+ const interpolated =
46
+ this.lastSample +
47
+ (currentSample - this.lastSample) * this.resampleAccumulator;
48
+ outputSamples.push(interpolated);
49
+ this.resampleAccumulator += this.resampleRatio;
50
+ }
51
+
52
+ this.resampleAccumulator -= 1;
53
+ this.lastSample = currentSample;
54
+ }
55
+
56
+ return new Float32Array(outputSamples);
11
57
  }
12
58
 
13
59
  process(inputs) {
14
60
  const input = inputs[0];
15
61
  if (input.length > 0) {
16
- const channelData = input[0]; // Get first channel (mono)
62
+ let channelData = input[0]; // Get first channel (mono)
63
+
64
+ // Resample if needed (for Firefox and other browsers that don't
65
+ // support AudioContext sample rate constraints)
66
+ if (this.resampleRatio !== 1) {
67
+ channelData = this.resample(channelData);
68
+ }
17
69
 
18
70
  // Add incoming audio to buffer
19
- this.buffer.push(...channelData);
71
+ for (let i = 0; i < channelData.length; i++) {
72
+ this.buffer.push(channelData[i]);
73
+ }
20
74
 
21
75
  // When buffer reaches threshold, convert and send
22
76
  if (this.buffer.length >= this.bufferSize) {