@@ -19,12 +19,13 @@ const path = require('path');
19
19
const { Storage} = require ( '@google-cloud/storage' ) ;
20
20
const { assert} = require ( 'chai' ) ;
21
21
const uuid = require ( 'uuid' ) ;
22
- const execa = require ( 'execa' ) ;
22
+ const cp = require ( 'child_process' ) ;
23
+
24
+ const execSync = cmd => cp . execSync ( cmd , { encoding : 'utf-8' } ) ;
23
25
24
26
const storage = new Storage ( ) ;
25
27
const bucketName = `nodejs-docs-samples-test-${ uuid . v4 ( ) } ` ;
26
28
const cmd = 'node recognize.js' ;
27
- const cwd = path . join ( __dirname , '..' ) ;
28
29
const resourcePath = path . join ( __dirname , '..' , 'resources' ) ;
29
30
const filename = `audio.raw` ;
30
31
const filename1 = `Google_Gnome.wav` ;
@@ -38,7 +39,6 @@ const text = 'how old is the Brooklyn Bridge';
38
39
const text1 = 'the weather outside is sunny' ;
39
40
const text2 = `Terrific. It's on the way.` ;
40
41
const text3 = 'Chrome' ;
41
- const exec = async cmd => ( await execa . shell ( cmd , { cwd} ) ) . stdout ;
42
42
43
43
describe ( 'Recognize' , ( ) => {
44
44
before ( async ( ) => {
@@ -56,35 +56,33 @@ describe('Recognize', () => {
56
56
} ) ;
57
57
58
58
it ( 'should run sync recognize' , async ( ) => {
59
- const output = await exec ( `${ cmd } sync ${ filepath } ` ) ;
59
+ const output = execSync ( `${ cmd } sync ${ filepath } ` ) ;
60
60
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
61
61
} ) ;
62
62
63
63
it ( 'should run sync recognize on a GCS file' , async ( ) => {
64
- const output = await exec ( `${ cmd } sync-gcs gs://${ bucketName } /${ filename } ` ) ;
64
+ const output = execSync ( `${ cmd } sync-gcs gs://${ bucketName } /${ filename } ` ) ;
65
65
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
66
66
} ) ;
67
67
68
68
it ( 'should run sync recognize with word time offset' , async ( ) => {
69
- const output = await exec ( `${ cmd } sync-words ${ filepath } ` ) ;
69
+ const output = execSync ( `${ cmd } sync-words ${ filepath } ` ) ;
70
70
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
71
71
assert . match ( output , new RegExp ( '\\d+\\.\\d+ secs - \\d+\\.\\d+ secs' ) ) ;
72
72
} ) ;
73
73
74
74
it ( 'should run async recognize on a local file' , async ( ) => {
75
- const output = await exec ( `${ cmd } async ${ filepath } ` ) ;
75
+ const output = execSync ( `${ cmd } async ${ filepath } ` ) ;
76
76
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
77
77
} ) ;
78
78
79
79
it ( 'should run async recognize on a GCS file' , async ( ) => {
80
- const output = await exec (
81
- `${ cmd } async-gcs gs://${ bucketName } /${ filename } `
82
- ) ;
80
+ const output = execSync ( `${ cmd } async-gcs gs://${ bucketName } /${ filename } ` ) ;
83
81
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
84
82
} ) ;
85
83
86
84
it ( 'should run async recognize on a GCS file with word time offset' , async ( ) => {
87
- const output = await exec (
85
+ const output = execSync (
88
86
`${ cmd } async-gcs-words gs://${ bucketName } /${ filename } `
89
87
) ;
90
88
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
@@ -93,43 +91,43 @@ describe('Recognize', () => {
93
91
} ) ;
94
92
95
93
it ( 'should run streaming recognize' , async ( ) => {
96
- const output = await exec ( `${ cmd } stream ${ filepath } ` ) ;
94
+ const output = execSync ( `${ cmd } stream ${ filepath } ` ) ;
97
95
assert . match ( output , new RegExp ( `Transcription: ${ text } ` ) ) ;
98
96
} ) ;
99
97
100
98
it ( 'should run sync recognize with model selection' , async ( ) => {
101
99
const model = 'video' ;
102
- const output = await exec ( `${ cmd } sync-model ${ filepath1 } ${ model } ` ) ;
100
+ const output = execSync ( `${ cmd } sync-model ${ filepath1 } ${ model } ` ) ;
103
101
assert . match ( output , / T r a n s c r i p t i o n : / ) ;
104
102
assert . match ( output , new RegExp ( text1 ) ) ;
105
103
} ) ;
106
104
107
105
it ( 'should run sync recognize on a GCS file with model selection' , async ( ) => {
108
106
const model = 'video' ;
109
- const output = await exec (
107
+ const output = execSync (
110
108
`${ cmd } sync-model-gcs gs://${ bucketName } /${ filename1 } ${ model } `
111
109
) ;
112
110
assert . match ( output , / T r a n s c r i p t i o n : / ) ;
113
111
assert . match ( output , new RegExp ( text1 ) ) ;
114
112
} ) ;
115
113
116
114
it ( 'should run sync recognize with auto punctuation' , async ( ) => {
117
- const output = await exec ( `${ cmd } sync-auto-punctuation ${ filepath2 } ` ) ;
115
+ const output = execSync ( `${ cmd } sync-auto-punctuation ${ filepath2 } ` ) ;
118
116
assert . match ( output , new RegExp ( text2 ) ) ;
119
117
} ) ;
120
118
121
119
it ( 'should run sync recognize with enhanced model' , async ( ) => {
122
- const output = await exec ( `${ cmd } sync-enhanced-model ${ filepath2 } ` ) ;
120
+ const output = execSync ( `${ cmd } sync-enhanced-model ${ filepath2 } ` ) ;
123
121
assert . match ( output , new RegExp ( text3 ) ) ;
124
122
} ) ;
125
123
126
124
it ( 'should run multi channel transcription on a local file' , async ( ) => {
127
- const output = await exec ( `${ cmd } sync-multi-channel ${ filepath3 } ` ) ;
125
+ const output = execSync ( `${ cmd } sync-multi-channel ${ filepath3 } ` ) ;
128
126
assert . match ( output , / C h a n n e l T a g : 2 / ) ;
129
127
} ) ;
130
128
131
129
it ( 'should run multi channel transcription on GCS file' , async ( ) => {
132
- const output = await exec (
130
+ const output = execSync (
133
131
`${ cmd } sync-multi-channel-gcs gs://${ bucketName } /${ filename3 } `
134
132
) ;
135
133
assert . match ( output , / C h a n n e l T a g : 2 / ) ;
0 commit comments