| 1 | import * as speech from "@distilled.cloud/gcp/speech_v1"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makePhraseSetHttpBinding } from "./BindingHttp.ts"; |
| 4 | import { Recognize, type RecognizeRequest } from "./Recognize.ts"; |
| 5 | |
| 6 | /** |
| 7 | * HTTP implementation of {@link Recognize}. |
| 8 | * |
| 9 | * @layer |
| 10 | * @provides GCP.Speech.Recognize |
| 11 | */ |
| 12 | export const RecognizeHttp = Layer.effect( |
| 13 | Recognize, |
| 14 | makePhraseSetHttpBinding< |
| 15 | speech.RecognizeSpeechRequest, |
| 16 | speech.RecognizeResponse, |
| 17 | speech.RecognizeSpeechError, |
| 18 | RecognizeRequest |
| 19 | >({ |
| 20 | tag: "GCP.Speech.Recognize", |
| 21 | operation: speech.recognizeSpeech, |
| 22 | iam: { role: "roles/speech.client" }, |
| 23 | toInput: (name, request) => { |
| 24 | const body = request?.body ?? {}; |
| 25 | const config = body.config ?? {}; |
| 26 | const adaptation = config.adaptation ?? {}; |
| 27 | const references = [ |
| 28 | ...(adaptation.phraseSetReferences ?? []), |
| 29 | name, |
| 30 | ].filter((value, index, all) => all.indexOf(value) === index); |
| 31 | return { |
| 32 | body: { |
| 33 | ...body, |
| 34 | config: { |
| 35 | ...config, |
| 36 | adaptation: { |
| 37 | ...adaptation, |
| 38 | phraseSetReferences: references, |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | }; |
| 43 | }, |
| 44 | }), |
| 45 | ); |