code: def _average_by_duration(ds, xs, text_lengths, feats_lengths):
      B = ds.shape[0]
      xs_avg = np.zeros_like(ds)
      ds = ds.astype(np.int32)
      for b in range(B):
          t_text = text_lengths[b]
          t_feats = feats_lengths[b]
          d = ds[b, :t_text]
          d_cumsum = d.cumsum()
          d_cumsum = [0] + list(d_cumsum)
          x = xs[b, :t_feats]
          for n, (start, end) in enumerate(
              zip(d_cumsum[:-1], d_cumsum[1:])
          ):
              if len(x[start:end]) != 0:
                  xs_avg[b, n] = x[start:end].mean()
              else:
                  xs_avg[b, n] = 0
      return xs_avg
  
file_path: espnet/espnet2/gan_tts/jets/alignments.py
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from numba import jit
  from scipy.stats import betabinom
label_desc: Use image node_id 3 for calling a global function with example usage: _average_by_duration(ds, xs, text_lengths, feats_lengths) and returns: xs_avg