class_docstr: Creates a new ``AudioData`` instance, which represents mono audio data.
  
  The raw audio data is specified by ``frame_data``, which is a sequence of bytes representing audio samples. This is the frame data structure used by the PCM WAV format.
  
  The width of each sample, in bytes, is specified by ``sample_width``. Each group of ``sample_width`` bytes represents a single audio sample.
  
  The audio data is assumed to have a sample rate of ``sample_rate`` samples per second (Hertz).
  
  Usually, instances of this class are obtained from ``recognizer_instance.record`` or ``recognizer_instance.listen``, or in the callback for ``recognizer_instance.listen_in_background``, rather than instantiating them directly.
class_docstr_tok: ["Creates","a","new","``","AudioData","``","instance",",","which","represents","mono","audio","data",".","The","raw","audio","data","is","specified","by","``","frame_data","``",",","which","is","a","sequence","of","bytes","representing","audio","samples",".","This","is","the","frame","data","structure","used","by","the","PCM","WAV","format",".","The","width","of","each","sample",",","in","bytes",",","is","specified","by","``","sample_width","``",".","Each","group","of","``","sample_width","``","bytes","represents","a","single","audio","sample",".","The","audio","data","is","assumed","to","have","a","sample","rate","of","``","sample_rate","``","samples","per","second","(","Hertz",")",".","Usually",",","instances","of","this","class","are","obtained","from","``","recognizer_instance.record","``","or","``","recognizer_instance.listen","``",",","or","in","the","callback","for","``","recognizer_instance.listen_in_background","``",",","rather","than","instantiating","them","directly","."]
docstr: Returns a byte string representing the contents of a WAV file containing the audio represented by the ``AudioData`` instance.
  
  If ``convert_width`` is specified and the audio samples are not ``convert_width`` bytes each, the resulting audio is converted to match.
  
  If ``convert_rate`` is specified and the audio sample rate is not ``convert_rate`` Hz, the resulting audio is resampled to match.
  
  Writing these bytes directly to a file results in a valid `WAV file <https://en.wikipedia.org/wiki/WAV>`__.
docstr_tok: ["Returns","a","byte","string","representing","the","contents","of","a","WAV","file","containing","the","audio","represented","by","the","``","AudioData","``","instance",".","If","``","convert_width","``","is","specified","and","the","audio","samples","are","not","``","convert_width","``","bytes","each",",","the","resulting","audio","is","converted","to","match",".","If","``","convert_rate","``","is","specified","and","the","audio","sample","rate","is","not","``","convert_rate","``","Hz",",","the","resulting","audio","is","resampled","to","match",".","Writing","these","bytes","directly","to","a","file","results","in","a","valid","`","WAV","file","<","https",":","\/\/en.wikipedia.org\/wiki\/WAV",">","`","__","."]
code: def get_wav_data(self, convert_rate=None, convert_width=None):
      """
      Returns a byte string representing the contents of a WAV file containing the audio represented by the ``AudioData`` instance.
  
      If ``convert_width`` is specified and the audio samples are not ``convert_width`` bytes each, the resulting audio is converted to match.
  
      If ``convert_rate`` is specified and the audio sample rate is not ``convert_rate`` Hz, the resulting audio is resampled to match.
  
      Writing these bytes directly to a file results in a valid `WAV file <https://en.wikipedia.org/wiki/WAV>`__.
      """
      raw_data = self.get_raw_data(convert_rate, convert_width)
      sample_rate = (
          self.sample_rate if convert_rate is None else convert_rate
      )
      sample_width = (
          self.sample_width if convert_width is None else convert_width
      )
  
      # generate the WAV file contents
      with io.BytesIO() as wav_file:
          wav_writer = wave.open(wav_file, "wb")
          try:  # note that we can't use context manager, since that was only added in Python 3.4
              wav_writer.setframerate(sample_rate)
              wav_writer.setsampwidth(sample_width)
              wav_writer.setnchannels(1)
              wav_writer.writeframes(raw_data)
              wav_data = wav_file.getvalue()
          finally:  # make sure resources are cleaned up
              wav_writer.close()
      return wav_data
  
file_path: speech_recognition/speech_recognition/audio.py
imports: import aifc
  import audioop
  import io
  import os
  import platform
  import stat
  import subprocess
  import sys
  import wave
label_desc: Use image node_id 4 for calling the AudioData obj's underlying member method code with example usage: obj.get_wav_data(convert_rate, convert_width) and returns: wav_data