MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

speech/adaptationInlineCustomClass.v2.js:21–71  ·  view source on GitHub ↗
(recognizerName)

Source from the content-addressed store, hash-verified

19// description: Build inline custom class for adaptation in Speech-to-Text v2
20
21async function main(recognizerName) {
22 // [START speech_adaptation_v2_inline_custom_class]
23 /**
24 * TODO(developer): Uncomment this variable before running the sample.
25 */
26 // const recognizerName = "projects/[PROJECT_ID]/locations/[LOCATION]/recognizers/[RECOGNIZER_ID]";
27
28 // TODO(developer): Replace with your own file
29 const audioFilePath = 'resources/brooklyn.flac';
30
31 // Imports the Google Cloud Speech-to-Text library (v2)
32 const speech = require('@google-cloud/speech').v2;
33 const fs = require('fs');
34
35 async function buildInlineCustomClass() {
36 const client = new speech.SpeechClient();
37
38 // Create an inline phrase set to produce a more accurate transcript.
39 const phraseSet = {
40 phrases: [{value: '${brooklyn}', boost: 20}],
41 };
42 const customClass = {
43 name: 'brooklyn',
44 items: [{value: 'Brooklyn'}],
45 };
46 const adaptation = {
47 phraseSets: [{inlinePhraseSet: phraseSet}],
48 customClasses: [customClass],
49 };
50
51 const config = {
52 autoDecodingConfig: {},
53 adaptation,
54 };
55
56 const content = fs.readFileSync(audioFilePath).toString('base64');
57
58 const transcriptionRequest = {
59 recognizer: recognizerName,
60 config,
61 content,
62 };
63 const response = await client.recognize(transcriptionRequest);
64 for (const result of response[0].results) {
65 console.log(`Transcript: ${result.alternatives[0].transcript}`);
66 }
67 }
68
69 await buildInlineCustomClass();
70 // [END speech_adaptation_v2_inline_custom_class]
71}
72
73exports.buildInlineCustomClassV2 = main;

Callers

nothing calls this directly

Calls 1

buildInlineCustomClassFunction · 0.85

Tested by

no test coverage detected