-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(samples): adds model adaptation sample (#712)
- Loading branch information
1 parent
2d94f1f
commit 25b9a21
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* eslint-disable */ | ||
|
||
'use strict'; | ||
|
||
const { v4: uuidv4 } = require('uuid'); | ||
const {assert} = require('chai'); | ||
const {describe, it} = require('mocha'); | ||
const cp = require('child_process'); | ||
const speech = require('@google-cloud/speech').v1p1beta1; | ||
|
||
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); | ||
const storageUri = 'gs://cloud-samples-tests/speech/brooklyn.flac'; | ||
const text = 'how old is the Brooklyn Bridge'; | ||
const adaptationClient = new speech.AdaptationClient(); | ||
|
||
const projectId = process.env.GCLOUD_PROJECT; | ||
const location = 'us-west1' | ||
const customClassId = uuidv4().replace(/-/g, '').substring(0, 20); | ||
const phraseSetId = uuidv4().replace(/-/g, '').substring(0, 20); | ||
const classParent = `projects/${projectId}/locations/${location}/customClasses/${customClassId}`; | ||
const phraseParent = `projects/${projectId}/locations/${location}/phraseSets/${customClassId}`; | ||
|
||
describe('modelAdaptation', () => { | ||
it('should run modelAdaptation', async () => { | ||
const stdout = execSync(`node modelAdaptation.js ${projectId} ${location} ${storageUri} ${customClassId} ${phraseSetId}`) | ||
assert.match(stdout, /Transcription:/ ); | ||
}); | ||
// Release used resources | ||
cleanUp(classParent, phraseParent); | ||
}); | ||
|
||
async function cleanUp(classParent, phraseParent) { | ||
await adaptationClient.deleteCustomClass({ name: classParent }); | ||
await adaptationClient.deletePhraseSet({ name: phraseParent }); | ||
} |