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

Function main

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

Source from the content-addressed store, hash-verified

19// description: Build inline phrase set for adaptation in Speech-to-Text v2
20
21async function main(recognizerName) {
22 // [START speech_adaptation_v2_inline_phrase_set]
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 buildInlinePhraseSetV2() {
36 // Instantiate the Speech client
37 const client = new speech.SpeechClient();
38
39 // Create an inline phrase set to produce a more accurate transcript.
40 const phraseSet = {
41 phrases: [{value: 'Brooklyn', boost: 10}],
42 };
43 const adaptation = {
44 phraseSets: [{inlinePhraseSet: phraseSet}],
45 };
46
47 const config = {
48 autoDecodingConfig: {},
49 adaptation,
50 };
51
52 const content = fs.readFileSync(audioFilePath).toString('base64');
53
54 const transcriptionRequest = {
55 recognizer: recognizerName,
56 config,
57 content,
58 };
59 const response = await client.recognize(transcriptionRequest);
60 for (const result of response[0].results) {
61 console.log(`Transcript: ${result.alternatives[0].transcript}`);
62 }
63 }
64
65 await buildInlinePhraseSetV2();
66 // [END speech_adaptation_v2_inline_phrase_set]
67}
68
69exports.buildInlinePhraseSetV2 = main;

Callers

nothing calls this directly

Calls 1

buildInlinePhraseSetV2Function · 0.85

Tested by

no test coverage detected