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 new ``AudioData`` instance, trimmed to a given time interval. In other words, an ``AudioData`` instance with the same audio data except starting at ``start_ms`` milliseconds in and ending ``end_ms`` milliseconds in.
  
  If not specified, ``start_ms`` defaults to the beginning of the audio, and ``end_ms`` defaults to the end.
docstr_tok: ["Returns","a","new","``","AudioData","``","instance",",","trimmed","to","a","given","time","interval",".","In","other","words",",","an","``","AudioData","``","instance","with","the","same","audio","data","except","starting","at","``","start_ms","``","milliseconds","in","and","ending","``","end_ms","``","milliseconds","in",".","If","not","specified",",","``","start_ms","``","defaults","to","the","beginning","of","the","audio",",","and","``","end_ms","``","defaults","to","the","end","."]
code: def get_segment(self, start_ms=None, end_ms=None):
      """
      Returns a new ``AudioData`` instance, trimmed to a given time interval. In other words, an ``AudioData`` instance with the same audio data except starting at ``start_ms`` milliseconds in and ending ``end_ms`` milliseconds in.
  
      If not specified, ``start_ms`` defaults to the beginning of the audio, and ``end_ms`` defaults to the end.
      """
      assert (
          start_ms is None or start_ms >= 0
      ), "``start_ms`` must be a non-negative number"
      assert end_ms is None or end_ms >= (
          0 if start_ms is None else start_ms
      ), "``end_ms`` must be a non-negative number greater or equal to ``start_ms``"
      if start_ms is None:
          start_byte = 0
      else:
          start_byte = int(
              (start_ms * self.sample_rate * self.sample_width) // 1000
          )
      if end_ms is None:
          end_byte = len(self.frame_data)
      else:
          end_byte = int(
              (end_ms * self.sample_rate * self.sample_width) // 1000
          )
      return AudioData(
          self.frame_data[start_byte:end_byte],
          self.sample_rate,
          self.sample_width,
      )
  
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 2 for calling the AudioData obj's underlying member method code with example usage: obj.get_segment(start_ms, end_ms) and returns: AudioData