title: How to fix "request contains an invalid argument error" when transcribing audio file with Google Cloud Speech
body: <p>We are able to create unique buckets on each run of the program, however, it hits a road-block around the time it reaches the <code>transcribe_gcs</code> function. We want the program to transcribe the audio file that gets uploaded to the bucket. But the transcribe process isn't quite functioning. </p>
  
  <p>We changed the directory for the gcs_uri to be "gs://". This allows unique buckets to be created each time. </p>
  
  <pre><code>def transcribe_gcs(gcs_uri):
      """Asynchronously transcribes the audio file specified by the gcs_uri."""
      #from google.cloud import speech
      from google.cloud.speech import enums
      from google.cloud.speech import types
      from google.cloud.speech_v1p1beta1 import enums
      from google.cloud.speech_v1p1beta1 import types
      audio = types.RecognitionAudio(uri=gcs_uri)
      config = types.RecognitionConfig(
          encoding='LINEAR16',
          sample_rate_hertz=44100,
          language_code='en-US',
          enable_speaker_diarization=True,
          diarization_speaker_count=2)
  
      client = speech.SpeechClient()
  
      ##response = client.recognize(config, audio)
  
      operation = client.long_running_recognize(config, audio)
      print('Waiting for operation to complete...')
      response = operation.result(timeout=3000)
      result = response.results[-1]
  
      words_info = result.alternatives[0].words
  
      tag = 1
      speaker = ""
  
      for word_info in words_info:
          if word_info.speaker_tag == tag:
              speaker = speaker + " " + word_info.word     #need to adjust how speakers are actually separated
  
          else:
              print("Speaker {}: {}".format(tag, speaker)) #get program to print entire transcript through here
              tag = word_info.speaker_tag
              speaker = "" + word_info.word                #make sentiment analysis work on each individual line
  
  
      # Each result is for a consecutive portion of the audio. Iterate through
      # them to get the transcripts for the entire audio file.
      for result in response.results:
          # The first alternative is the most likely one for this portion.
          print(u'Transcript: {}'.format(result.alternatives[0].transcript)) #this should be removed eventually but should be used somehow to modify the speaker portion
  
          transcribedSpeechFile = open('speechToAnalyze.txt', 'a+')  # this is where a text file is made with the transcribed speech
  
          transcribedSpeechFile.write(format(result.alternatives[0].transcript))
  
          transcribedSpeechFile.close()
  
          confidencePercentage = result.alternatives[0].confidence
          confidencePercentage = confidencePercentage * 100
  
          print("Confidence level of transcription: {}%".format(round(confidencePercentage, 2)))
  # [END speech_transcribe_async_gcs]
  
  
  if __name__ == '__main__':
      transcribe_gcs(gcs_uri)
  </code></pre>
  
  <p>Expected results: transcribes the audio file uploaded to the unique bucket</p>
  
  <p>Actual results: creates a bucket, but does not go further than that.</p>
  
  <p>ERROR: </p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\grpc_helpers.py", line 57, in error_remapped_callable
      return callable_(*args, **kwargs)
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\grpc\_channel.py", line 565, in __call__
      return _end_unary_response_blocking(state, call, False, None)
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\grpc\_channel.py", line 467, in _end_unary_response_blocking
      raise _Rendezvous(state, None, None, deadline)
  grpc._channel._Rendezvous: &lt;_Rendezvous of RPC that terminated with:
      status = StatusCode.INVALID_ARGUMENT
      details = "Request contains an invalid argument."
      debug_error_string = "{"created":"@1564207941.288000000","description":"Error received from peer ipv6:[2607:f8b0:4000:80e::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1052,"grpc_message":"Request contains an invalid argument.","grpc_status":3}"
  &gt;
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File "C:/Users/Dave/Desktop/mizu/test.py", line 120, in &lt;module&gt;
      transcribe_gcs(gcs_uri)
    File "C:/Users/Dave/Desktop/mizu/test.py", line 80, in transcribe_gcs
      operation = client.long_running_recognize(config, audio)
    File "C:\Users\Dave\AppData\Local\Programs\Python\Python37\lib\site-packages\google\cloud\speech_v1p1beta1\gapic\speech_client.py", line 326, in long_running_recognize
      request, retry=retry, timeout=timeout, metadata=metadata
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\gapic_v1\method.py", line 143, in __call__
      return wrapped_func(*args, **kwargs)
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\retry.py", line 273, in retry_wrapped_func
      on_error=on_error,
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\retry.py", line 182, in retry_target
      return target()
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\timeout.py", line 214, in func_with_timeout
      return func(*args, **kwargs)
    File "C:\Users\Dave\AppData\Roaming\Python\Python37\site-packages\google\api_core\grpc_helpers.py", line 59, in error_remapped_callable
      six.raise_from(exceptions.from_grpc_error(exc), exc)
    File "&lt;string&gt;", line 3, in raise_from
  google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument
  </code></pre>