(projectId, location, gcsUri, customClassId, phraseSetId)
| 13 | 'use strict'; |
| 14 | |
| 15 | function main(projectId, location, gcsUri, customClassId, phraseSetId) { |
| 16 | // [START speech_transcribe_with_model_adaptation] |
| 17 | // Imports the Google Cloud client library |
| 18 | const speech = require('@google-cloud/speech').v1p1beta1; |
| 19 | |
| 20 | // Create the speech client |
| 21 | const client = new speech.SpeechClient(); |
| 22 | |
| 23 | // Create the adaptation client |
| 24 | const adaptationClient = new speech.AdaptationClient(); |
| 25 | |
| 26 | async function modelAdaptation() { |
| 27 | // Create`PhraseSet` and `CustomClasses` to create custom lists of similar |
| 28 | // items that are likely to occur in your input data. |
| 29 | |
| 30 | // The parent resource where the custom class and phrase set will be created. |
| 31 | const parent = `projects/${projectId}/locations/${location}`; |
| 32 | |
| 33 | // Create the custom class |
| 34 | const customClassResponse = await adaptationClient.createCustomClass({ |
| 35 | parent: parent, |
| 36 | customClassId: customClassId, |
| 37 | customClass: { |
| 38 | items: [{value: 'sushido'}, {value: 'altura'}, {value: 'taneda'}], |
| 39 | }, |
| 40 | }); |
| 41 | |
| 42 | // Create the phrase set |
| 43 | const phraseSetResponse = await adaptationClient.createPhraseSet({ |
| 44 | parent: parent, |
| 45 | phraseSetId: phraseSetId, |
| 46 | phraseSet: { |
| 47 | boost: 10, |
| 48 | phrases: [{value: `Visit restaurants like ${customClassId}`}], |
| 49 | }, |
| 50 | }); |
| 51 | |
| 52 | // The next section shows how to use the newly created custom |
| 53 | // class and phrase set to send a transcription request with speech adaptation |
| 54 | |
| 55 | const speechAdaptation = { |
| 56 | phraseSets: [phraseSetResponse[0]], |
| 57 | phraseSetReferences: [], |
| 58 | customClasses: [customClassResponse[0]], |
| 59 | }; |
| 60 | |
| 61 | const audio = { |
| 62 | uri: gcsUri, |
| 63 | }; |
| 64 | |
| 65 | const config = { |
| 66 | encoding: 'FLAC', |
| 67 | sampleRateHertz: 16000, |
| 68 | languageCode: 'en-US', |
| 69 | adaptation: speechAdaptation, |
| 70 | }; |
| 71 | |
| 72 | const request = { |
no test coverage detected