@elevenlabs/client 0.12.1 → 0.13.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.
- package/.turbo/turbo-build.log +12 -12
- package/.turbo/turbo-generate-version.log +1 -1
- package/README.md +6 -0
- package/dist/VoiceConversation.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/lib.cjs +1 -1
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.modern.js +1 -1
- package/dist/lib.modern.js.map +1 -1
- package/dist/lib.module.js +1 -1
- package/dist/lib.module.js.map +1 -1
- package/dist/lib.umd.js +1 -1
- package/dist/lib.umd.js.map +1 -1
- package/dist/scribe/scribe.d.ts +1 -1
- package/dist/utils/BaseConnection.d.ts +3 -0
- package/dist/utils/errors.d.ts +8 -0
- package/dist/utils/events.d.ts +2 -0
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/worklets/scribeAudioProcessor.js +56 -2
package/dist/scribe/scribe.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface AudioOptions extends BaseOptions {
|
|
|
73
73
|
*/
|
|
74
74
|
export interface MicrophoneOptions extends BaseOptions {
|
|
75
75
|
microphone?: {
|
|
76
|
-
deviceId?:
|
|
76
|
+
deviceId?: ConstrainDOMString;
|
|
77
77
|
echoCancellation?: boolean;
|
|
78
78
|
noiseSuppression?: boolean;
|
|
79
79
|
autoGainControl?: boolean;
|
package/dist/utils/events.d.ts
CHANGED
|
@@ -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;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "0.
|
|
1
|
+
export declare const PACKAGE_VERSION = "0.13.0";
|
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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) {
|