diff --git a/speech/.eslintrc.yml b/speech/.eslintrc.yml new file mode 100644 index 0000000000..282535f55f --- /dev/null +++ b/speech/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/speech/package.json b/speech/package.json index 6449f5ac39..06c72e2a52 100644 --- a/speech/package.json +++ b/speech/package.json @@ -4,42 +4,24 @@ "private": true, "license": "Apache-2.0", "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, + "repository": "googleapis/nodejs-speech", "engines": { - "node": ">=4.3.2" + "node": ">=4.0.0" }, "scripts": { - "lint": "samples lint", - "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + "test": "repo-tools test run --cmd ava -- -T 20s --verbose system-test/*.test.js" }, "dependencies": { - "@google-cloud/speech": "0.10.2", - "@google-cloud/storage": "1.2.1", + "@google-cloud/speech": "0.10.3", + "@google-cloud/storage": "1.4.0", "node-record-lpcm16": "0.3.0", - "yargs": "8.0.2" + "yargs": "10.0.3" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", + "@google-cloud/nodejs-repo-tools": "2.1.1", + "ava": "0.23.0", "proxyquire": "1.8.0", - "sinon": "3.2.0" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true, - "product": "speech", - "samples": [ - { - "id": "recognize", - "name": "Speech Recognition", - "file": "recognize.js", - "docs_link": "https://cloud.google.com/speech/docs", - "usage": "node recognize.js --help" - } - ] + "sinon": "4.1.1", + "uuid": "3.1.0" } } diff --git a/speech/quickstart.js b/speech/quickstart.js index 8652facb5f..47cd24bc0d 100644 --- a/speech/quickstart.js +++ b/speech/quickstart.js @@ -17,15 +17,15 @@ // [START speech_quickstart] // Imports the Google Cloud client library -const Speech = require('@google-cloud/speech'); +const speech = require('@google-cloud/speech'); const fs = require('fs'); // Your Google Cloud Platform project ID const projectId = 'your-project-id'; -// Instantiates a client -const speechClient = Speech({ - projectId: projectId +// Creates a client +const client = new speech.SpeechClient({ + projectId: projectId, }); // The name of the audio file to transcribe @@ -37,27 +37,29 @@ const audioBytes = file.toString('base64'); // The audio file's encoding, sample rate in hertz, and BCP-47 language code const audio = { - content: audioBytes + content: audioBytes, }; const config = { encoding: 'LINEAR16', sampleRateHertz: 16000, - languageCode: 'en-US' + languageCode: 'en-US', }; const request = { audio: audio, - config: config + config: config, }; // Detects speech in the audio file -speechClient.recognize(request) - .then((data) => { +client + .recognize(request) + .then(data => { const response = data[0]; - const transcription = response.results.map(result => - result.alternatives[0].transcript).join('\n'); + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); console.log(`Transcription: ${transcription}`); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_quickstart] diff --git a/speech/recognize.js b/speech/recognize.js index 6b5338f856..ddaef6e818 100644 --- a/speech/recognize.js +++ b/speech/recognize.js @@ -23,377 +23,374 @@ 'use strict'; -function syncRecognize (filename, encoding, sampleRateHertz, languageCode) { +function syncRecognize(filename, encoding, sampleRateHertz, languageCode) { // [START speech_sync_recognize] // Imports the Google Cloud client library const fs = require('fs'); - const Speech = require('@google-cloud/speech'); + const speech = require('@google-cloud/speech'); - // Instantiates a client - const speech = Speech(); + // Creates a client + const client = new speech.SpeechClient(); - // The path to the local file on which to perform speech recognition, e.g. /path/to/audio.raw - // const filename = '/path/to/audio.raw'; - - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const filename = 'Local path to audio file, e.g. /path/to/audio.raw'; + // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - content: fs.readFileSync(filename).toString('base64') + content: fs.readFileSync(filename).toString('base64'), }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file - speech.recognize(request) - .then((data) => { + client + .recognize(request) + .then(data => { const response = data[0]; - const transcription = response.results.map(result => - result.alternatives[0].transcript).join('\n'); + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); console.log(`Transcription: `, transcription); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_sync_recognize] } -function syncRecognizeGCS (gcsUri, encoding, sampleRateHertz, languageCode) { +function syncRecognizeGCS(gcsUri, encoding, sampleRateHertz, languageCode) { // [START speech_sync_recognize_gcs] // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); + const speech = require('@google-cloud/speech'); - // Instantiates a client - const speech = Speech(); + // Creates a client + const client = new speech.SpeechClient(); - // The Google Cloud Storage URI of the file on which to perform speech recognition, e.g. gs://my-bucket/audio.raw + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ // const gcsUri = 'gs://my-bucket/audio.raw'; - - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + // const encoding = 'Eencoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - uri: gcsUri + uri: gcsUri, }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file - speech.recognize(request) - .then((data) => { + client + .recognize(request) + .then(data => { const response = data[0]; - const transcription = response.results.map(result => - result.alternatives[0].transcript).join('\n'); + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); console.log(`Transcription: `, transcription); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_sync_recognize_gcs] } -function syncRecognizeWords (filename, encoding, sampleRateHertz, languageCode) { +function syncRecognizeWords(filename, encoding, sampleRateHertz, languageCode) { // [START speech_sync_recognize_words] // Imports the Google Cloud client library const fs = require('fs'); - const Speech = require('@google-cloud/speech'); - - // Instantiates a client - const speech = Speech(); + const speech = require('@google-cloud/speech'); - // The path to the local file on which to perform speech recognition, e.g. /path/to/audio.raw - // const filename = '/path/to/audio.raw'; + // Creates a client + const client = new speech.SpeechClient(); - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const filename = 'Local path to audio file, e.g. /path/to/audio.raw'; + // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { enableWordTimeOffsets: true, encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - content: fs.readFileSync(filename).toString('base64') + content: fs.readFileSync(filename).toString('base64'), }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file - speech.recognize(request) - .then((data) => { + client + .recognize(request) + .then(data => { const response = data[0]; - response.results.forEach((result) => { + response.results.forEach(result => { console.log(`Transcription: `, result.alternatives[0].transcript); - result.alternatives[0].words.forEach((wordInfo) => { + result.alternatives[0].words.forEach(wordInfo => { // NOTE: If you have a time offset exceeding 2^32 seconds, use the // wordInfo.{x}Time.seconds.high to calculate seconds. - const startSecs = `${wordInfo.startTime.seconds}` + `.` + - (wordInfo.startTime.nanos / 100000000); - const endSecs = `${wordInfo.endTime.seconds}` + `.` + - (wordInfo.endTime.nanos / 100000000); + const startSecs = + `${wordInfo.startTime.seconds}` + + `.` + + wordInfo.startTime.nanos / 100000000; + const endSecs = + `${wordInfo.endTime.seconds}` + + `.` + + wordInfo.endTime.nanos / 100000000; console.log(`Word: ${wordInfo.word}`); console.log(`\t ${startSecs} secs - ${endSecs} secs`); }); }); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_sync_recognize_words] } -function asyncRecognize (filename, encoding, sampleRateHertz, languageCode) { +function asyncRecognize(filename, encoding, sampleRateHertz, languageCode) { // [START speech_async_recognize] // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); + const speech = require('@google-cloud/speech'); const fs = require('fs'); - // Instantiates a client - const speech = Speech(); - - // The path to the local file on which to perform speech recognition, e.g. /path/to/audio.raw - // const filename = '/path/to/audio.raw'; + // Creates a client + const client = new speech.SpeechClient(); - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const filename = 'Local path to audio file, e.g. /path/to/audio.raw'; + // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - content: fs.readFileSync(filename).toString('base64') + content: fs.readFileSync(filename).toString('base64'), }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file. This creates a recognition job that you // can wait for now, or get its result later. - speech.longRunningRecognize(request) - .then((data) => { + client + .longRunningRecognize(request) + .then(data => { const response = data[0]; const operation = response; // Get a Promise representation of the final result of the job return operation.promise(); }) - .then((data) => { + .then(data => { const response = data[0]; - const transcription = response.results.map(result => - result.alternatives[0].transcript).join('\n'); + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); console.log(`Transcription: ${transcription}`); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_async_recognize] } -function asyncRecognizeGCS (gcsUri, encoding, sampleRateHertz, languageCode) { +function asyncRecognizeGCS(gcsUri, encoding, sampleRateHertz, languageCode) { // [START speech_async_recognize_gcs] // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); + const speech = require('@google-cloud/speech'); - // Instantiates a client - const speech = Speech(); + // Creates a client + const client = new speech.SpeechClient(); - // The Google Cloud Storage URI of the file on which to perform speech recognition, e.g. gs://my-bucket/audio.raw + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ // const gcsUri = 'gs://my-bucket/audio.raw'; - - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + // const encoding = 'Eencoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - uri: gcsUri + uri: gcsUri, }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file. This creates a recognition job that you // can wait for now, or get its result later. - speech.longRunningRecognize(request) - .then((data) => { + client + .longRunningRecognize(request) + .then(data => { const operation = data[0]; // Get a Promise representation of the final result of the job return operation.promise(); }) - .then((data) => { + .then(data => { const response = data[0]; - const transcription = response.results.map(result => - result.alternatives[0].transcript).join('\n'); + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); console.log(`Transcription: ${transcription}`); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_async_recognize_gcs] } -function asyncRecognizeGCSWords (gcsUri, encoding, sampleRateHertz, languageCode) { +function asyncRecognizeGCSWords( + gcsUri, + encoding, + sampleRateHertz, + languageCode +) { // [START speech_async_recognize_gcs_words] // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); + const speech = require('@google-cloud/speech'); - // Instantiates a client - const speech = Speech(); + // Creates a client + const client = new speech.SpeechClient(); - // The Google Cloud Storage URI of the file on which to perform speech recognition, e.g. gs://my-bucket/audio.raw + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ // const gcsUri = 'gs://my-bucket/audio.raw'; - - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; - - // The sample rate of the audio file in hertz, e.g. 16000 + // const encoding = 'Eencoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const config = { enableWordTimeOffsets: true, encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }; const audio = { - uri: gcsUri + uri: gcsUri, }; const request = { config: config, - audio: audio + audio: audio, }; // Detects speech in the audio file. This creates a recognition job that you // can wait for now, or get its result later. - speech.longRunningRecognize(request) - .then((data) => { + client + .longRunningRecognize(request) + .then(data => { const operation = data[0]; // Get a Promise representation of the final result of the job return operation.promise(); }) - .then((data) => { + .then(data => { const response = data[0]; - response.results.forEach((result) => { + response.results.forEach(result => { console.log(`Transcription: ${result.alternatives[0].transcript}`); - result.alternatives[0].words.forEach((wordInfo) => { + result.alternatives[0].words.forEach(wordInfo => { // NOTE: If you have a time offset exceeding 2^32 seconds, use the // wordInfo.{x}Time.seconds.high to calculate seconds. - const startSecs = `${wordInfo.startTime.seconds}` + `.` + - (wordInfo.startTime.nanos / 100000000); - const endSecs = `${wordInfo.endTime.seconds}` + `.` + - (wordInfo.endTime.nanos / 100000000); + const startSecs = + `${wordInfo.startTime.seconds}` + + `.` + + wordInfo.startTime.nanos / 100000000; + const endSecs = + `${wordInfo.endTime.seconds}` + + `.` + + wordInfo.endTime.nanos / 100000000; console.log(`Word: ${wordInfo.word}`); console.log(`\t ${startSecs} secs - ${endSecs} secs`); }); }); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END speech_async_recognize_gcs_words] } -function streamingRecognize (filename, encoding, sampleRateHertz, languageCode) { +function streamingRecognize(filename, encoding, sampleRateHertz, languageCode) { // [START speech_streaming_recognize] const fs = require('fs'); // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); - - // Instantiates a client - const speech = Speech(); - - // The path to the local file on which to perform speech recognition, e.g. /path/to/audio.raw - // const filename = '/path/to/audio.raw'; + const speech = require('@google-cloud/speech'); - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; + // Creates a client + const client = new speech.SpeechClient(); - // The sample rate of the audio file in hertz, e.g. 16000 + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const filename = 'Local path to audio file, e.g. /path/to/audio.raw'; + // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const request = { config: { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }, - interimResults: false // If you want interim results, set this to true + interimResults: false, // If you want interim results, set this to true }; // Stream the audio to the Google Cloud Speech API - const recognizeStream = speech.streamingRecognize(request) + const recognizeStream = client + .streamingRecognize(request) .on('error', console.error) - .on('data', (data) => { + .on('data', data => { console.log( - `Transcription: ${data.results[0].alternatives[0].transcript}`); + `Transcription: ${data.results[0].alternatives[0].transcript}` + ); }); // Stream an audio file from disk to the Speech API, e.g. "./resources/audio.raw" @@ -401,42 +398,43 @@ function streamingRecognize (filename, encoding, sampleRateHertz, languageCode) // [END speech_streaming_recognize] } -function streamingMicRecognize (encoding, sampleRateHertz, languageCode) { +function streamingMicRecognize(encoding, sampleRateHertz, languageCode) { // [START speech_streaming_mic_recognize] const record = require('node-record-lpcm16'); // Imports the Google Cloud client library - const Speech = require('@google-cloud/speech'); - - // Instantiates a client - const speech = Speech(); + const speech = require('@google-cloud/speech'); - // The encoding of the audio file, e.g. 'LINEAR16' - // const encoding = 'LINEAR16'; + // Creates a client + const client = new speech.SpeechClient(); - // The sample rate of the audio file in hertz, e.g. 16000 + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const encoding = 'Encoding of the audio file, e.g. LINEAR16'; // const sampleRateHertz = 16000; - - // The BCP-47 language code to use, e.g. 'en-US' - // const languageCode = 'en-US'; + // const languageCode = 'BCP-47 language code, e.g. en-US'; const request = { config: { encoding: encoding, sampleRateHertz: sampleRateHertz, - languageCode: languageCode + languageCode: languageCode, }, - interimResults: false // If you want interim results, set this to true + interimResults: false, // If you want interim results, set this to true }; // Create a recognize stream - const recognizeStream = speech.streamingRecognize(request) + const recognizeStream = client + .streamingRecognize(request) .on('error', console.error) - .on('data', (data) => - process.stdout.write( - (data.results[0] && data.results[0].alternatives[0]) - ? `Transcription: ${data.results[0].alternatives[0].transcript}\n` - : `\n\nReached transcription time limit, press Ctrl+C\n`)); + .on('data', data => + process.stdout.write( + data.results[0] && data.results[0].alternatives[0] + ? `Transcription: ${data.results[0].alternatives[0].transcript}\n` + : `\n\nReached transcription time limit, press Ctrl+C\n` + ) + ); // Start recording and send the microphone input to the Speech API record @@ -446,7 +444,7 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) { // Other options, see https://www.npmjs.com/package/node-record-lpcm16#options verbose: false, recordProgram: 'rec', // Try also "arecord" or "sox" - silence: '10.0' + silence: '10.0', }) .on('error', console.error) .pipe(recognizeStream); @@ -455,55 +453,102 @@ function streamingMicRecognize (encoding, sampleRateHertz, languageCode) { // [END speech_streaming_mic_recognize] } -const cli = require(`yargs`) +require(`yargs`) .demand(1) .command( `sync `, `Detects speech in a local audio file.`, {}, - (opts) => syncRecognize(opts.filename, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + syncRecognize( + opts.filename, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `sync-gcs `, `Detects speech in an audio file located in a Google Cloud Storage bucket.`, {}, - (opts) => syncRecognizeGCS(opts.gcsUri, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + syncRecognizeGCS( + opts.gcsUri, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `sync-words `, `Detects speech in a local audio file with word time offset.`, {}, - (opts) => syncRecognizeWords(opts.filename, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + syncRecognizeWords( + opts.filename, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `async `, `Creates a job to detect speech in a local audio file, and waits for the job to complete.`, {}, - (opts) => asyncRecognize(opts.filename, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + asyncRecognize( + opts.filename, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `async-gcs `, `Creates a job to detect speech in an audio file located in a Google Cloud Storage bucket, and waits for the job to complete.`, {}, - (opts) => asyncRecognizeGCS(opts.gcsUri, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + asyncRecognizeGCS( + opts.gcsUri, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `async-gcs-words `, `Creates a job to detect speech with word time offset in an audio file located in a Google Cloud Storage bucket, and waits for the job to complete.`, {}, - (opts) => asyncRecognizeGCSWords(opts.gcsUri, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + asyncRecognizeGCSWords( + opts.gcsUri, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `stream `, `Detects speech in a local audio file by streaming it to the Speech API.`, {}, - (opts) => streamingRecognize(opts.filename, opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + streamingRecognize( + opts.filename, + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .command( `listen`, `Detects speech in a microphone input stream. This command requires that you have SoX installed and available in your $PATH. See https://www.npmjs.com/package/node-record-lpcm16#dependencies`, {}, - (opts) => streamingMicRecognize(opts.encoding, opts.sampleRateHertz, opts.languageCode) + opts => + streamingMicRecognize( + opts.encoding, + opts.sampleRateHertz, + opts.languageCode + ) ) .options({ encoding: { @@ -511,22 +556,22 @@ const cli = require(`yargs`) default: 'LINEAR16', global: true, requiresArg: true, - type: 'string' + type: 'string', }, sampleRateHertz: { alias: 'r', default: 16000, global: true, requiresArg: true, - type: 'number' + type: 'number', }, languageCode: { alias: 'l', default: 'en-US', global: true, requiresArg: true, - type: 'string' - } + type: 'string', + }, }) .example(`node $0 sync ./resources/audio.raw -e LINEAR16 -r 16000`) .example(`node $0 async-gcs gs://gcs-test-data/vr.flac -e FLAC -r 16000`) @@ -536,8 +581,4 @@ const cli = require(`yargs`) .recommendCommands() .epilogue(`For more information, see https://cloud.google.com/speech/docs`) .help() - .strict(); - -if (module === require.main) { - cli.parse(process.argv.slice(2)); -} + .strict().argv; diff --git a/speech/system-test/.eslintrc.yml b/speech/system-test/.eslintrc.yml new file mode 100644 index 0000000000..c0289282a6 --- /dev/null +++ b/speech/system-test/.eslintrc.yml @@ -0,0 +1,5 @@ +--- +rules: + node/no-unpublished-require: off + node/no-unsupported-features: off + no-empty: off diff --git a/speech/system-test/quickstart.test.js b/speech/system-test/quickstart.test.js index 6a86782a10..9d18ee2cfb 100644 --- a/speech/system-test/quickstart.test.js +++ b/speech/system-test/quickstart.test.js @@ -22,14 +22,11 @@ const cmd = `node quickstart.js`; const cwd = path.join(__dirname, `..`); const text = `how old is the Brooklyn Bridge`; -const { - runAsync -} = require(`@google-cloud/nodejs-repo-tools`); +const {runAsync} = require(`@google-cloud/nodejs-repo-tools`); -test.before(async () => { -}); +test.before(async () => {}); -test(`should run quickstart`, async (t) => { +test(`should run quickstart`, async t => { const output = await runAsync(`${cmd}`, cwd); t.true(output.includes(`Transcription: ${text}`)); }); diff --git a/speech/system-test/recognize.test.js b/speech/system-test/recognize.test.js index 7c729d5b53..57ba0507c5 100644 --- a/speech/system-test/recognize.test.js +++ b/speech/system-test/recognize.test.js @@ -20,9 +20,7 @@ const storage = require(`@google-cloud/storage`)(); const test = require(`ava`); const uuid = require(`uuid`); -const { - runAsync -} = require(`@google-cloud/nodejs-repo-tools`); +const {runAsync} = require(`@google-cloud/nodejs-repo-tools`); const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; const cmd = `node recognize.js`; @@ -38,45 +36,54 @@ test.before(async () => { test.after.always(async () => { const bucket = storage.bucket(bucketName); - await bucket.deleteFiles({ force: true }); - await bucket.deleteFiles({ force: true }); // Try a second time... + await bucket.deleteFiles({force: true}); + await bucket.deleteFiles({force: true}); // Try a second time... await bucket.delete(); }); -test(`should run sync recognize`, async (t) => { +test(`should run sync recognize`, async t => { const output = await runAsync(`${cmd} sync ${filepath}`, cwd); t.true(output.includes(`Transcription: ${text}`)); }); -test(`should run sync recognize on a GCS file`, async (t) => { - const output = await runAsync(`${cmd} sync-gcs gs://${bucketName}/${filename}`, cwd); +test(`should run sync recognize on a GCS file`, async t => { + const output = await runAsync( + `${cmd} sync-gcs gs://${bucketName}/${filename}`, + cwd + ); t.true(output.includes(`Transcription: ${text}`)); }); -test(`should run sync recognize with word time offset`, async (t) => { +test(`should run sync recognize with word time offset`, async t => { const output = await runAsync(`${cmd} sync-words ${filepath}`, cwd); t.true(output.includes(`Transcription: ${text}`)); t.true(new RegExp(`\\d+\\.\\d+ secs - \\d+\\.\\d+ secs`).test(output)); }); -test(`should run async recognize on a local file`, async (t) => { +test(`should run async recognize on a local file`, async t => { const output = await runAsync(`${cmd} async ${filepath}`, cwd); t.true(output.includes(`Transcription: ${text}`)); }); -test(`should run async recognize on a GCS file`, async (t) => { - const output = await runAsync(`${cmd} async-gcs gs://${bucketName}/${filename}`, cwd); +test(`should run async recognize on a GCS file`, async t => { + const output = await runAsync( + `${cmd} async-gcs gs://${bucketName}/${filename}`, + cwd + ); t.true(output.includes(`Transcription: ${text}`)); }); -test(`should run async recognize on a GCS file with word time offset`, async (t) => { - const output = await runAsync(`${cmd} async-gcs-words gs://${bucketName}/${filename}`, cwd); +test(`should run async recognize on a GCS file with word time offset`, async t => { + const output = await runAsync( + `${cmd} async-gcs-words gs://${bucketName}/${filename}`, + cwd + ); t.true(output.includes(`Transcription: ${text}`)); // Check for word time offsets t.true(new RegExp(`\\d+\\.\\d+ secs - \\d+\\.\\d+ secs`).test(output)); }); -test(`should run streaming recognize`, async (t) => { +test(`should run streaming recognize`, async t => { const output = await runAsync(`${cmd} stream ${filepath}`, cwd); t.true(output.includes(`Transcription: ${text}`)); });