diff --git a/packages/google-cloud-speech/samples/README.md b/packages/google-cloud-speech/samples/README.md index 19ec303cdac..c316d64ec3c 100644 --- a/packages/google-cloud-speech/samples/README.md +++ b/packages/google-cloud-speech/samples/README.md @@ -32,7 +32,7 @@ recognition technologies into developer applications. View the [documentation][recognize_docs] or the [source code][recognize_code]. -__Usage:__ `node recognize --help` +__Usage:__ `node recognize.js --help` ``` Commands: @@ -42,15 +42,13 @@ Commands: listen Detects speech in a microphone input stream. Options: - --help Show help [boolean] + --help Show help [boolean] Examples: - node recognize sync ./resources/audio.raw Detects speech in "./resources/audio.raw". - node recognize async ./resources/audio.raw Creates a job to detect speech in "./resources/audio.raw", and waits for - the job to complete. - node recognize stream ./resources/audio.raw Detects speech in "./resources/audio.raw" by streaming it to the Speech - API. - node recognize listen ./resources/audio.raw Detects speech in a microphone input stream. + node recognize.js sync ./resources/audio.raw + node recognize.js async ./resources/audio.raw + node recognize.js stream ./resources/audio.raw + node recognize.js listen For more information, see https://cloud.google.com/speech/docs ``` diff --git a/packages/google-cloud-speech/samples/package.json b/packages/google-cloud-speech/samples/package.json index 63b3f552541..4ce70045cb4 100644 --- a/packages/google-cloud-speech/samples/package.json +++ b/packages/google-cloud-speech/samples/package.json @@ -5,17 +5,13 @@ "license": "Apache Version 2.0", "author": "Google Inc.", "scripts": { - "test": "mocha -R spec -t 10000 --require intelli-espower-loader ../test/_setup.js test/*.test.js", - "system-test": "mocha -R spec -t 10000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js" + "test": "cd ..; npm run st -- speech/system-test/*.test.js" }, "dependencies": { "@google-cloud/speech": "^0.4.0", "node-record-lpcm16": "^0.1.4", "yargs": "^6.4.0" }, - "devDependencies": { - "mocha": "^3.1.2" - }, "engines": { "node": ">=4.3.2" } diff --git a/packages/google-cloud-speech/samples/quickstart.js b/packages/google-cloud-speech/samples/quickstart.js index fa28527ca30..bc2cde2bd46 100644 --- a/packages/google-cloud-speech/samples/quickstart.js +++ b/packages/google-cloud-speech/samples/quickstart.js @@ -37,12 +37,9 @@ const options = { }; // Detects speech in the audio file -speechClient.recognize(fileName, options, (err, result) => { - if (err) { - console.error(err); - return; - } - - console.log(`Transcription: ${result}`); -}); +speechClient.recognize(fileName, options) + .then((results) => { + const transcription = results[0]; + console.log(`Transcription: ${transcription}`); + }); // [END speech_quickstart] diff --git a/packages/google-cloud-speech/samples/test/quickstart.test.js b/packages/google-cloud-speech/samples/test/quickstart.test.js deleted file mode 100644 index 807e23e507f..00000000000 --- a/packages/google-cloud-speech/samples/test/quickstart.test.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2016, Google, Inc. - * 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. - */ - -'use strict'; - -const proxyquire = require(`proxyquire`).noCallThru(); - -const config = { - encoding: 'LINEAR16', - sampleRate: 16000 -}; - -describe(`speech:quickstart`, () => { - let speechMock, SpeechMock; - const error = new Error(`error`); - const fileName = `./resources/audio.raw`; - - before(() => { - speechMock = { - recognize: sinon.stub().yields(error) - }; - SpeechMock = sinon.stub().returns(speechMock); - }); - - it(`should handle error`, () => { - proxyquire(`../quickstart`, { - '@google-cloud/speech': SpeechMock - }); - - assert.equal(SpeechMock.calledOnce, true); - assert.deepEqual(SpeechMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); - assert.equal(speechMock.recognize.calledOnce, true); - assert.deepEqual(speechMock.recognize.firstCall.args.slice(0, -1), [fileName, config]); - assert.equal(console.error.calledOnce, true); - assert.deepEqual(console.error.firstCall.args, [error]); - }); -});