agents
Version:
A home for your AI agents
137 lines (135 loc) • 4.24 kB
TypeScript
import {
a as TranscriberSessionOptions,
i as TranscriberSession,
n as TTSProvider,
r as Transcriber
} from "../types-_Faxb570.js";
//#region src/voice/workers-ai.d.ts
/** Loose type for the Workers AI binding — avoids hard dependency on @cloudflare/workers-types. */
interface AiLike {
run(
model: string,
input: Record<string, unknown>,
options?: Record<string, unknown>
): Promise<unknown>;
}
interface WorkersAITTSOptions {
/** TTS model name. @default "@cf/deepgram/aura-1" */
model?: string;
/** TTS speaker voice. @default "asteria" */
speaker?: string;
}
/**
* Workers AI text-to-speech provider.
*
* @example
* ```ts
* class MyAgent extends VoiceAgent<Env> {
* tts = new WorkersAITTS(this.env.AI);
* }
* ```
*/
declare class WorkersAITTS implements TTSProvider {
#private;
constructor(ai: AiLike, options?: WorkersAITTSOptions);
synthesize(text: string, signal?: AbortSignal): Promise<ArrayBuffer | null>;
}
interface WorkersAIFluxSTTOptions {
/** End-of-turn confidence threshold (0.5-0.9). @default 0.7 */
eotThreshold?: number;
/**
* Eager end-of-turn threshold (0.3-0.9). When set, enables
* EagerEndOfTurn and TurnResumed events for speculative processing.
*/
eagerEotThreshold?: number;
/** EOT timeout in milliseconds. @default 5000 */
eotTimeoutMs?: number;
/** Keyterms to boost recognition of specialized terminology. */
keyterms?: string[];
/** Sample rate in Hz. @default 16000 */
sampleRate?: number;
}
/**
* Workers AI continuous speech-to-text provider using the Flux model.
*
* Flux is a conversational STT model with built-in end-of-turn detection.
* A single session is created per call and receives all audio continuously.
* The model detects speech boundaries and fires `onUtterance` when a
* turn is complete — no client-side silence detection needed for STT.
*
* Recommended for `withVoice` (conversational voice agents).
*
* @example
* ```ts
* import { Agent } from "agents";
* import { withVoice, WorkersAIFluxSTT, WorkersAITTS } from "agents/voice";
*
* const VoiceAgent = withVoice(Agent);
*
* class MyAgent extends VoiceAgent<Env> {
* transcriber = new WorkersAIFluxSTT(this.env.AI);
* tts = new WorkersAITTS(this.env.AI);
*
* async onTurn(transcript, context) { ... }
* }
* ```
*/
declare class WorkersAIFluxSTT implements Transcriber {
#private;
constructor(ai: AiLike, options?: WorkersAIFluxSTTOptions);
createSession(options?: TranscriberSessionOptions): TranscriberSession;
}
interface WorkersAINova3STTOptions {
/** Language code. @default "en" */
language?: string;
/** Endpointing silence duration in ms. @default 300 */
endpointingMs?: number;
/** Utterance end detection timeout in ms. @default 1000 */
utteranceEndMs?: number;
/** Enable smart formatting (numbers, dates, etc.). @default true */
smartFormat?: boolean;
/** Enable punctuation. @default true */
punctuate?: boolean;
/** Keyterms to boost recognition of specialized terminology. */
keyterms?: string[];
/** Sample rate in Hz. @default 16000 */
sampleRate?: number;
}
/**
* Workers AI continuous speech-to-text provider using Nova 3.
*
* Nova 3 is a high-accuracy STT model with streaming WebSocket support.
* A single session is created per call and receives all audio continuously.
* Server-side VAD events and endpointing handle speech boundary detection.
*
* Recommended for `withVoiceInput` (dictation / voice input UIs).
*
* @example
* ```ts
* import { Agent } from "agents";
* import { withVoiceInput, WorkersAINova3STT } from "agents/voice";
*
* const InputAgent = withVoiceInput(Agent);
*
* class MyAgent extends InputAgent<Env> {
* transcriber = new WorkersAINova3STT(this.env.AI);
*
* onTranscript(text, connection) { ... }
* }
* ```
*/
declare class WorkersAINova3STT implements Transcriber {
#private;
constructor(ai: AiLike, options?: WorkersAINova3STTOptions);
createSession(options?: TranscriberSessionOptions): TranscriberSession;
}
//#endregion
export {
WorkersAIFluxSTT,
WorkersAIFluxSTTOptions,
WorkersAINova3STT,
WorkersAINova3STTOptions,
WorkersAITTS,
WorkersAITTSOptions
};
//# sourceMappingURL=workers-ai.d.ts.map