Skip to content

Commit

Permalink
feat: adds a multi region sample (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-loved-dreamer authored Dec 21, 2020
1 parent f663ad2 commit 02e4346
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
11 changes: 3 additions & 8 deletions speech/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ function main() {
// [START speech_quickstart]
// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');
const fs = require('fs').promises;

// Creates a client
const client = new speech.SpeechClient();

async function quickstart() {
// The name of the audio file to transcribe
const fileName = './resources/audio.raw';

// Reads a local audio file and converts it to base64
const file = await fs.readFile(fileName);
const audioBytes = file.toString('base64');
// The path to the remote LINEAR16 file
const gcsUri = 'gs://cloud-samples-data/speech/brooklyn_bridge.raw';

// The audio file's encoding, sample rate in hertz, and BCP-47 language code
const audio = {
content: audioBytes,
uri: gcsUri,
};
const config = {
encoding: 'LINEAR16',
Expand Down
32 changes: 32 additions & 0 deletions speech/system-test/multiRegion.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020 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
//
// https://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 {assert} = require('chai');
const {describe, it} = require('mocha');
const cp = require('child_process');

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';

describe('multiRegion', () => {
it('should run multiRegion', async () => {
const stdout = execSync(`node multiRegion.js ${storageUri}`)
assert.match(stdout, /Transcription:/ );
});
});
2 changes: 1 addition & 1 deletion speech/system-test/profanityFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ describe('profanityFilter', () => {
const stdout = execSync(`node profanityFilter.js ${storageUri}`)
assert.match(stdout, /Transcription:/ );
});
});
});

0 comments on commit 02e4346

Please sign in to comment.