GCP.Speech reference
CustomClass
Section titled “CustomClass”Source:
src/GCP/Speech/CustomClass.ts
A Speech-to-Text Adaptation custom class. Custom classes group words
that represent one concept (for example passenger ship names) and are
referenced from PhraseSet hints as ${custom_class_id}.
Speech-to-Text v1 classes have no labels field and Alchemy does not
write ownership into the items (they steer recognition). A generated id
identifies the class; one with an explicit id that Alchemy has no state
for is reported as unowned. Location and custom class id are identity — changing either replaces the class.
items update in place.
CustomClass: Creating a Custom Class
Section titled “CustomClass: Creating a Custom Class”Generated id
const ships = yield* GCP.Speech.CustomClass("Ships", { items: [{ value: "sloop" }, { value: "ketch" }],});Explicit id and location
const ships = yield* GCP.Speech.CustomClass("Ships", { location: "global", customClassId: "passenger-ships", items: [{ value: "sloop" }],});CustomClass: Updating a Custom Class
Section titled “CustomClass: Updating a Custom Class”const ships = yield* GCP.Speech.CustomClass("Ships", { items: [{ value: "brig" }, { value: "barque" }],});GetCustomClass
Section titled “GetCustomClass”Source:
src/GCP/Speech/GetCustomClass.ts
Runtime binding for Speech-to-Text customClasses.get.
Bind this operation to a CustomClass in a Function/Action
init phase. Provide GetCustomClassHttp.
Grants roles/speech.client on the project because Speech-to-Text has no
resource-level IAM.
GetCustomClass: Reading a Custom Class
Section titled “GetCustomClass: Reading a Custom Class”const getClass = yield* GCP.Speech.GetCustomClass(ships);const live = yield* getClass();GetCustomClassHttp
Section titled “GetCustomClassHttp”Source:
src/GCP/Speech/GetCustomClassHttp.tsKind: Layer · Provides:GCP.Speech.GetCustomClass
HTTP implementation of GetCustomClass.
GetPhraseSet
Section titled “GetPhraseSet”Source:
src/GCP/Speech/GetPhraseSet.ts
Runtime binding for Speech-to-Text phraseSets.get.
Bind this operation to a PhraseSet in a Function/Action init
phase. Provide GetPhraseSetHttp.
Grants roles/speech.client on the project because Speech-to-Text has no
resource-level IAM.
GetPhraseSet: Reading a Phrase Set
Section titled “GetPhraseSet: Reading a Phrase Set”const getPhraseSet = yield* GCP.Speech.GetPhraseSet(hints);const live = yield* getPhraseSet();GetPhraseSetHttp
Section titled “GetPhraseSetHttp”Source:
src/GCP/Speech/GetPhraseSetHttp.tsKind: Layer · Provides:GCP.Speech.GetPhraseSet
HTTP implementation of GetPhraseSet.
PhraseSet
Section titled “PhraseSet”Source:
src/GCP/Speech/PhraseSet.ts
A Speech-to-Text Adaptation phrase set. Phrase sets bias recognition
toward listed words and phrases, including references to custom
classes (${custom_class_id}).
Speech-to-Text v1 phrase sets have no labels field and Alchemy does
not write ownership into the phrases (they bias recognition). A
generated id identifies the set; one with an explicit id that Alchemy
has no state for is reported as unowned. Location and
phrase set id are identity — changing either replaces the set.
phrases and boost update in place.
PhraseSet: Creating a Phrase Set
Section titled “PhraseSet: Creating a Phrase Set”Generated id
const hints = yield* GCP.Speech.PhraseSet("Hints", { phrases: [{ value: "weather", boost: 10 }], boost: 5,});Explicit id with a custom class reference
const hints = yield* GCP.Speech.PhraseSet("Hints", { phraseSetId: "weather-hints", phrases: [{ value: "sail on ${passenger-ships}" }],});PhraseSet: Updating a Phrase Set
Section titled “PhraseSet: Updating a Phrase Set”const hints = yield* GCP.Speech.PhraseSet("Hints", { phrases: [ { value: "weather", boost: 15 }, { value: "forecast" }, ], boost: 8,});Recognize
Section titled “Recognize”Source:
src/GCP/Speech/Recognize.ts
Runtime binding for Speech-to-Text speech.recognize using a PhraseSet
as Adaptation.
Bind this operation to a PhraseSet in a Function/Action init
phase. Provide RecognizeHttp.
Grants roles/speech.client on the project because Speech-to-Text has no
resource-level IAM.
Recognize: Recognizing Speech
Section titled “Recognize: Recognizing Speech”const recognize = yield* GCP.Speech.Recognize(hints);const result = yield* recognize({ body: { config: { languageCode: "en-US" }, audio: { uri: "gs://bucket/clip.flac" }, },});RecognizeHttp
Section titled “RecognizeHttp”Source:
src/GCP/Speech/RecognizeHttp.tsKind: Layer · Provides:GCP.Speech.Recognize
HTTP implementation of Recognize.