1import type * as speech from "@distilled.cloud/gcp/speech_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { PhraseSet } from "./PhraseSet.ts";
6
7export interface RecognizeRequest {
8 /**
9 * Recognize body. The bound PhraseSet is added to
10 * `config.adaptation.phraseSetReferences`.
11 */
12 body?: speech.RecognizeRequest;
13}
14
15/**
16 * Runtime binding for Speech-to-Text `speech.recognize` using a PhraseSet
17 * as Adaptation.
18 *
19 * Bind this operation to a {@link PhraseSet} in a Function/Action init
20 * phase. Provide {@link RecognizeHttp}.
21 *
22 * Grants `roles/speech.client` on the project because Speech-to-Text has no
23 * resource-level IAM.
24 *
25 * ### Recognizing Speech
26 * **Example:** Transcribe audio with phrase hints
27 * ```typescript
28 * const recognize = yield* GCP.Speech.Recognize(hints);
29 * const result = yield* recognize({
30 * body: {
31 * config: { languageCode: "en-US" },
32 * audio: { uri: "gs://bucket/clip.flac" },
33 * },
34 * });
35 * ```
36 *
37 * @binding
38 * @category Speech
39 */
40export interface Recognize extends Binding.Service<
41 Recognize,
42 "GCP.Speech.Recognize",
43 (
44 phraseSet: PhraseSet,
45 ) => Effect.Effect<
46 (
47 request?: RecognizeRequest,
48 ) => Effect.Effect<
49 speech.RecognizeResponse,
50 speech.RecognizeSpeechError,
51 RuntimeContext
52 >
53 >
54> {}
55
56export const Recognize = Binding.Service<Recognize>("GCP.Speech.Recognize");