(recognizerName)
| 19 | // description: Build inline custom class for adaptation in Speech-to-Text v2 |
| 20 | |
| 21 | async 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 | |
| 73 | exports.buildInlineCustomClassV2 = main; |
nothing calls this directly
no test coverage detected