diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..a6867007 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/samples/betaFeatures.js" + } + ] +} \ No newline at end of file diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 403c40a8..525d8704 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -6,7 +6,14 @@ Ace Nassri Alexander Fenster Ali Ijaz Sheikh +Chris Frater +Chris Frater +Chris Frater +Christopher Wilcox +Christopher Wilcox +DPE bot Dan Aharon +Daniel Ruf Daryush Laqab Dave Gramlich Eric Uldall @@ -14,14 +21,19 @@ Ernest Landrito Gus Class Jason Dobry Jerjou +Jonathan Lui Jun Mukai +Justin Beckwith Luke Sneeringer Philippe Sultan Pierre Fritsch Puneith Kaul Rebecca Taylor +Shahin Song Wang Stephen Sawchuk Tim Swast +cfrater greenkeeper[bot] +renovate[bot] wanacode diff --git a/README.md b/README.md index 71f38887..ebd59210 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `npm run generate-scaffolding`." Google Cloud Platform logo # [Google Cloud Speech API: Node.js Client](https://github.com/googleapis/nodejs-speech) @@ -145,4 +147,4 @@ See [LICENSE](https://github.com/googleapis/nodejs-speech/blob/master/LICENSE) [client-docs]: https://cloud.google.com/nodejs/docs/reference/speech/latest/ [product-docs]: https://cloud.google.com/speech/docs -[shell_img]: //gstatic.com/cloudssh/images/open-btn.png +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png diff --git a/package-lock.json b/package-lock.json old mode 100644 new mode 100755 diff --git a/package.json b/package.json index 49fbbbcd..aa7c3f3e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,14 @@ "Ace Nassri ", "Alexander Fenster ", "Ali Ijaz Sheikh ", + "Chris Frater ", + "Chris Frater ", + "Chris Frater ", + "Christopher Wilcox ", + "Christopher Wilcox ", + "DPE bot ", "Dan Aharon ", + "Daniel Ruf ", "Daryush Laqab ", "Dave Gramlich ", "Eric Uldall ", @@ -40,16 +47,21 @@ "Gus Class ", "Jason Dobry ", "Jerjou ", + "Jonathan Lui ", "Jun Mukai ", + "Justin Beckwith ", "Luke Sneeringer ", "Philippe Sultan ", "Pierre Fritsch ", "Puneith Kaul ", "Rebecca Taylor ", + "Shahin ", "Song Wang ", "Stephen Sawchuk ", "Tim Swast ", + "cfrater ", "greenkeeper[bot] ", + "renovate[bot] ", "wanacode " ], "scripts": { diff --git a/samples/README.md b/samples/README.md index 4b8fb0c9..1acc3006 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,3 +1,5 @@ +[//]: # "This README.md file is auto-generated, all changes to this file will be lost." +[//]: # "To regenerate it, use `npm run generate-scaffolding`." Google Cloud Platform logo # Google Cloud Speech API: Node.js Samples @@ -78,9 +80,12 @@ __Usage:__ `node recognize.v1p1beta1.js --help` recognize.v1p1beta1.js Commands: - recognize.v1p1beta1.js sync-model Detects speech in a local audio file using provided model. - recognize.v1p1beta1.js sync-model-gcs Detects speech in an audio file located in a Google Cloud - Storage bucket using provided model. + recognize.v1p1beta1.js sync-model Detects speech in a local audio file using provided model. + recognize.v1p1beta1.js sync-model-gcs Detects speech in an audio file located in a Google Cloud + Storage bucket using provided model. + recognize.v1p1beta1.js sync-auto-punctuation Detects speech in a local audio file with auto punctuation. + recognize.v1p1beta1.js sync-metadata Detects speech in a local audio file with metadata. + recognize.v1p1beta1.js sync-enhanced-model Detects speech in a local audio file using an enhanced model. Options: --version Show version number [boolean] @@ -92,6 +97,9 @@ Options: Examples: node recognize.v1p1beta1.js sync-model ./resources/Google_Gnome.wav video -e LINEAR16 -r 16000 node recognize.v1p1beta1.js sync-model-gcs gs://gcs-test-data/Google_Gnome.wav phone_call -e FLAC -r 16000 + node recognize.v1p1beta1.js sync-auto-punctuation ./resources/commercial_mono.wav + node recognize.v1p1beta1.js sync-metadata ./resources/commercial_mono.wav + node recognize.v1p1beta1.js sync-enhanced-model ./resources/commercial_mono.wav For more information, see https://cloud.google.com/speech/docs ``` @@ -99,5 +107,53 @@ For more information, see https://cloud.google.com/speech/docs [recognize.v1p1beta1_1_docs]: https://cloud.google.com/speech/docs [recognize.v1p1beta1_1_code]: recognize.v1p1beta1.js +[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png +[shell_img]: //gstatic.com/cloudssh/images/open-btn.png +[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/README.md + +### Speech Recognition betaFeatures + +View the [source code][betaFeatures_code]. + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/betaFeatures.js,samples/README.md) + +__Usage:__ `node betaFeatures.js --help` + +``` +betaFeatures.js + +Commands: + betaFeatures.js Diarization Isolate distinct speakers in an audio file + betaFeatures.js DiarizationGCS Isolate distinct speakers in an audio file located in a Google Cloud + Storage bucket. + betaFeatures.js multiChannelTranscribe Differentiates input by audio channel in local audio file. + betaFeatures.js multiChannelTranscribeGCS Differentiates input by audio channe from GCS audio file. + betaFeatures.js multiLanguageTranscribe Transcribes multiple languages from local audio file. + betaFeatures.js multiLanguageTranscribeGCS Transcribes multiple languages from GCS audio file. + betaFeatures.js wordLevelConfidence Detects word level confidence from local audio file. + betaFeatures.js wordLevelConfidenceGCS Detects word level confidence from GCS audio file. + +Options: + --version Show version number [boolean] + --speechFile, -f [string] + --gcsUri, -u [string] + --help Show help [boolean] + +Examples: + node betaFeatures.js Diarization -f ./resources/commercial_mono.wav + node betaFeatures.js DiarizationGCS -u gs://cloud-samples-tests/speech/commercial_mono.wav + node betaFeatures.js multiChannelTranscribe -f ./resources/commercial_stereo.wav + node betaFeatures.js multiChannelTranscribeGCS -u gs://cloud-samples-tests/speech/commercial_stereo.wav + node betaFeatures.js multiLanguageTranscribe -f ./resources/multi.wav + node betaFeatures.js multiLanguageTranscribeGCS -u gs://nodejs-docs-samples/multi_mono.wav + node betaFeatures.js wordLevelConfidence -f ./resources/brooklyn.flac + node betaFeatures.js wordLevelConfidenceGCS -u gs://cloud-samples-tests/speech/brooklyn.flac + +For more information, see https://cloud.google.com/speech/docs +``` + +[betaFeatures_docs]: https://cloud.google.com/speech/docs +[betaFeatures_code]: recognize.v1p1beta1.js + [shell_img]: //gstatic.com/cloudssh/images/open-btn.png [shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-speech&page=editor&open_in_editor=samples/README.md diff --git a/samples/betaFeatures.js b/samples/betaFeatures.js new file mode 100644 index 00000000..834b8fa2 --- /dev/null +++ b/samples/betaFeatures.js @@ -0,0 +1,528 @@ +/** + * Copyright 2017, 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. + */ + +/** + * This application demonstrates how to perform basic recognize operations with + * with the Google Cloud Speech API. + * + * For more information, see the README.md under /speech and the documentation + * at https://cloud.google.com/speech/docs. + */ + +'use strict'; + +function speechTranscribeDiarization(fileName) { + // [START speech_transcribe_diarization] + const fs = require('fs'); + + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const fileName = 'Local path to audio file, e.g. /path/to/audio.raw'; + + const config = { + encoding: `LINEAR16`, + sampleRateHertz: 8000, + languageCode: `en-US`, + enableSpeakerDiarization: true, + diarizationSpeakerCount: 2, + model: `phone_call`, + }; + + const audio = { + content: fs.readFileSync(fileName).toString('base64'), + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + console.log(`Transcription: ${transcription}`); + console.log(`Speaker Diarization:`); + const result = response.results[response.results.length - 1]; + const wordsInfo = result.alternatives[0].words; + // Note: The transcript within each result is separate and sequential per result. + // However, the words list within an alternative includes all the words + // from all the results thus far. Thus, to get all the words with speaker + // tags, you only have to take the words list from the last result: + wordsInfo.forEach(a => + console.log(` word: ${a.word}, speakerTag: ${a.speakerTag}`) + ); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_diarization] +} + +function asyncSpeechTranscribeDiarizationGCS(gcsUri) { + // [START speech_transcribe_diarization_gcs] + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following line before running the sample. + */ + // const uri = path to GCS audio file e.g. `gs:/bucket/audio.wav`; + + const config = { + encoding: `LINEAR16`, + sampleRateHertz: 8000, + languageCode: `en-US`, + enableSpeakerDiarization: true, + diarizationSpeakerCount: 2, + model: `phone_call`, + }; + + const audio = { + uri: gcsUri, + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + console.log(`Transcription: ${transcription}`); + console.log(`Speaker Diarization:`); + const result = response.results[response.results.length - 1]; + const wordsInfo = result.alternatives[0].words; + // Note: The transcript within each result is separate and sequential per result. + // However, the words list within an alternative includes all the words + // from all the results thus far. Thus, to get all the words with speaker + // tags, you only have to take the words list from the last result: + wordsInfo.forEach(a => + console.log(` word: ${a.word}, speakerTag: ${a.speakerTag}`) + ); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_diarization_gcs] +} + +function speechTranscribeMultiChannel(fileName) { + // [START speech_transcribe_multichannel] + const fs = require('fs'); + + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const fileName = 'Local path to audio file, e.g. /path/to/audio.raw'; + + const config = { + encoding: `LINEAR16`, + languageCode: `en-US`, + audioChannelCount: 2, + enableSeparateRecognitionPerChannel: true, + }; + + const audio = { + content: fs.readFileSync(fileName).toString('base64'), + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map( + result => + ` Channel Tag: ` + + result.channelTag + + ` ` + + result.alternatives[0].transcript + ) + .join('\n'); + console.log(`Transcription: \n${transcription}`); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_multichannel] +} + +function speechTranscribeMultichannelGCS(gcsUri) { + // [START speech_transcribe_multichannel_gcs] + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + const config = { + encoding: 'LINEAR16', + languageCode: `en-US`, + audioChannelCount: 2, + enableSeparateRecognitionPerChannel: true, + }; + + const audio = { + uri: gcsUri, + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map( + result => + ` Channel Tag: ` + + result.channelTag + + ` ` + + result.alternatives[0].transcript + ) + .join('\n'); + console.log(`Transcription: \n${transcription}`); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_multichannel_gcs] +} + +function speechTranscribeMultilang(fileName) { + // [START speech_transcribe_multilanguage] + const fs = require('fs'); + + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const fileName = 'Local path to audio file, e.g. /path/to/audio.raw'; + + const config = { + encoding: 'LINEAR16', + sampleRateHertz: 44100, + languageCode: `en-US`, + alternativeLanguageCodes: [`es-ES`, `en-US`], + }; + + const audio = { + content: fs.readFileSync(fileName).toString('base64'), + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + console.log(`Transcription: ${transcription}`); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_multilang] +} + +function speechTranscribeMultilangGCS(gcsUri) { + // [START speech_transcribe_multilang_gcs] + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following line before running the sample. + */ + // const uri = path to GCS audio file e.g. `gs:/bucket/audio.wav`; + + const config = { + encoding: 'LINEAR16', + sampleRateHertz: 44100, + languageCode: `en-US`, + alternativeLanguageCodes: [`es-ES`, `en-US`], + }; + + const audio = { + uri: gcsUri, + }; + + const request = { + config: config, + audio: audio, + }; + + client + .longRunningRecognize(request) + .then(data => { + const operation = data[0]; + return operation.promise(); + }) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + console.log(`Transcription: ${transcription}`); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_multilang_gcs] +} + +function speechTranscribeWordLevelConfidence(fileName) { + // [START speech_transcribe_word_level_confidence] + const fs = require('fs'); + + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following lines before running the sample. + */ + // const fileName = 'Local path to audio file, e.g. /path/to/audio.raw'; + + const config = { + encoding: `FLAC`, + sampleRateHertz: 16000, + languageCode: `en-US`, + enableWordConfidence: true, + }; + + const audio = { + content: fs.readFileSync(fileName).toString('base64'), + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + const confidence = response.results + .map(result => result.alternatives[0].confidence) + .join(`\n`); + console.log( + `Transcription: ${transcription} \n Confidence: ${confidence}` + ); + + console.log(`Word-Level-Confidence:`); + const words = response.results.map(result => result.alternatives[0]); + words[0].words.forEach(a => { + console.log(` word: ${a.word}, confidence: ${a.confidence}`); + }); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_word_level_confidence] +} + +function speechTranscribeWordLevelConfidenceGCS(gcsUri) { + // [START speech_transcribe_word_level_confidence_gcs] + // Imports the Google Cloud client library + const speech = require('@google-cloud/speech').v1p1beta1; + + // Creates a client + const client = new speech.SpeechClient(); + + /** + * TODO(developer): Uncomment the following line before running the sample. + */ + // const uri = path to GCS audio file e.g. `gs:/bucket/audio.wav`; + + const config = { + encoding: `FLAC`, + sampleRateHertz: 16000, + languageCode: `en-US`, + enableWordConfidence: true, + }; + + const audio = { + uri: gcsUri, + }; + + const request = { + config: config, + audio: audio, + }; + + client + .recognize(request) + .then(data => { + const response = data[0]; + const transcription = response.results + .map(result => result.alternatives[0].transcript) + .join('\n'); + const confidence = response.results + .map(result => result.alternatives[0].confidence) + .join(`\n`); + console.log( + `Transcription: ${transcription} \n Confidence: ${confidence}` + ); + + console.log(`Word-Level-Confidence:`); + const words = response.results.map(result => result.alternatives[0]); + words[0].words.forEach(a => { + console.log(` word: ${a.word}, confidence: ${a.confidence}`); + }); + }) + .catch(err => { + console.error('ERROR:', err); + }); + // [END speech_transcribe_word_level_confidence_gcs] +} + +require(`yargs`) + .demand(1) + .command( + `Diarization`, + `Isolate distinct speakers in an audio file`, + {}, + opts => speechTranscribeDiarization(opts.speechFile) + ) + .command( + `DiarizationGCS`, + `Isolate distinct speakers in an audio file located in a Google Cloud Storage bucket.`, + {}, + opts => asyncSpeechTranscribeDiarizationGCS(opts.gcsUri) + ) + .command( + `multiChannelTranscribe`, + `Differentiates input by audio channel in local audio file.`, + {}, + opts => speechTranscribeMultiChannel(opts.speechFile) + ) + .command( + `multiChannelTranscribeGCS`, + `Differentiates input by audio channel in an audio file located in a Google Cloud Storage bucket.`, + {}, + opts => speechTranscribeMultichannelGCS(opts.gcsUri) + ) + .command( + `multiLanguageTranscribe`, + `Transcribes multiple languages from local audio file.`, + {}, + opts => speechTranscribeMultilang(opts.speechFile) + ) + .command( + `multiLanguageTranscribeGCS`, + `Transcribes multiple languages from GCS audio file.`, + {}, + opts => speechTranscribeMultilangGCS(opts.gcsUri) + ) + .command( + `wordLevelConfidence`, + `Detects word level confidence from local audio file.`, + {}, + opts => speechTranscribeWordLevelConfidence(opts.speechFile) + ) + .command( + `wordLevelConfidenceGCS`, + `Detects word level confidence from GCS audio file.`, + {}, + opts => speechTranscribeWordLevelConfidenceGCS(opts.gcsUri) + ) + .options({ + speechFile: { + alias: 'f', + global: true, + requiresArg: false, + type: 'string', + }, + gcsUri: { + alias: 'u', + global: true, + requiresArg: true, + type: 'string', + }, + }) + .example(`node $0 Diarization -f ./resources/commercial_mono.wav`) + .example( + `node $0 DiarizationGCS -u gs://cloud-samples-tests/speech/commercial_mono.wav` + ) + .example( + `node $0 multiChannelTranscribe -f ./resources/commercial_stereo.wav` + ) + .example( + `node $0 multiChannelTranscribeGCS -u gs://cloud-samples-tests/speech/commercial_stereo.wav` + ) + .example(`node $0 multiLanguageTranscribe -f ./resources/multi.wav`) + .example( + `node $0 multiLanguageTranscribeGCS -u gs://nodejs-docs-samples/multi_mono.wav` + ) + .example(`node $0 wordLevelConfidence -f ./resources/brooklyn.flac`) + .example( + `node $0 wordLevelConfidenceGCS -u gs://cloud-samples-tests/speech/brooklyn.flac` + ) + .wrap(120) + .recommendCommands() + .epilogue(`For more information, see https://cloud.google.com/speech/docs`) + .help() + .strict().argv; diff --git a/samples/package-lock.json b/samples/package-lock.json old mode 100644 new mode 100755 diff --git a/samples/package.json b/samples/package.json old mode 100644 new mode 100755 diff --git a/samples/resources/ManualTest.wav b/samples/resources/ManualTest.wav new file mode 100644 index 00000000..c919511d Binary files /dev/null and b/samples/resources/ManualTest.wav differ diff --git a/samples/resources/brooklyn.flac b/samples/resources/brooklyn.flac new file mode 100644 index 00000000..44d6f9ec Binary files /dev/null and b/samples/resources/brooklyn.flac differ diff --git a/samples/resources/commercial_mono.wav b/samples/resources/commercial_mono.wav old mode 100644 new mode 100755 diff --git a/samples/resources/commercial_stereo.wav b/samples/resources/commercial_stereo.wav new file mode 100644 index 00000000..467f3687 Binary files /dev/null and b/samples/resources/commercial_stereo.wav differ diff --git a/samples/resources/multi.wav b/samples/resources/multi.wav new file mode 100644 index 00000000..5734aa03 Binary files /dev/null and b/samples/resources/multi.wav differ diff --git a/samples/system-test/betaFeatures.test.js b/samples/system-test/betaFeatures.test.js new file mode 100644 index 00000000..a5504fb0 --- /dev/null +++ b/samples/system-test/betaFeatures.test.js @@ -0,0 +1,109 @@ +// /** +// * Copyright 2016, 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 path = require(`path`); +const test = require(`ava`); + +const {runAsync} = require(`@google-cloud/nodejs-repo-tools`); + +const cmd = `node betaFeatures.js`; +const cwd = path.join(__dirname, `..`); + + +//audio file paths +const monoFileName = `commercial_mono.wav`; +const monoFilePath = path.join( + __dirname, + `../resources/${monoFileName}` +); + +const stereoFileName = `commercial_stereo.wav`; +const stereoFilePath = path.join( + __dirname, + `../resources/${stereoFileName}` +); +const multiLanguageFileName = `multi.wav`; +const multiLanguageFile = path.join( + __dirname, + `../resources/${multiLanguageFileName}` +); + +const gnomef = `Google_Gnome.wav`; +const gnome = path.join(__dirname, `../resources/${gnomef}`); + +const Brooklyn = 'brooklyn.flac'; +const BrooklynFilePath = path.join( + __dirname, + `../resources/${Brooklyn}` +); + +const monoUri = `gs://cloud-samples-tests/speech/commercial_mono.wav`; +const multiUri = `gs://nodejs-docs-samples/multi_mono.wav`; +const brooklynUri = `gs://cloud-samples-tests/speech/brooklyn.flac`; +const stereoUri = `gs://cloud-samples-tests/speech/commercial_stereo.wav`; + +test(`should run speech diarization on a local file`, async t => { + const output = await runAsync(`${cmd} Diarization -f ${monoFilePath}`, cwd); + t.true( + output.includes(`speakerTag: 1`) && output.includes(`speakerTag: 2`) + ); +}); + +test(`should run speech diarization on a GCS file`, async t => { + const output = await runAsync(`${cmd} DiarizationGCS -u ${monoUri}`, cwd); + t.true( + output.includes(`speakerTag: 1`) && output.includes(`speakerTag: 2`) + ); +}); + +test(`should run multi channel transcription on a local file`, async t => { + const output = await runAsync(`${cmd} multiChannelTranscribe -f ${stereoFilePath}`, cwd); + t.true(output.includes(`Channel Tag: 2`)); +}); + +test(`should run multi channel transcription on GCS file`, async t => { + const output = await runAsync(`${cmd} multiChannelTranscribeGCS -u ${stereoUri}`, cwd); + t.true(output.includes(`Channel Tag: 2`)); +}); + +test(`should transcribe multi-language on a local file`, async t => { + const output = await runAsync(`${cmd} multiLanguageTranscribe -f ${multiLanguageFile}`, cwd); + t.true(output.includes(`Transcription: how are you doing estoy bien e tu`)); +}); + +test(`should transcribe multi-language on a GCS bucket`, async t => { + const output = await runAsync(`${cmd} multiLanguageTranscribeGCS -u ${multiUri}`, cwd); + t.true(output.includes(`Transcription: how are you doing estoy bien e tu`)); +}); + +test(`should run word Level Confience on a local file`, async t => { + const output = await runAsync(`${cmd} wordLevelConfidence -f ${BrooklynFilePath}`); + t.true( + output.includes(`Transcription: how old is the Brooklyn Bridge`) && + output.includes(`Confidence: \d\.\d`) + ); +}); + +test(`should run word level confidence on a GCS bucket`, async t => { + const output = await runAsync(`${cmd} wordLevelConfidenceGCS -u ${brooklynUri}`, cwd); + t.true( + output.includes(`Transcription: how old is the Brooklyn Bridge`) && + output.includes(`Confidence: \d\.\d`) + ); +}); diff --git a/samples/system-test/quickstart.test.js b/samples/system-test/quickstart.test.js index 9d18ee2c..56dd390d 100644 --- a/samples/system-test/quickstart.test.js +++ b/samples/system-test/quickstart.test.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable */ + 'use strict'; const path = require(`path`); diff --git a/samples/system-test/recognize.test.js b/samples/system-test/recognize.test.js index 57ba0507..3c9dd07e 100644 --- a/samples/system-test/recognize.test.js +++ b/samples/system-test/recognize.test.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable */ + 'use strict'; const path = require(`path`); diff --git a/samples/system-test/recognize.v1p1beta1.test.js b/samples/system-test/recognize.v1p1beta1.test.js index b52cec5f..73a2ab2e 100644 --- a/samples/system-test/recognize.v1p1beta1.test.js +++ b/samples/system-test/recognize.v1p1beta1.test.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/* eslint-disable */ + 'use strict'; const path = require(`path`);