class_docstr: Reader class for random access to text.
  
      Simple text reader for non-pair text data (for unsupervised ASR)
          Instead of loading the whole text into memory (often large for UASR),
          the reader consumes text which stores in byte-offset of each text file
          and randomly selected unpaired text from it for training using mmap.
  
      Examples:
          text
              text1line
              text2line
              text3line
          scp
              11
              00000000000000000010
              00000000110000000020
              00000000210000000030
          scp explanation
              (number of digits per int value)
              (text start at bytes 0 and end at bytes 10 (including "
  "))
              (text start at bytes 11 and end at bytes 20 (including "
  "))
              (text start at bytes 21 and end at bytes 30 (including "
  "))
      
class_docstr_tok: ["Reader","class","for","random","access","to","text",".","Simple","text","reader","for","non-pair","text","data","(","for","unsupervised","ASR",")","Instead","of","loading","the","whole","text","into","memory","(","often","large","for","UASR",")",",","the","reader","consumes","text","which","stores","in","byte-offset","of","each","text","file","and","randomly","selected","unpaired","text","from","it","for","training","using","mmap",".","Examples",":","text","text1line","text2line","text3line","scp","11","00000000000000000010","00000000110000000020","00000000210000000030","scp","explanation","(","number","of","digits","per","int","value",")","(","text","start","at","bytes","0","and","end","at","bytes","10","(","including","``","''",")",")","(","text","start","at","bytes","11","and","end","at","bytes","20","(","including","``","''",")",")","(","text","start","at","bytes","21","and","end","at","bytes","30","(","including","``","''",")",")"]
code: def __init__(
      self,
      text_and_scp: str,
  ):
      assert check_argument_types()
      super().__init__()
  
      text, text_scp = text_and_scp.split("-")
  
      text_f = Path(text).open("r+b")
      scp_f = Path(text_scp).open("r+b")
  
      self.text_mm = mmap(text_f.fileno(), 0)
      self.scp_mm = mmap(scp_f.fileno(), 0)
  
      max_num_digits_line = self.scp_mm.readline()
      max_num_digits = int(max_num_digits_line)
      assert max_num_digits > 0
  
      self.first_line_offset = len(max_num_digits_line)
      self.max_num_digits = max_num_digits
      self.stride = 2 * max_num_digits + 1
  
      num_text_bites = len(self.scp_mm) - len(max_num_digits_line)
      assert num_text_bites % self.stride == 0
      num_lines = num_text_bites // self.stride
      self.num_lines = num_lines
  
file_path: espnet/espnet2/fileio/read_text.py
imports: import collections.abc
  import logging
  from mmap import mmap
  from pathlib import Path
  from random import randint
  from typing import Dict, List, Optional, Tuple, Union
  from typeguard import check_argument_types
label_desc: Use image node_id 1 to create a new RandomTextReader object from inherited base classes: collections.abc with example: obj = RandomTextReader(text_and_scp)