title: Google Speech To Text API: Extracting audio from mp4
body: <p>I am trying to extract text from video (mp4) file saved in AWS S3 using Python. I am able to make it working using audio file, but not with an MP4. Is it possible to use MP4 directly or should I extract the audio using ffmpeg or something similar.</p>
  
  <p>I am referring to the following link: <a href="https://cloud.google.com/speech-to-text/docs/video-model#speech-select-model-python" rel="nofollow noreferrer">Google Video Transcribing</a></p>
  
  <pre><code>def transcribe_model_selection(speech_file, model):
  """Transcribe the given audio file synchronously with
  the selected model."""
  from google.cloud import speech
  client = speech.SpeechClient()
  
  with open(speech_file, 'rb') as audio_file:
      content = audio_file.read()
  
  audio = speech.types.RecognitionAudio(content=content)
  
  config = speech.types.RecognitionConfig(
      encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
      sample_rate_hertz=16000,
      language_code='en-US',
      model=model)
  
  response = client.recognize(config, audio)
  
  for i, result in enumerate(response.results):
      alternative = result.alternatives[0]
      print('-' * 20)
      print('First alternative of result {}'.format(i))
      print(u'Transcript: {}'.format(alternative.transcript))
  </code></pre>