1import type * as polly from "@distilled.cloud/aws/polly";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4
5/**
6 * Runtime binding for `polly:StartSpeechSynthesisStream` — bidirectional
7 * streaming synthesis: send text incrementally as `TextEvent`s on the input
8 * `ActionStream` and receive `AudioEvent` chunks on the output `EventStream`
9 * as they become available.
10 *
11 * The binding takes no arguments and grants the function
12 * `polly:StartSpeechSynthesisStream`. Provide the implementation with
13 * `Effect.provide(AWS.Polly.StartSpeechSynthesisStreamHttp)`.
14 *
15 * NOTE: the distilled HTTP transport does not yet support bidirectional
16 * (input) event-stream request bodies — a live call currently hangs waiting
17 * for response headers (probed 2026-07; same transport gap leaves
18 * transcribe-streaming and lex StartConversation unbound). Prefer
19 * `SynthesizeSpeech` (request-response) until distilled core ships
20 * event-stream request support.
21 *
22 * ### Streaming Synthesis
23 * **Example:** Stream text in, collect audio out
24 * ```typescript
25 * // init
26 * const startSpeechSynthesisStream =
27 * yield* AWS.Polly.StartSpeechSynthesisStream();
28 *
29 * // runtime
30 * const result = yield* startSpeechSynthesisStream({
31 * Engine: "generative",
32 * OutputFormat: "mp3",
33 * VoiceId: "Matthew",
34 * ActionStream: Stream.make(
35 * { TextEvent: { Text: "Hello from Alchemy." } },
36 * { CloseStreamEvent: {} },
37 * ),
38 * });
39 * const events = yield* Stream.runCollect(result.EventStream!);
40 * const audioBytes = Array.from(events)
41 * .flatMap((event) => (event.AudioEvent?.AudioChunk ? [event.AudioEvent.AudioChunk] : []))
42 * .reduce((total, chunk) => total + chunk.length, 0);
43 * ```
44 *
45 * @binding
46 */
47export interface StartSpeechSynthesisStream extends Binding.Service<
48 StartSpeechSynthesisStream,
49 "AWS.Polly.StartSpeechSynthesisStream",
50 () => Effect.Effect<
51 (
52 request: polly.StartSpeechSynthesisStreamInput,
53 ) => Effect.Effect<
54 polly.StartSpeechSynthesisStreamOutput,
55 polly.StartSpeechSynthesisStreamError
56 >
57 >
58> {}
59export const StartSpeechSynthesisStream =
60 Binding.Service<StartSpeechSynthesisStream>(
61 "AWS.Polly.StartSpeechSynthesisStream",
62 );