title: Loop of function for taking multiple audio files from a directory
body: <p>I am currently taking input from a directory, for a single audio file and I am saving my output in CSV file, with the file name and converted speech to text output but I have 100 files in that directory (i.e 001.wav,002.wav,003.wav..........100.wav)</p>
  
  <p>I want to write a loop or function which saves the speech to text output in CSV automatically with the respective file name in different rows.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>import speech_recognition as sr
  import csv
  import os
  AUDIO_FILE =path.join(path.dirname('C:/path/to/directory'), "001.wav")
  file_name = os.path.basename(AUDIO_FILE)
  name = os.path.basename(AUDIO_FILE)
  
  # use the audio file as the audio source
  r = sr.Recognizer()
  with sr.AudioFile(AUDIO_FILE) as source:
  audio = r.record(source)  # read the entire audio file
  
  # recognize speech using Google Speech Recognition
  try:
      # for testing purposes, we're just using the default API key
      # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
      # instead of `r.recognize_google(audio)`
      a =  r.recognize_google(audio)        
  except sr.UnknownValueError:
      a = "Google Speech Recognition could not understand audio"
  except sr.RequestError as e:
      a = "Could not request results from Google Speech Recognition service; {0}".format(e)
  
  try:
      b = r.recognize_sphinx(audio)
  except sr.UnknownValueError:
      b = "Sphinx could not understand audio"
  except sr.RequestError as e:
      b = "Sphinx error; {0}".format(e)
  
  with open('speech_output.csv', 'a') as f:
  writer = csv.writer(f)
  writer.writerow(['file_name','google',sphinx])
  writer.writerow([file_name,a,b])
  </code></pre>
  
  <p>References to the code.
  <a href="https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py" rel="nofollow">https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py</a></p>