@happyvertical/speech 0.102.0 → 0.102.2
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/adapters/local/audio.d.ts +11 -1
- package/dist/adapters/local/env.d.ts +6 -2
- package/dist/adapters/local/runtime.d.ts +8 -1
- package/dist/adapters/local/transcriber.d.ts +3 -3
- package/dist/adapters/local/types.d.ts +7 -1
- package/dist/adapters/local/worker.d.ts +13 -3
- package/dist/adapters/openai-compatible-transcriber.d.ts +1 -1
- package/dist/adapters/openai-compatible.d.ts +1 -1
- package/dist/adapters/openai-realtime.d.ts +13 -2
- package/dist/adapters/qwen3.d.ts +1 -1
- package/dist/adapters/studio-server.d.ts +1 -1
- package/dist/adapters/voxtral-realtime.d.ts +36 -2
- package/dist/conversation/openai-webrtc.d.ts +1 -1
- package/dist/conversation-server.d.ts +3 -2
- package/dist/local.d.ts +20 -2
- package/dist/shared/audio.d.ts +7 -1
- package/dist/shared/env.d.ts +8 -1
- package/dist/shared/factory.d.ts +2 -2
- package/dist/shared/http.d.ts +2 -2
- package/dist/shared/input-format.d.ts +1 -1
- package/dist/shared/pcm.d.ts +6 -1
- package/dist/shared/realtime-auth.d.ts +10 -2
- package/dist/shared/realtime-session.d.ts +14 -5
- package/dist/shared/registry.d.ts +10 -2
- package/dist/shared/streaming-client-secret.d.ts +21 -3
- package/dist/shared/streaming-factory.d.ts +7 -3
- package/dist/shared/streaming-types.d.ts +10 -3
- package/dist/shared/turn-limit.d.ts +13 -1
- package/dist/shared/types.d.ts +4 -4
- package/package.json +1 -1
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Audio decoding for on-device inference: turns encoded bytes into 16 kHz
|
|
3
|
+
* mono Float32 PCM, the input Whisper and Moonshine expect.
|
|
4
|
+
*
|
|
5
|
+
* - WAV (PCM 8/16/24/32-bit, IEEE float 32/64, WAVE_FORMAT_EXTENSIBLE) and raw
|
|
6
|
+
* `audio/pcm` are decoded in-process in every runtime, including workers.
|
|
7
|
+
* - Anything else goes to the caller's `decodeAudio` hook, or, in browsers,
|
|
8
|
+
* to `OfflineAudioContext.decodeAudioData` (MediaRecorder WebM/Opus, Safari
|
|
9
|
+
* `audio/mp4`, MP3, ...).
|
|
10
|
+
*/
|
|
11
|
+
import type { DecodedAudio, LocalAudioDecoder } from './types.js';
|
|
2
12
|
/** Sample rate expected by Whisper and Moonshine feature extractors. */
|
|
3
13
|
export declare const LOCAL_SAMPLE_RATE = 16000;
|
|
4
14
|
export interface DecodeToPcmOptions {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Environment configuration for the `local` transcriber. Explicit options win,
|
|
3
|
+
* then the factory context, then `HAVE_SPEECH_TRANSCRIBER_*` variables (Node).
|
|
4
|
+
*/
|
|
5
|
+
import type { SpeechFactoryContext } from '../../shared/factory.js';
|
|
6
|
+
import type { LocalTranscriberOptions } from './types.js';
|
|
3
7
|
/** Local-only environment variables, in priority order. */
|
|
4
8
|
export declare const LOCAL_TRANSCRIBER_ENV_KEYS: {
|
|
5
9
|
readonly device: readonly ["HAVE_SPEECH_TRANSCRIBER_DEVICE"];
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Loads the optional `@huggingface/transformers` peer dependency and builds
|
|
3
|
+
* `automatic-speech-recognition` pipelines from it.
|
|
4
|
+
*
|
|
5
|
+
* This is the only module that names the peer. It is reachable only from the
|
|
6
|
+
* `@happyvertical/speech/local` entry, never from the core entry.
|
|
7
|
+
*/
|
|
8
|
+
import type { LocalTranscriberDevice, LocalTranscriberDtype, LocalTranscriberProgressCallback, LocalTransformersRuntime } from './types.js';
|
|
2
9
|
export declare const TRANSFORMERS_PACKAGE = "@huggingface/transformers";
|
|
3
10
|
export declare const TRANSFORMERS_INSTALL_HINT: string;
|
|
4
11
|
/** One ASR result as returned by transformers.js. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Transcriber, TranscriptionRequest, TranscriptResult } from '../../shared/types.js';
|
|
2
|
-
import { AsrOutput } from './runtime.js';
|
|
3
|
-
import { LocalTranscriberOptions } from './types.js';
|
|
1
|
+
import type { Transcriber, TranscriptionRequest, TranscriptResult } from '../../shared/types.js';
|
|
2
|
+
import { type AsrOutput } from './runtime.js';
|
|
3
|
+
import type { LocalTranscriberOptions } from './types.js';
|
|
4
4
|
/** Small multilingual Whisper (~80 MB at the default q8 quantisation). */
|
|
5
5
|
export declare const DEFAULT_LOCAL_MODEL = "onnx-community/whisper-base";
|
|
6
6
|
/**
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Public option types for the on-device (`local`) transcriber.
|
|
3
|
+
*
|
|
4
|
+
* Kept free of `@huggingface/transformers` types so the core entry can
|
|
5
|
+
* reference them without depending on the optional peer.
|
|
6
|
+
*/
|
|
7
|
+
import type { SpeechUsageCallback } from '../../shared/usage.js';
|
|
2
8
|
/**
|
|
3
9
|
* Inference device. `auto` picks WebGPU when the browser exposes a usable
|
|
4
10
|
* adapter (falling back to WASM if WebGPU fails to initialise) and `cpu` in
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Web Worker support for the `local` transcriber.
|
|
3
|
+
*
|
|
4
|
+
* Inference runs in a worker (`serveLocalTranscriber`) so long recordings never
|
|
5
|
+
* block the UI thread. The main-thread client (`LocalTranscriberWorkerClient`)
|
|
6
|
+
* transfers WAV and raw PCM bytes to the worker, which parses, downmixes, and
|
|
7
|
+
* resamples them there. Only formats that need `AudioContext` (which workers
|
|
8
|
+
* lack) or the client's `decodeAudio` hook are decoded on the main thread;
|
|
9
|
+
* their Float32 channels are then transferred and resampled in the worker.
|
|
10
|
+
*/
|
|
11
|
+
import type { TimestampGranularity, Transcriber, TranscriptionRequest, TranscriptResult } from '../../shared/types.js';
|
|
12
|
+
import { type SpeechUsageCallback } from '../../shared/usage.js';
|
|
13
|
+
import type { LocalAudioDecoder, LocalTranscriberOptions, LocalTranscriberProgress, LocalTranscriberProgressCallback } from './types.js';
|
|
4
14
|
/** Minimal `postMessage` endpoint: a `Worker`, `DedicatedWorkerGlobalScope`, or `MessagePort`. */
|
|
5
15
|
export interface LocalWorkerEndpoint {
|
|
6
16
|
postMessage(message: unknown, transfer?: Transferable[]): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
-
import { OpenAICompatibleTranscriberOptions, Transcriber, TranscriptionRequest, TranscriptResult } from '../shared/types.js';
|
|
2
|
+
import type { OpenAICompatibleTranscriberOptions, Transcriber, TranscriptionRequest, TranscriptResult } from '../shared/types.js';
|
|
3
3
|
export declare function isJsonOnlyTranscriptionModel(model: string): boolean;
|
|
4
4
|
/**
|
|
5
5
|
* OpenAI-compatible speech-to-text adapter (`POST <base>/audio/transcriptions`).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
-
import { OpenAICompatibleSpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
2
|
+
import type { OpenAICompatibleSpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
3
3
|
export declare class OpenAICompatibleSpeechSynthesizer extends HttpSpeechAdapter implements SpeechSynthesizer {
|
|
4
4
|
readonly type: "openai-compatible";
|
|
5
5
|
/** Explicit override, resolved relative to `baseUrl` (or absolute). */
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Realtime transcription adapter (`openai-realtime`).
|
|
3
|
+
*
|
|
4
|
+
* Targets the GA Realtime API transcription session (no `OpenAI-Beta`
|
|
5
|
+
* header): connect to `wss://api.openai.com/v1/realtime?intent=transcription`,
|
|
6
|
+
* send `session.update` with `session.type: "transcription"`, stream
|
|
7
|
+
* `input_audio_buffer.append`, and read
|
|
8
|
+
* `conversation.item.input_audio_transcription.delta` / `.completed`.
|
|
9
|
+
* Reference: https://developers.openai.com/api/docs/guides/realtime-transcription
|
|
10
|
+
* and https://developers.openai.com/api/reference/resources/realtime/client-events
|
|
11
|
+
*/
|
|
12
|
+
import { type RealtimeProtocol, type RealtimeProtocolEvent, type RealtimeSessionConfig } from '../shared/realtime-session.js';
|
|
13
|
+
import type { OpenAIRealtimeTranscriberOptions, StreamingAudioFormat, StreamingSession, StreamingSessionOptions, StreamingTranscriber, StreamingTurnLimit } from '../shared/streaming-types.js';
|
|
3
14
|
export declare const OPENAI_REALTIME_DEFAULT_URL = "wss://api.openai.com/v1/realtime";
|
|
4
15
|
export declare const OPENAI_REALTIME_DEFAULT_MODEL = "gpt-4o-transcribe";
|
|
5
16
|
/** The OpenAI Realtime transcription wire protocol. */
|
package/dist/adapters/qwen3.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
-
import { Qwen3SpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
2
|
+
import type { Qwen3SpeechSynthesizerOptions, SpeechSynthesizer, SynthesisRequest, SynthesizedSpeech } from '../shared/types.js';
|
|
3
3
|
export declare class Qwen3SpeechSynthesizer extends HttpSpeechAdapter implements SpeechSynthesizer {
|
|
4
4
|
readonly type: "qwen3-tts";
|
|
5
5
|
private readonly speechPath;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpSpeechAdapter } from '../shared/http.js';
|
|
2
|
-
import { SpeechSynthesizer, StudioServerSpeechSynthesizerOptions, StudioServerTranscriberOptions, SynthesisRequest, SynthesizedSpeech, Transcriber, TranscriptionRequest, TranscriptResult } from '../shared/types.js';
|
|
2
|
+
import type { SpeechSynthesizer, StudioServerSpeechSynthesizerOptions, StudioServerTranscriberOptions, SynthesisRequest, SynthesizedSpeech, Transcriber, TranscriptionRequest, TranscriptResult } from '../shared/types.js';
|
|
3
3
|
export declare class StudioServerTranscriber extends HttpSpeechAdapter implements Transcriber {
|
|
4
4
|
readonly type: "studio-server";
|
|
5
5
|
private readonly transcribePath;
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* vLLM realtime transcription adapter (`voxtral-realtime`), for Mistral's
|
|
3
|
+
* Voxtral Realtime models (e.g. `mistralai/Voxtral-Mini-4B-Realtime-2602`)
|
|
4
|
+
* served by vLLM at `/v1/realtime`.
|
|
5
|
+
*
|
|
6
|
+
* vLLM's protocol borrows OpenAI event names but is not OpenAI-compatible.
|
|
7
|
+
* Verified against vLLM's `entrypoints/speech_to_text/realtime` source and a
|
|
8
|
+
* live server:
|
|
9
|
+
*
|
|
10
|
+
* 1. The server sends `session.created` (`{ id, created }`) on connect.
|
|
11
|
+
* 2. The client sends `session.update` with a top-level `model` (no nested
|
|
12
|
+
* `session` object, no acknowledgement; an unknown model yields an
|
|
13
|
+
* `error` with code `model_not_found`).
|
|
14
|
+
* 3. A non-final `input_audio_buffer.commit` starts generation for a turn.
|
|
15
|
+
* 4. `input_audio_buffer.append` carries base64 PCM16 at 16 kHz mono. Audio
|
|
16
|
+
* appended before the start commit is kept.
|
|
17
|
+
* 5. The server streams `transcription.delta` (`{ delta }`, often empty) while
|
|
18
|
+
* audio arrives, at roughly real-time speed.
|
|
19
|
+
* 6. `input_audio_buffer.commit` with `final: true` ends the turn; the server
|
|
20
|
+
* replies `transcription.done` (`{ text, usage }`, token usage only) and
|
|
21
|
+
* clears its buffer. A further start commit opens the next turn on the same
|
|
22
|
+
* socket.
|
|
23
|
+
* 7. Errors arrive as `{ type: 'error', error: string, code }` and leave the
|
|
24
|
+
* socket open; this adapter treats every error as fatal.
|
|
25
|
+
* 8. A turn whose audio and tokens exceed `max_model_len` (~12.5 tokens per
|
|
26
|
+
* audio second plus a 39-token prompt) ends in `error` `processing_error`
|
|
27
|
+
* and can take the engine down. The limit is per turn: after a final
|
|
28
|
+
* commit vLLM clears the turn's context. The session therefore rolls over
|
|
29
|
+
* to a new turn before `maxTurnSeconds` (default 270) of audio.
|
|
30
|
+
* 9. A stray final commit leaves a stale end marker: the next turn ends at once
|
|
31
|
+
* with `prompt_tokens: 1` (any audio costs 39) and its audio is dropped.
|
|
32
|
+
* The session fails closed on that, and on any `done` for a turn it did
|
|
33
|
+
* not commit, rather than losing audio silently.
|
|
34
|
+
*/
|
|
35
|
+
import { type RealtimeProtocol, type RealtimeProtocolEvent } from '../shared/realtime-session.js';
|
|
36
|
+
import type { StreamingAudioFormat, StreamingSession, StreamingSessionOptions, StreamingTranscriber, StreamingTurnLimit, VoxtralRealtimeTranscriberOptions } from '../shared/streaming-types.js';
|
|
3
37
|
/** vLLM's default served model name for Voxtral Mini Realtime. */
|
|
4
38
|
export declare const VOXTRAL_REALTIME_DEFAULT_MODEL = "mistralai/Voxtral-Mini-4B-Realtime-2602";
|
|
5
39
|
/** The only input format vLLM's realtime endpoint accepts. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAIWebRTCVoiceOptions, VoiceSession } from './types.js';
|
|
1
|
+
import type { OpenAIWebRTCVoiceOptions, VoiceSession } from './types.js';
|
|
2
2
|
/** Browser WebRTC transport. No credentials, Node dependencies or globals are read at import. */
|
|
3
3
|
export declare function createOpenAIWebRTCVoiceSession(options: OpenAIWebRTCVoiceOptions): VoiceSession;
|
|
4
4
|
//# sourceMappingURL=openai-webrtc.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Server-only OpenAI conversational call lifecycle. Hosts own authorization and admission policy. */
|
|
1
2
|
import { SpeechProviderError } from './shared/errors.js';
|
|
2
|
-
import { StreamingTurnDetection } from './shared/streaming-types.js';
|
|
3
|
-
import { SpeechFetch } from './shared/types.js';
|
|
3
|
+
import type { StreamingTurnDetection } from './shared/streaming-types.js';
|
|
4
|
+
import type { SpeechFetch } from './shared/types.js';
|
|
4
5
|
export interface OpenAIVoiceCallOptions {
|
|
5
6
|
apiKey: string;
|
|
6
7
|
/** Fixed by the host, never copied from untrusted browser JSON. */
|
package/dist/local.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @happyvertical/speech/local
|
|
3
|
+
*
|
|
4
|
+
* On-device speech-to-text with transformers.js (`@huggingface/transformers`,
|
|
5
|
+
* an optional peer dependency loaded on first use). Importing this entry
|
|
6
|
+
* registers `type: 'local'` with `getTranscriber()` and `getSpeech()`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { getTranscriber } from '@happyvertical/speech';
|
|
11
|
+
* import '@happyvertical/speech/local';
|
|
12
|
+
*
|
|
13
|
+
* const transcriber = await getTranscriber({ type: 'local' });
|
|
14
|
+
* const { text } = await transcriber.transcribe({ audio: wavBytes, mimeType: 'audio/wav' });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
1
19
|
import { LocalTranscriber } from './adapters/local/transcriber.js';
|
|
2
|
-
import { LocalTranscriberOptions } from './adapters/local/types.js';
|
|
3
|
-
import { SpeechFactoryContext } from './shared/factory.js';
|
|
20
|
+
import type { LocalTranscriberOptions } from './adapters/local/types.js';
|
|
21
|
+
import type { SpeechFactoryContext } from './shared/factory.js';
|
|
4
22
|
export { decodeToPcm16k, LOCAL_SAMPLE_RATE, } from './adapters/local/audio.js';
|
|
5
23
|
export { LOCAL_TRANSCRIBER_ENV_KEYS } from './adapters/local/env.js';
|
|
6
24
|
export { TRANSFORMERS_INSTALL_HINT, TRANSFORMERS_PACKAGE, } from './adapters/local/runtime.js';
|
package/dist/shared/audio.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Audio input normalisation shared by speech adapters: accepts the input
|
|
3
|
+
* shapes callers actually have (Blob, Buffer, Uint8Array, ArrayBuffer,
|
|
4
|
+
* ReadableStream), enforces byte limits while buffering, and derives a
|
|
5
|
+
* multipart filename whose extension matches the MIME type.
|
|
6
|
+
*/
|
|
7
|
+
import type { AudioInput, AudioSource } from './types.js';
|
|
2
8
|
/** OpenAI caps `/audio/transcriptions` uploads at 25 MB. */
|
|
3
9
|
export declare const DEFAULT_MAX_AUDIO_BYTES: number;
|
|
4
10
|
/**
|
package/dist/shared/env.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Environment configuration for speech adapters.
|
|
3
|
+
*
|
|
4
|
+
* Transcriber settings resolve in this order (first wins):
|
|
5
|
+
* explicit options → factory context → `HAVE_SPEECH_TRANSCRIBER_*` →
|
|
6
|
+
* legacy `HAVE_SPEECH_STT_*` → gateway `STT_*` aliases.
|
|
7
|
+
*/
|
|
8
|
+
import type { SpeechFetch } from './types.js';
|
|
2
9
|
export interface SpeechEnv {
|
|
3
10
|
[key: string]: string | undefined;
|
|
4
11
|
}
|
package/dist/shared/factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SpeechEnv } from './env.js';
|
|
2
|
-
import { GetSpeechOptions, GetSpeechSynthesizerOptions, GetTranscriberOptions, Speech, SpeechAdapterAvailability, SpeechFetch, SpeechSynthesizer, Transcriber } from './types.js';
|
|
1
|
+
import { type SpeechEnv } from './env.js';
|
|
2
|
+
import type { GetSpeechOptions, GetSpeechSynthesizerOptions, GetTranscriberOptions, Speech, SpeechAdapterAvailability, SpeechFetch, SpeechSynthesizer, Transcriber } from './types.js';
|
|
3
3
|
export interface SpeechFactoryContext {
|
|
4
4
|
env?: SpeechEnv;
|
|
5
5
|
fetch?: SpeechFetch;
|
package/dist/shared/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SpeechRetryOptions } from './retry.js';
|
|
2
|
-
import { HttpSpeechOptions, SpeechFetch, SynthesisRequest, SynthesizedSpeech, TranscriptResult, TranscriptSegment, WordTiming } from './types.js';
|
|
1
|
+
import { type SpeechRetryOptions } from './retry.js';
|
|
2
|
+
import type { HttpSpeechOptions, SpeechFetch, SynthesisRequest, SynthesizedSpeech, TranscriptResult, TranscriptSegment, WordTiming } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Returns `baseUrl` with a trailing `/` on its path so relative paths resolve
|
|
5
5
|
* beneath it. The query string is preserved and any fragment is dropped.
|
package/dist/shared/pcm.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Raw-audio helpers for streaming adapters: byte views, base64 encoding,
|
|
3
|
+
* duration from byte counts, and WAV/`audio/L16` unwrapping for the
|
|
4
|
+
* record-then-send wrapper. Nothing here decodes compressed audio or resamples.
|
|
5
|
+
*/
|
|
6
|
+
import type { StreamingAudioChunk, StreamingAudioFormat } from './streaming-types.js';
|
|
2
7
|
/** Returns a byte view over a chunk without copying. */
|
|
3
8
|
export declare function chunkToBytes(chunk: StreamingAudioChunk, adapter?: string): Uint8Array;
|
|
4
9
|
export declare function encodeBase64(bytes: Uint8Array): string;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Credential handling shared by realtime (WebSocket) adapters.
|
|
3
|
+
*
|
|
4
|
+
* Node callers authenticate with a long-lived `apiKey` in the
|
|
5
|
+
* `Authorization` header. Browsers cannot set WebSocket headers and must never
|
|
6
|
+
* hold a long-lived key, so they pass a short-lived `clientSecret`, which is
|
|
7
|
+
* sent as a WebSocket subprotocol.
|
|
8
|
+
*/
|
|
9
|
+
import type { RealtimeConnection } from './realtime-session.js';
|
|
10
|
+
import type { StreamingClientSecret } from './streaming-types.js';
|
|
3
11
|
/** Subprotocol prefix that carries a client secret (OpenAI's convention). */
|
|
4
12
|
export declare const CLIENT_SECRET_SUBPROTOCOL_PREFIX = "openai-insecure-api-key.";
|
|
5
13
|
/** Throws when an adapter is given a long-lived `apiKey` in a browser. */
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Protocol-agnostic realtime transcription session over a WebSocket.
|
|
3
|
+
*
|
|
4
|
+
* The session owns the socket lifecycle, write queue and backpressure,
|
|
5
|
+
* timeouts, turn bookkeeping, events, and the final `TranscriptResult`. A
|
|
6
|
+
* {@link RealtimeProtocol} supplies the wire format, so a sibling adapter
|
|
7
|
+
* (for example a vLLM-served Voxtral realtime endpoint) only has to map its
|
|
8
|
+
* own messages.
|
|
9
|
+
*/
|
|
10
|
+
import type { StreamingAudioChunk, StreamingAudioFormat, StreamingSession, StreamingSessionEventName, StreamingSessionListener, StreamingSessionState, StreamingTurnDetection } from './streaming-types.js';
|
|
11
|
+
import { type TurnLimit } from './turn-limit.js';
|
|
12
|
+
import type { TranscriptResult } from './types.js';
|
|
13
|
+
import { type SpeechUsageCallback } from './usage.js';
|
|
14
|
+
import { type SpeechWebSocketFactory } from './websocket.js';
|
|
6
15
|
export declare const DEFAULT_STREAMING_TIMEOUT_MS = 30000;
|
|
7
16
|
export declare const DEFAULT_STREAMING_CONNECT_TIMEOUT_MS = 10000;
|
|
8
17
|
export declare const DEFAULT_STREAMING_HIGH_WATER_MARK: number;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Registry for opt-in transcriber adapters that live behind subpath exports
|
|
3
|
+
* (e.g. `@happyvertical/speech/local`).
|
|
4
|
+
*
|
|
5
|
+
* The core entry never imports those adapters, so their heavy optional peer
|
|
6
|
+
* dependencies are never resolved by bundlers or loaded at runtime unless the
|
|
7
|
+
* caller imports the subpath, which registers its factory here.
|
|
8
|
+
*/
|
|
9
|
+
import type { SpeechFactoryContext } from './factory.js';
|
|
10
|
+
import type { GetTranscriberOptions, Transcriber, TranscriberType } from './types.js';
|
|
3
11
|
export type OptionalTranscriberFactory = (options: GetTranscriberOptions, context: SpeechFactoryContext) => Transcriber | Promise<Transcriber>;
|
|
4
12
|
export declare function registerOptionalTranscriber(type: TranscriberType, factory: OptionalTranscriberFactory): void;
|
|
5
13
|
export declare function getOptionalTranscriberFactory(type: string): OptionalTranscriberFactory | undefined;
|
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Server-side minting of short-lived browser credentials for realtime
|
|
3
|
+
* transcription.
|
|
4
|
+
*
|
|
5
|
+
* A browser must never hold the long-lived provider key. Your server calls
|
|
6
|
+
* {@link createStreamingClientSecret} once per tenant session (after its own
|
|
7
|
+
* auth check), records the returned tenant/session attribution, and hands the
|
|
8
|
+
* browser only `value` and `expiresAt`. The browser passes `value` as the
|
|
9
|
+
* streaming adapter's `clientSecret`.
|
|
10
|
+
*
|
|
11
|
+
* - `openai-realtime`: `POST /v1/realtime/client_secrets` with
|
|
12
|
+
* `expires_after: { anchor: 'created_at', seconds }` and a
|
|
13
|
+
* `session.type: "transcription"` config, returning an `ek_…` secret
|
|
14
|
+
* (https://developers.openai.com/api/reference/resources/realtime/subresources/client_secrets/methods/create).
|
|
15
|
+
* - `voxtral-realtime`: vLLM has no ephemeral-token mechanism, so this throws
|
|
16
|
+
* `SpeechConfigurationError`. Browser Voxtral needs your own proxy or token
|
|
17
|
+
* gateway in front of vLLM.
|
|
18
|
+
*/
|
|
19
|
+
import { type SpeechEnv } from './env.js';
|
|
20
|
+
import type { OpenAIRealtimeTranscriberOptions, StreamingAudioFormat, StreamingTranscriberType, StreamingTurnDetection } from './streaming-types.js';
|
|
21
|
+
import type { SpeechFetch } from './types.js';
|
|
4
22
|
/** Default client-secret lifetime: long enough to connect, short if leaked. */
|
|
5
23
|
export declare const DEFAULT_CLIENT_SECRET_TTL_SECONDS = 60;
|
|
6
24
|
/** OpenAI's accepted `expires_after.seconds` range. */
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Streaming transcriber factory, environment configuration, and the
|
|
3
|
+
* record-then-send `Transcriber` wrapper.
|
|
4
|
+
*/
|
|
5
|
+
import { type SpeechEnv } from './env.js';
|
|
6
|
+
import type { GetStreamingTranscriberOptions, StreamingTranscriber, StreamingTranscriberType, StreamingTurnDetection } from './streaming-types.js';
|
|
7
|
+
import type { Transcriber } from './types.js';
|
|
4
8
|
/** Streaming adapters `getStreamingTranscriber()` can build. */
|
|
5
9
|
export declare const STREAMING_TRANSCRIBER_TYPES: readonly StreamingTranscriberType[];
|
|
6
10
|
/** Environment variable names read for each streaming setting, in priority order. */
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Streaming (realtime) speech-to-text contract.
|
|
3
|
+
*
|
|
4
|
+
* A {@link StreamingTranscriber} opens one {@link StreamingSession} per
|
|
5
|
+
* utterance or conversation. Callers push raw audio with `write()`, listen for
|
|
6
|
+
* `partial` and `final` events, and call `end()` for the whole transcript.
|
|
7
|
+
*/
|
|
8
|
+
import type { TranscriptResult } from './types.js';
|
|
9
|
+
import type { SpeechUsageCallback } from './usage.js';
|
|
10
|
+
import type { SpeechWebSocketConstructor, SpeechWebSocketFactory } from './websocket.js';
|
|
4
11
|
/** Streaming adapter identifiers. */
|
|
5
12
|
export type StreamingTranscriberType = 'openai-realtime' | 'voxtral-realtime';
|
|
6
13
|
/**
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Per-turn audio limits for realtime sessions.
|
|
3
|
+
*
|
|
4
|
+
* Some providers cap the audio of one turn rather than of a session: vLLM's
|
|
5
|
+
* realtime endpoint keeps a turn's audio and generated tokens in one model
|
|
6
|
+
* context (`max_model_len`) and clears it after each final commit. A
|
|
7
|
+
* {@link TurnSplitter} measures the audio of the current turn from byte counts
|
|
8
|
+
* and the negotiated format, and picks where to roll over to a new turn: at
|
|
9
|
+
* the first quiet stretch inside a window before the limit, or at the limit
|
|
10
|
+
* itself when no quiet stretch turns up. The silence check is a plain RMS
|
|
11
|
+
* energy test, not a voice-activity model.
|
|
12
|
+
*/
|
|
13
|
+
import type { StreamingAudioFormat, StreamingSessionSettings, StreamingTurnLimit } from './streaming-types.js';
|
|
2
14
|
/** Default per-turn audio cap for providers that need one (`voxtral-realtime`). */
|
|
3
15
|
export declare const DEFAULT_MAX_TURN_SECONDS = 270;
|
|
4
16
|
/** How long before the cap the rollover starts looking for silence. */
|
package/dist/shared/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { LocalTranscriberSettings } from '../adapters/local/types.js';
|
|
2
|
-
import { SpeechRetryOptions } from './retry.js';
|
|
3
|
-
import { GetStreamingTranscriberOptions, StreamingTranscriberType } from './streaming-types.js';
|
|
4
|
-
import { SpeechUsage, SpeechUsageCallback } from './usage.js';
|
|
1
|
+
import type { LocalTranscriberSettings } from '../adapters/local/types.js';
|
|
2
|
+
import type { SpeechRetryOptions } from './retry.js';
|
|
3
|
+
import type { GetStreamingTranscriberOptions, StreamingTranscriberType } from './streaming-types.js';
|
|
4
|
+
import type { SpeechUsage, SpeechUsageCallback } from './usage.js';
|
|
5
5
|
export type { SpeechRetryOptions } from './retry.js';
|
|
6
6
|
export type { SpeechOperation, SpeechUsage, SpeechUsageCallback, } from './usage.js';
|
|
7
7
|
export type SpeechAdapterType = 'studio-server' | 'qwen3-tts' | 'openai-compatible' | 'local' | StreamingTranscriberType;
|