class_docstr: Transcriber: speech to text pipeline
docstr: ```
  Transcribes audio files to text.
  This method supports files as a string or a list. If the input is a string,
  the return type is string. If text is a list, the return type is a list.
  Args:
      afiles (str|list):  file path to audio file or a list of them
      batch_size (int): batch size
  Returns:
      list of transcribed text
  ```
docstr_tok: ["``","`","Transcribes","audio","files","to","text",".","This","method","supports","files","as","a","string","or","a","list",".","If","the","input","is","a","string",",","the","return","type","is","string",".","If","text","is","a","list",",","the","return","type","is","a","list",".","Args",":","afiles","(","str|list",")",":","file","path","to","audio","file","or","a","list","of","them","batch_size","(","int",")",":","batch","size","Returns",":","list","of","transcribed","text","``","`"]
code: def transcribe(self, afiles, batch_size=32):
      """
      ```
      Transcribes audio files to text.
      This method supports files as a string or a list. If the input is a string,
      the return type is string. If text is a list, the return type is a list.
      Args:
          afiles (str|list):  file path to audio file or a list of them
          batch_size (int): batch size
      Returns:
          list of transcribed text
      ```
      """
  
      # preprocess audio
      values = [afiles] if not isinstance(afiles, list) else afiles
  
      # parse audio files
      # speech = [sf.read(f) for f in values]
      speech = [librosa.load(f, sr=16000) for f in values]
  
      # get unique list of sampling rates (since we're resampling, should be {16000})
      unique = set(s[1] for s in speech)
  
      results = {}
      for sampling in unique:
          # get inputs for current sampling rate
          inputs = [
              (x, s[0])
              for x, s in enumerate(speech)
              if s[1] == sampling
          ]
  
          # transcribe in batches
          outputs = []
          for chunk in batchify([s for _, s in inputs], batch_size):
              outputs.extend(self._transcribe(chunk, sampling))
  
          # Store output value
          for y, (x, _) in enumerate(inputs):
              results[x] = outputs[y].capitalize()
  
      # Return results in same order as input
      results = [results[x] for x in sorted(results)]
      return results[0] if isinstance(afiles, str) else results
  
file_path: ktrain/ktrain/text/speech/core.py
imports: from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
  from ...torch_base import TorchBase
label_desc: Use image node_id 2 for calling the Transcriber obj's underlying member method code with example usage: obj.transcribe(afiles, batch_size) and returns: unknown