class_docstr: Sample collection reader for reading a Sample DB (SDB) file
class_docstr_tok: ["Sample","collection","reader","for","reading","a","Sample","DB","(","SDB",")","file"]
docstr: Parameters
  ----------
  sdb_filename : str
      Path to the SDB file to read samples from
  buffering : int
      Read-ahead buffer size to use while reading the SDB file in normal order. Fixed to 16kB if in reverse-mode.
  id_prefix : str
      Prefix for IDs of read samples - defaults to sdb_filename
  labeled : bool or None
      If True: Reads util.sample_collections.LabeledSample instances. Fails, if SDB file provides no transcripts.
      If False: Ignores transcripts (if available) and reads (unlabeled) util.audio.Sample instances.
      If None: Automatically determines if SDB schema has transcripts
      (reading util.sample_collections.LabeledSample instances) or not (reading util.audio.Sample instances).
code: def __init__(
      self,
      sdb_filename,
      buffering=BUFFER_SIZE,
      id_prefix=None,
      labeled=True,
      reverse=False,
  ):
      """
      Parameters
      ----------
      sdb_filename : str
          Path to the SDB file to read samples from
      buffering : int
          Read-ahead buffer size to use while reading the SDB file in normal order. Fixed to 16kB if in reverse-mode.
      id_prefix : str
          Prefix for IDs of read samples - defaults to sdb_filename
      labeled : bool or None
          If True: Reads util.sample_collections.LabeledSample instances. Fails, if SDB file provides no transcripts.
          If False: Ignores transcripts (if available) and reads (unlabeled) util.audio.Sample instances.
          If None: Automatically determines if SDB schema has transcripts
          (reading util.sample_collections.LabeledSample instances) or not (reading util.audio.Sample instances).
      """
      self.sdb_filename = sdb_filename
      self.id_prefix = sdb_filename if id_prefix is None else id_prefix
      self.sdb_file = open_remote(
          sdb_filename,
          "rb",
          buffering=REVERSE_BUFFER_SIZE if reverse else buffering,
      )
      self.offsets = []
      if self.sdb_file.read(len(MAGIC)) != MAGIC:
          raise RuntimeError("No Sample Database")
      meta_chunk_len = self.read_big_int()
      self.meta = json.loads(
          self.sdb_file.read(meta_chunk_len).decode()
      )
      if SCHEMA_KEY not in self.meta:
          raise RuntimeError("Missing schema")
      self.schema = self.meta[SCHEMA_KEY]
  
      speech_columns = self.find_columns(
          content=CONTENT_TYPE_SPEECH,
          mime_type=SERIALIZABLE_AUDIO_TYPES,
      )
      if not speech_columns:
          raise RuntimeError("No speech data (missing in schema)")
      self.speech_index = speech_columns[0]
      self.audio_type = self.schema[self.speech_index][MIME_TYPE_KEY]
  
      self.transcript_index = None
      if labeled is not False:
          transcript_columns = self.find_columns(
              content=CONTENT_TYPE_TRANSCRIPT, mime_type=MIME_TYPE_TEXT
          )
          if transcript_columns:
              self.transcript_index = transcript_columns[0]
          else:
              if labeled is True:
                  raise RuntimeError(
                      "No transcript data (missing in schema)"
                  )
  
      sample_chunk_len = self.read_big_int()
      self.sdb_file.seek(sample_chunk_len + BIGINT_SIZE, 1)
      num_samples = self.read_big_int()
      for _ in range(num_samples):
          self.offsets.append(self.read_big_int())
      if reverse:
          self.offsets.reverse()
  
imports: import os
  import io
  import csv
  import json
  import tarfile
  from pathlib import Path
  from functools import partial
  from .helpers import KILOBYTE, MEGABYTE, GIGABYTE, Interleaved, LenMap
  from .audio import Sample, AUDIO_TYPE_PCM, AUDIO_TYPE_OPUS, SERIALIZABLE_AUDIO_TYPES, get_loadable_audio_type_from_extension, write_wav
  from .io import open_remote, is_remote_path
label_desc: Use image node_id 1 to create a new SDB object  with example: obj = SDB(sdb_filename, buffering, id_prefix, labeled, reverse)