Google Cloud Platform: Speech to Text Conversion of Large Media Files












-1














I'm trying to extract text from mp4 media file downloaded from youtube. As I'm using google cloud platform so thought to give a try to google cloud speech.



After all the installations and configurations, I copied the following code snippet to get start with:



with io.open(file_name, 'rb') as audio_file:
content = audio_file.read()
audio = types.RecognitionAudio(content=content)

config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US')

response = client.long_running_recognize(config, audio)


But I got the following error regarding file size:




InvalidArgument: 400 Inline audio exceeds duration limit. Please use a
GCS URI.




Then I read that I should use streams for large media files. So, I tried the following code snippet:



with io.open(file_name, 'rb') as audio_file:
content = audio_file.read()

#In practice, stream should be a generator yielding chunks of audio data.

stream = [content]
requests = (types.StreamingRecognizeRequest(audio_content=chunk)for chunk in stream)

config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-US')

streaming_config = types.StreamingRecognitionConfig(config=config)

responses = client.streaming_recognize(streaming_config, requests)


But still I got the following error:




InvalidArgument: 400 Invalid audio content: too long.




So, can anyone please suggest an approach to transcribe an mp4 file and extract text. I don't have any complex requirement of very large media file. Media file can be 10-15 mins long maximum. Thanks










