code: def extract_segments(wavs, segments=None):
      """This function returns generator of segmented audio.
      Yields (utterance id, numpy.float32 array).
      TODO?: sampling rate is not converted.
      """
      if segments is not None:
          # segments should be sorted by rec-id
          for seg in segments:
              wav = wavs[seg["rec"]]
              data, samplerate = load_wav(wav)
              st_sample = np.rint(seg["st"] * samplerate).astype(int)
              et_sample = np.rint(seg["et"] * samplerate).astype(int)
              yield seg["utt"], data[st_sample:et_sample]
      else:
          # segments file not found,
          # wav.scp is used as segmented audio list
          for rec in wavs:
              data, samplerate = load_wav(wavs[rec])
              yield rec, data
  
imports: from __future__ import print_function
  import io
  import os
  import subprocess
  import sys
  from functools import lru_cache
  import numpy
  import soundfile
label_desc: Use image node_id 10 for calling a global function with example usage: extract_segments(wavs, segments) without return types