@@ -355,6 +355,59 @@ function analyzeSafeSearch(gcsUri) {
355355 // [END analyze_safe_search]
356356}
357357
358+ function analyzeVideoTranscription ( gcsUri ) {
359+ // [START video_speech_transcription]
360+ // Imports the Google Cloud Video Intelligence library
361+ const videoIntelligence = require ( '@google-cloud/video-intelligence' )
362+ . v1p1beta1 ;
363+
364+ // Creates a client
365+ const client = new videoIntelligence . VideoIntelligenceServiceClient ( ) ;
366+
367+ /**
368+ * TODO(developer): Uncomment the following line before running the sample.
369+ */
370+ // const gcsUri = 'GCS URI of video to analyze, e.g. gs://my-bucket/my-video.mp4';
371+
372+ const videoContext = {
373+ speechTranscriptionConfig : {
374+ languageCode : 'en-US' ,
375+ } ,
376+ } ;
377+
378+ const request = {
379+ inputUri : gcsUri ,
380+ features : [ 'SPEECH_TRANSCRIPTION' ] ,
381+ videoContext : videoContext ,
382+ } ;
383+
384+ client
385+ . annotateVideo ( request )
386+ . then ( results => {
387+ const operation = results [ 0 ] ;
388+ console . log ( 'Waiting for operation to complete...' ) ;
389+ return operation . promise ( ) ;
390+ } )
391+ . then ( results => {
392+ console . log ( 'Word level information:' ) ;
393+ const alternative =
394+ results [ 0 ] . annotationResults [ 0 ] . speechTranscriptions [ 0 ] . alternatives [ 0 ] ;
395+ alternative . words . forEach ( wordInfo => {
396+ let start_time =
397+ wordInfo . startTime . seconds + wordInfo . startTime . nanos * 1e-9 ;
398+ let end_time = wordInfo . endTime . seconds + wordInfo . endTime . nanos * 1e-9 ;
399+ console . log (
400+ '\t' + start_time + 's - ' + end_time + 's: ' + wordInfo . word
401+ ) ;
402+ } ) ;
403+ console . log ( 'Transcription: ' + alternative . transcript ) ;
404+ } )
405+ . catch ( err => {
406+ console . error ( 'ERROR:' , err ) ;
407+ } ) ;
408+ // [END video_speech_transcription]
409+ }
410+
358411require ( `yargs` )
359412 . demand ( 1 )
360413 . command (
@@ -387,11 +440,18 @@ require(`yargs`)
387440 { } ,
388441 opts => analyzeSafeSearch ( opts . gcsUri )
389442 )
443+ . command (
444+ `transcription <gcsUri>` ,
445+ `Extract the video transcription using the Cloud Video Intelligence API.` ,
446+ { } ,
447+ opts => analyzeVideoTranscription ( opts . gcsUri )
448+ )
390449 . example ( `node $0 faces gs://demomaker/larry_sergey_ice_bucket_short.mp4` )
391450 . example ( `node $0 shots gs://demomaker/sushi.mp4` )
392451 . example ( `node $0 labels-gcs gs://demomaker/tomatoes.mp4` )
393452 . example ( `node $0 labels-file cat.mp4` )
394453 . example ( `node $0 safe-search gs://demomaker/tomatoes.mp4` )
454+ . example ( `node $0 transcription gs://demomaker/tomatoes.mp4` )
395455 . wrap ( 120 )
396456 . recommendCommands ( )
397457 . epilogue (
0 commit comments