share|improve this question



























    -1














    I'm trying to extract text from mp4 media file downloaded from youtube. As I'm using google cloud platform so thought to give a try to google cloud speech.



    After all the installations and configurations, I copied the following code snippet to get start with:



    with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()
    audio = types.RecognitionAudio(content=content)

    config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US')

    response = client.long_running_recognize(config, audio)


    But I got the following error regarding file size:




    InvalidArgument: 400 Inline audio exceeds duration limit. Please use a
    GCS URI.




    Then I read that I should use streams for large media files. So, I tried the following code snippet:



    with io.open(file_name, 'rb') as audio_file:
    content = audio_file.read()

    #In practice, stream should be a generator yielding chunks of audio data.

    stream = [content]
    requests = (types.StreamingRecognizeRequest(audio_content=chunk)for chunk in stream)

    config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-US')

    streaming_config = types.StreamingRecognitionConfig(config=config)

    responses = client.streaming_recognize(streaming_config, requests)


    But still I got the following error:




    InvalidArgument: 400 Invalid audio content: too long.




    So, can anyone please suggest an approach to transcribe an mp4 file and extract text. I don't have any complex requirement of very large media file. Media file can be 10-15 mins long maximum. Thanks










    share|improve this question

























      -1












      -1








      -1


      1





      I'm trying to extract text from mp4 media file downloaded from youtube. As I'm using google cloud platform so thought to give a try to google cloud speech.



      After all the installations and configurations, I copied the following code snippet to get start with:



      with io.open(file_name, 'rb') as audio_file:
      content = audio_file.read()
      audio = types.RecognitionAudio(content=content)

      config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US')

      response = client.long_running_recognize(config, audio)


      But I got the following error regarding file size:




      InvalidArgument: 400 Inline audio exceeds duration limit. Please use a
      GCS URI.




      Then I read that I should use streams for large media files. So, I tried the following code snippet:



      with io.open(file_name, 'rb') as audio_file:
      content = audio_file.read()

      #In practice, stream should be a generator yielding chunks of audio data.

      stream = [content]
      requests = (types.StreamingRecognizeRequest(audio_content=chunk)for chunk in stream)

      config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-US')

      streaming_config = types.StreamingRecognitionConfig(config=config)

      responses = client.streaming_recognize(streaming_config, requests)


      But still I got the following error:




      InvalidArgument: 400 Invalid audio content: too long.




      So, can anyone please suggest an approach to transcribe an mp4 file and extract text. I don't have any complex requirement of very large media file. Media file can be 10-15 mins long maximum. Thanks










      share|improve this question













      I'm trying to extract text from mp4 media file downloaded from youtube. As I'm using google cloud platform so thought to give a try to google cloud speech.



      After all the installations and configurations, I copied the following code snippet to get start with:



      with io.open(file_name, 'rb') as audio_file:
      content = audio_file.read()
      audio = types.RecognitionAudio(content=content)

      config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16, sample_rate_hertz=16000, language_code='en-US')

      response = client.long_running_recognize(config, audio)


      But I got the following error regarding file size:




      InvalidArgument: 400 Inline audio exceeds duration limit. Please use a
      GCS URI.




      Then I read that I should use streams for large media files. So, I tried the following code snippet:



      with io.open(file_name, 'rb') as audio_file:
      content = audio_file.read()

      #In practice, stream should be a generator yielding chunks of audio data.

      stream = [content]
      requests = (types.StreamingRecognizeRequest(audio_content=chunk)for chunk in stream)

      config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-US')

      streaming_config = types.StreamingRecognitionConfig(config=config)

      responses = client.streaming_recognize(streaming_config, requests)


      But still I got the following error:




      InvalidArgument: 400 Invalid audio content: too long.




      So, can anyone please suggest an approach to transcribe an mp4 file and extract text. I don't have any complex requirement of very large media file. Media file can be 10-15 mins long maximum. Thanks







      google-cloud-platform speech-recognition speech-to-text google-speech-api google-cloud-speech






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 19:43









      Bilal Ahmed Yaseen

      5931423




      5931423
























          1 Answer
          1






          active

          oldest

          votes


















          1














          The error message means that the file is too big and you need to first copy the media file to Google Cloud Storage and then specify a Cloud Storage URI such as gs://bucket/path/mediafile.



          The key to using a Cloud Storage URI is:




          RecognitionAudio audio =
          RecognitionAudio.newBuilder().setUri(gcsUri).build();




          The following code will show you how to specify a GCS URI for input. Google has a complete example on github.



            public static void syncRecognizeGcs(String gcsUri) throws Exception {
          // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS
          try (SpeechClient speech = SpeechClient.create()) {
          // Builds the request for remote FLAC file
          RecognitionConfig config =
          RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.FLAC)
          .setLanguageCode("en-US")
          .setSampleRateHertz(16000)
          .build();
          RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();

          // Use blocking call for getting audio transcript
          RecognizeResponse response = speech.recognize(config, audio);
          List<SpeechRecognitionResult> results = response.getResultsList();

          for (SpeechRecognitionResult result : results) {
          // There can be several alternative transcripts for a given chunk of speech. Just use the
          // first (most likely) one here.
          SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
          System.out.printf("Transcription: %s%n", alternative.getTranscript());
          }
          }
          }





          share|improve this answer























          • Can you please share an example or sample code snipet?
            – Bilal Ahmed Yaseen
            Nov 15 '18 at 19:47










          • Updated my answer to include code and a reference link. This is the code that I used to get started.
            – John Hanley
            Nov 15 '18 at 20:17










          • I'm working in python, but got an idea and will give it a try!
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:49










          • please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:51











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307696%2fgoogle-cloud-platform-speech-to-text-conversion-of-large-media-files%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The error message means that the file is too big and you need to first copy the media file to Google Cloud Storage and then specify a Cloud Storage URI such as gs://bucket/path/mediafile.



          The key to using a Cloud Storage URI is:




          RecognitionAudio audio =
          RecognitionAudio.newBuilder().setUri(gcsUri).build();




          The following code will show you how to specify a GCS URI for input. Google has a complete example on github.



            public static void syncRecognizeGcs(String gcsUri) throws Exception {
          // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS
          try (SpeechClient speech = SpeechClient.create()) {
          // Builds the request for remote FLAC file
          RecognitionConfig config =
          RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.FLAC)
          .setLanguageCode("en-US")
          .setSampleRateHertz(16000)
          .build();
          RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();

          // Use blocking call for getting audio transcript
          RecognizeResponse response = speech.recognize(config, audio);
          List<SpeechRecognitionResult> results = response.getResultsList();

          for (SpeechRecognitionResult result : results) {
          // There can be several alternative transcripts for a given chunk of speech. Just use the
          // first (most likely) one here.
          SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
          System.out.printf("Transcription: %s%n", alternative.getTranscript());
          }
          }
          }





          share|improve this answer























          • Can you please share an example or sample code snipet?
            – Bilal Ahmed Yaseen
            Nov 15 '18 at 19:47










          • Updated my answer to include code and a reference link. This is the code that I used to get started.
            – John Hanley
            Nov 15 '18 at 20:17










          • I'm working in python, but got an idea and will give it a try!
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:49










          • please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:51
















          1














          The error message means that the file is too big and you need to first copy the media file to Google Cloud Storage and then specify a Cloud Storage URI such as gs://bucket/path/mediafile.



          The key to using a Cloud Storage URI is:




          RecognitionAudio audio =
          RecognitionAudio.newBuilder().setUri(gcsUri).build();




          The following code will show you how to specify a GCS URI for input. Google has a complete example on github.



            public static void syncRecognizeGcs(String gcsUri) throws Exception {
          // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS
          try (SpeechClient speech = SpeechClient.create()) {
          // Builds the request for remote FLAC file
          RecognitionConfig config =
          RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.FLAC)
          .setLanguageCode("en-US")
          .setSampleRateHertz(16000)
          .build();
          RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();

          // Use blocking call for getting audio transcript
          RecognizeResponse response = speech.recognize(config, audio);
          List<SpeechRecognitionResult> results = response.getResultsList();

          for (SpeechRecognitionResult result : results) {
          // There can be several alternative transcripts for a given chunk of speech. Just use the
          // first (most likely) one here.
          SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
          System.out.printf("Transcription: %s%n", alternative.getTranscript());
          }
          }
          }





          share|improve this answer























          • Can you please share an example or sample code snipet?
            – Bilal Ahmed Yaseen
            Nov 15 '18 at 19:47










          • Updated my answer to include code and a reference link. This is the code that I used to get started.
            – John Hanley
            Nov 15 '18 at 20:17










          • I'm working in python, but got an idea and will give it a try!
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:49










          • please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:51














          1












          1








          1






          The error message means that the file is too big and you need to first copy the media file to Google Cloud Storage and then specify a Cloud Storage URI such as gs://bucket/path/mediafile.



          The key to using a Cloud Storage URI is:




          RecognitionAudio audio =
          RecognitionAudio.newBuilder().setUri(gcsUri).build();




          The following code will show you how to specify a GCS URI for input. Google has a complete example on github.



            public static void syncRecognizeGcs(String gcsUri) throws Exception {
          // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS
          try (SpeechClient speech = SpeechClient.create()) {
          // Builds the request for remote FLAC file
          RecognitionConfig config =
          RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.FLAC)
          .setLanguageCode("en-US")
          .setSampleRateHertz(16000)
          .build();
          RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();

          // Use blocking call for getting audio transcript
          RecognizeResponse response = speech.recognize(config, audio);
          List<SpeechRecognitionResult> results = response.getResultsList();

          for (SpeechRecognitionResult result : results) {
          // There can be several alternative transcripts for a given chunk of speech. Just use the
          // first (most likely) one here.
          SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
          System.out.printf("Transcription: %s%n", alternative.getTranscript());
          }
          }
          }





          share|improve this answer














          The error message means that the file is too big and you need to first copy the media file to Google Cloud Storage and then specify a Cloud Storage URI such as gs://bucket/path/mediafile.



          The key to using a Cloud Storage URI is:




          RecognitionAudio audio =
          RecognitionAudio.newBuilder().setUri(gcsUri).build();




          The following code will show you how to specify a GCS URI for input. Google has a complete example on github.



            public static void syncRecognizeGcs(String gcsUri) throws Exception {
          // Instantiates a client with GOOGLE_APPLICATION_CREDENTIALS
          try (SpeechClient speech = SpeechClient.create()) {
          // Builds the request for remote FLAC file
          RecognitionConfig config =
          RecognitionConfig.newBuilder()
          .setEncoding(AudioEncoding.FLAC)
          .setLanguageCode("en-US")
          .setSampleRateHertz(16000)
          .build();
          RecognitionAudio audio = RecognitionAudio.newBuilder().setUri(gcsUri).build();

          // Use blocking call for getting audio transcript
          RecognizeResponse response = speech.recognize(config, audio);
          List<SpeechRecognitionResult> results = response.getResultsList();

          for (SpeechRecognitionResult result : results) {
          // There can be several alternative transcripts for a given chunk of speech. Just use the
          // first (most likely) one here.
          SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0);
          System.out.printf("Transcription: %s%n", alternative.getTranscript());
          }
          }
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 20:16

























          answered Nov 14 '18 at 23:21









          John Hanley

          14k2528




          14k2528












          • Can you please share an example or sample code snipet?
            – Bilal Ahmed Yaseen
            Nov 15 '18 at 19:47










          • Updated my answer to include code and a reference link. This is the code that I used to get started.
            – John Hanley
            Nov 15 '18 at 20:17










          • I'm working in python, but got an idea and will give it a try!
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:49










          • please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:51


















          • Can you please share an example or sample code snipet?
            – Bilal Ahmed Yaseen
            Nov 15 '18 at 19:47










          • Updated my answer to include code and a reference link. This is the code that I used to get started.
            – John Hanley
            Nov 15 '18 at 20:17










          • I'm working in python, but got an idea and will give it a try!
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:49










          • please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
            – Bilal Ahmed Yaseen
            Nov 16 '18 at 6:51
















          Can you please share an example or sample code snipet?
          – Bilal Ahmed Yaseen
          Nov 15 '18 at 19:47




          Can you please share an example or sample code snipet?
          – Bilal Ahmed Yaseen
          Nov 15 '18 at 19:47












          Updated my answer to include code and a reference link. This is the code that I used to get started.
          – John Hanley
          Nov 15 '18 at 20:17




          Updated my answer to include code and a reference link. This is the code that I used to get started.
          – John Hanley
          Nov 15 '18 at 20:17












          I'm working in python, but got an idea and will give it a try!
          – Bilal Ahmed Yaseen
          Nov 16 '18 at 6:49




          I'm working in python, but got an idea and will give it a try!
          – Bilal Ahmed Yaseen
          Nov 16 '18 at 6:49












          please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
          – Bilal Ahmed Yaseen
          Nov 16 '18 at 6:51




          please share if you have any example implemented in python. I'm following the one given on official website but struggling with reading video file placed on google storage.
          – Bilal Ahmed Yaseen
          Nov 16 '18 at 6:51


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307696%2fgoogle-cloud-platform-speech-to-text-conversion-of-large-media-files%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)