title: How can I conver a transcribed .wav into txt in full extent. - Google Speech API
body: <p>I'm having trouble with converting full transcribed speech to a text file. Eventually, I get what I need but not the entire text from the audio file. Let me note this (1 Pic),<a href="https://i.stack.imgur.com/u4AfD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u4AfD.png" alt="enter image description here" /></a> I can see the whole text when I use print() function but get only one line of that text when I try to write it to .txt file (2 Pic).<a href="https://i.stack.imgur.com/7nJyx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7nJyx.png" alt="enter image description here" /></a></p>
  <p>Also, you can look at my code if you need additional info and stuff. Thank you in advance!</p>
  <pre><code>from google.cloud import speech
  import os
  
  
  
  os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'PATH'
  
     
  
  client = speech.SpeechClient()
  
  
  with open('sample.wav', &quot;rb&quot;) as audio_file:
      content = audio_file.read()
  
  audio = speech.RecognitionAudio(content=content)
  config = speech.RecognitionConfig(
      encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
      sample_rate_hertz=8000,
      language_code=&quot;en-US&quot;,
      # Enable automatic punctuation
      enable_automatic_punctuation=True,
  )
  
  response = client.recognize(config=config, audio=audio)
  
  for result in response.results:
      extr = result.alternatives[0].transcript
      print(extr)
      with open(&quot;guru9.txt&quot;,&quot;w+&quot;) as f:
          f.write(extr)
          f.close()
  </code></pre>