Skip to content

Commit

Permalink
docs(samples): adds model adaptation sample (#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-loved-dreamer authored and Ace Nassri committed Nov 17, 2022
1 parent 2d94f1f commit 25b9a21
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions speech/system-test/modelAdaptation.test.js
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 });
}

0 comments on commit 25b9a21

Please sign in to comment.