Skip to content

Commit 25b9a21

Browse files
b-loved-dreamerAce Nassri
authored andcommitted
docs(samples): adds model adaptation sample (#712)
1 parent 2d94f1f commit 25b9a21

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/* eslint-disable */
16+
17+
'use strict';
18+
19+
const { v4: uuidv4 } = require('uuid');
20+
const {assert} = require('chai');
21+
const {describe, it} = require('mocha');
22+
const cp = require('child_process');
23+
const speech = require('@google-cloud/speech').v1p1beta1;
24+
25+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
26+
const storageUri = 'gs://cloud-samples-tests/speech/brooklyn.flac';
27+
const text = 'how old is the Brooklyn Bridge';
28+
const adaptationClient = new speech.AdaptationClient();
29+
30+
const projectId = process.env.GCLOUD_PROJECT;
31+
const location = 'us-west1'
32+
const customClassId = uuidv4().replace(/-/g, '').substring(0, 20);
33+
const phraseSetId = uuidv4().replace(/-/g, '').substring(0, 20);
34+
const classParent = `projects/${projectId}/locations/${location}/customClasses/${customClassId}`;
35+
const phraseParent = `projects/${projectId}/locations/${location}/phraseSets/${customClassId}`;
36+
37+
describe('modelAdaptation', () => {
38+
it('should run modelAdaptation', async () => {
39+
const stdout = execSync(`node modelAdaptation.js ${projectId} ${location} ${storageUri} ${customClassId} ${phraseSetId}`)
40+
assert.match(stdout, /Transcription:/ );
41+
});
42+
// Release used resources
43+
cleanUp(classParent, phraseParent);
44+
});
45+
46+
async function cleanUp(classParent, phraseParent) {
47+
await adaptationClient.deleteCustomClass({ name: classParent });
48+
await adaptationClient.deletePhraseSet({ name: phraseParent });
49+
}

0 commit comments

Comments
 (0)