assemblyai 4.12.1 → 4.13.0-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/dist/assemblyai.umd.js +210 -4
- package/dist/assemblyai.umd.min.js +1 -1
- package/dist/browser.mjs +207 -5
- package/dist/bun.mjs +207 -5
- package/dist/deno.mjs +207 -5
- package/dist/index.cjs +210 -4
- package/dist/index.mjs +210 -5
- package/dist/node.cjs +207 -4
- package/dist/node.mjs +207 -5
- package/dist/services/index.d.ts +6 -1
- package/dist/services/streaming/factory.d.ts +10 -0
- package/dist/services/streaming/index.d.ts +2 -0
- package/dist/services/streaming/service.d.ts +20 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/openapi.generated.d.ts +1 -1
- package/dist/types/services/index.d.ts +1 -0
- package/dist/types/streaming/index.d.ts +71 -0
- package/dist/utils/errors/index.d.ts +1 -0
- package/dist/utils/errors/streaming.d.ts +23 -0
- package/dist/workerd.mjs +207 -5
- package/package.json +1 -1
- package/src/services/index.ts +14 -0
- package/src/services/streaming/factory.ts +39 -0
- package/src/services/streaming/index.ts +2 -0
- package/src/services/streaming/service.ts +219 -0
- package/src/types/index.ts +2 -1
- package/src/types/openapi.generated.ts +1 -1
- package/src/types/services/index.ts +1 -0
- package/src/types/streaming/index.ts +94 -0
- package/src/utils/errors/index.ts +6 -0
- package/src/utils/errors/streaming.ts +51 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export type StreamingTranscriberParams = {
|
|
2
|
+
websocketBaseUrl?: string;
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
token?: string;
|
|
5
|
+
sampleRate: number;
|
|
6
|
+
|
|
7
|
+
wordFinalizationMaxWaitTime?: number;
|
|
8
|
+
endOfTurnConfidenceThreshold?: number;
|
|
9
|
+
minEndOfTurnSilenceWhenConfident?: number;
|
|
10
|
+
maxTurnSilence?: number;
|
|
11
|
+
formattedFinals?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type StreamingEvents = "open" | "close" | "turn" | "error";
|
|
15
|
+
|
|
16
|
+
export type StreamingListeners = {
|
|
17
|
+
open?: (event: BeginEvent) => void;
|
|
18
|
+
close?: (code: number, reason: string) => void;
|
|
19
|
+
turn?: (event: TurnEvent) => void;
|
|
20
|
+
error?: (error: Error) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type StreamingTokenParams = {
|
|
24
|
+
expires_in_seconds: number;
|
|
25
|
+
max_session_duration_seconds: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type StreamingTemporaryTokenResponse = {
|
|
29
|
+
token: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type StreamingAudioData = ArrayBufferLike;
|
|
33
|
+
|
|
34
|
+
export type BeginEvent = {
|
|
35
|
+
type: "Begin";
|
|
36
|
+
id: string;
|
|
37
|
+
expires_at: number;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type TurnEvent = {
|
|
41
|
+
type: "Turn";
|
|
42
|
+
turn_order: number;
|
|
43
|
+
turn_is_formatted: boolean;
|
|
44
|
+
end_of_turn: boolean;
|
|
45
|
+
transcript: string;
|
|
46
|
+
end_of_turn_confidence: number;
|
|
47
|
+
words: StreamingWord[];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type StreamingWord = {
|
|
51
|
+
start: number;
|
|
52
|
+
end: number;
|
|
53
|
+
confidence: number;
|
|
54
|
+
text: string;
|
|
55
|
+
word_is_final: boolean;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type TerminationEvent = {
|
|
59
|
+
type: "Termination";
|
|
60
|
+
audio_duration_seconds: number;
|
|
61
|
+
session_duration_seconds: number;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type StreamingTerminateSession = {
|
|
65
|
+
type: "Terminate";
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export type StreamingUpdateConfiguration = {
|
|
69
|
+
type: "UpdateConfiguration";
|
|
70
|
+
word_finalization_max_wait_time?: number;
|
|
71
|
+
end_of_turn_confidence_threshold?: number;
|
|
72
|
+
min_end_of_turn_silence_when_confident?: number;
|
|
73
|
+
max_turn_silence?: number;
|
|
74
|
+
formatted_finals?: boolean;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type StreamingForceEndpoint = {
|
|
78
|
+
type: "ForceEndpoint";
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export type ErrorEvent = {
|
|
82
|
+
error: string;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export type StreamingEventMessage =
|
|
86
|
+
| BeginEvent
|
|
87
|
+
| TurnEvent
|
|
88
|
+
| TerminationEvent
|
|
89
|
+
| ErrorEvent;
|
|
90
|
+
|
|
91
|
+
export type StreamingOperationMessage =
|
|
92
|
+
| StreamingUpdateConfiguration
|
|
93
|
+
| StreamingForceEndpoint
|
|
94
|
+
| StreamingTerminateSession;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const StreamingErrorType = {
|
|
2
|
+
BadSampleRate: 4000,
|
|
3
|
+
AuthFailed: 4001,
|
|
4
|
+
InsufficientFunds: 4002,
|
|
5
|
+
FreeTierUser: 4003,
|
|
6
|
+
NonexistentSessionId: 4004,
|
|
7
|
+
SessionExpired: 4008,
|
|
8
|
+
ClosedSession: 4010,
|
|
9
|
+
RateLimited: 4029,
|
|
10
|
+
UniqueSessionViolation: 4030,
|
|
11
|
+
SessionTimeout: 4031,
|
|
12
|
+
AudioTooShort: 4032,
|
|
13
|
+
AudioTooLong: 4033,
|
|
14
|
+
AudioTooSmallToTranscode: 4034,
|
|
15
|
+
BadSchema: 4101,
|
|
16
|
+
TooManyStreams: 4102,
|
|
17
|
+
Reconnected: 4103,
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
type StreamingErrorTypeCodes =
|
|
21
|
+
(typeof StreamingErrorType)[keyof typeof StreamingErrorType];
|
|
22
|
+
|
|
23
|
+
const StreamingErrorMessages: Record<StreamingErrorTypeCodes, string> = {
|
|
24
|
+
[StreamingErrorType.BadSampleRate]: "Sample rate must be a positive integer",
|
|
25
|
+
[StreamingErrorType.AuthFailed]: "Not Authorized",
|
|
26
|
+
[StreamingErrorType.InsufficientFunds]: "Insufficient funds",
|
|
27
|
+
[StreamingErrorType.FreeTierUser]:
|
|
28
|
+
"This feature is paid-only and requires you to add a credit card. Please visit https://app.assemblyai.com/ to add a credit card to your account.",
|
|
29
|
+
[StreamingErrorType.NonexistentSessionId]: "Session ID does not exist",
|
|
30
|
+
[StreamingErrorType.SessionExpired]: "Session has expired",
|
|
31
|
+
[StreamingErrorType.ClosedSession]: "Session is closed",
|
|
32
|
+
[StreamingErrorType.RateLimited]: "Rate limited",
|
|
33
|
+
[StreamingErrorType.UniqueSessionViolation]: "Unique session violation",
|
|
34
|
+
[StreamingErrorType.SessionTimeout]: "Session Timeout",
|
|
35
|
+
[StreamingErrorType.AudioTooShort]: "Audio too short",
|
|
36
|
+
[StreamingErrorType.AudioTooLong]: "Audio too long",
|
|
37
|
+
[StreamingErrorType.AudioTooSmallToTranscode]: "Audio too small to transcode",
|
|
38
|
+
[StreamingErrorType.BadSchema]: "Bad schema",
|
|
39
|
+
[StreamingErrorType.TooManyStreams]: "Too many streams",
|
|
40
|
+
[StreamingErrorType.Reconnected]:
|
|
41
|
+
"This session has been reconnected. This WebSocket is no longer valid.",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
class StreamingError extends Error {}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
StreamingError,
|
|
48
|
+
StreamingErrorType,
|
|
49
|
+
StreamingErrorTypeCodes,
|
|
50
|
+
StreamingErrorMessages,
|
|
51
|
+
};
|