class_docstr: Emotion Task 
docstr: generate one example
docstr_tok: ["generate","one","example"]
code: def generate_data(self):
      """generate one example"""
  
      # total files
      total = len(self._train_by_filename.values())
      self._epoch += 1  # epcoh from 1
  
      batch = []
      np.random.shuffle(self.data_items)
      for i, (filename, examples) in enumerate(self.data_items):
          # logging.info("example info", filename, examples)
  
          # convert txt to ids
          if self.use_text:
              text = _load_text(".".join(filename.split(".")[:-1]))
              text2id = self._word_table_lookup(text)
          else:
              text2id = np.array([0] * self._max_text_len)
  
          # gen audio or load feat
          if self._file_suffix == ".wav":
              sr, raw_samples = feat_lib.load_wav(
                  filename
              )  # pylint: disable=invalid-name
              for label, seg, clip_id in examples:
                  # examples of one file
                  samples = raw_samples
                  if seg[2]:
                      samples = np.pad(
                          samples, [0, seg[2]], mode="constant"
                      )
                  samples = samples[seg[0] : seg[1]]
                  assert (
                      len(samples) == self.example_len
                  ), "{} {}".format(filename, seg)
  
                  labelid = self.class_id(label)
  
                  if self.use_distilling:
                      raise ValueError(
                          "Not Support distilation for *.wav input"
                      )
                  else:
                      class_num = self.taskconf["classes"]["num"]
                      soft_label = [0] * class_num
  
                  if self.use_text:
                      if clip_id == 0:
                          # only add into batch when meet the first clip
                          batch.append(
                              (
                                  samples,
                                  text2id,
                                  labelid,
                                  filename,
                                  clip_id,
                                  soft_label,
                              )
                          )
                  else:
                      batch.append(
                          (
                              samples,
                              text2id,
                              labelid,
                              filename,
                              clip_id,
                              soft_label,
                          )
                      )
  
          else:
              feat = np.load(filename)
  
              # shape : [nframe, feat_size, 3]
              if self._feature_type:
                  fbank = feat_lib.add_delta_delta(
                      feat, self._feature_size, order=2
                  )
                  if self._input_channels == 1:
                      fbank = fbank[:, :, 0:1]
              else:
                  fbank = feat_lib.delta_delta(feat)
  
              for label, seg, clip_id in examples:
                  feat = fbank
                  # logging.info("feat shape: {}".format(feat.shape))
  
                  seg = list(map(self.sample_to_frame, seg))
                  if seg[2]:
                      # need padding
                      feat = np.pad(
                          feat,
                          [(0, seg[2]), (0, 0), (0, 0)],
                          mode="constant",
                      )
  
                  feat = feat[seg[0] : seg[1], :, :]
                  expect_nframes = self.sample_to_frame(
                      self.example_len
                  )
                  if len(feat) != expect_nframes:
                      logging.warn(
                          "{} {} {} {} {} {}".format(
                              filename,
                              seg,
                              len(feat),
                              self.example_len,
                              self.sample_to_frame(self.example_len),
                              seg[2],
                          )
                      )
                      feat = np.pad(
                          feat,
                          [
                              (0, expect_nframes - len(feat)),
                              (0, 0),
                              (0, 0),
                          ],
                          mode="constant",
                      )
  
                  if self.use_distilling:
                      soft_label = self.teacher(feat)
                  else:
                      class_num = self.taskconf["classes"]["num"]
                      soft_label = [0] * class_num
  
                  # convert string label to int label
                  labelid = self.class_id(label)
  
                  if self.use_text:
                      if clip_id == 0:
                          # only add into batch when meet the first clip
                          batch.append(
                              (
                                  feat,
                                  text2id,
                                  labelid,
                                  filename,
                                  clip_id,
                                  soft_label,
                              )
                          )
                  else:
                      batch.append(
                          (
                              feat,
                              text2id,
                              labelid,
                              filename,
                              clip_id,
                              soft_label,
                          )
                      )
  
          # if i % 100000:
          #  logging.info('epoch:{} iter exmaple:{} total:{} : {:.2f}%'.format(
          #     self._epoch, i, total, i * 100 / total))
  
          for (
              inputs,
              texts,
              label,
              filepath,
              clip_id,
              soft_label,
          ) in batch:
              yield inputs, texts, label, filepath, clip_id, soft_label
  
          batch.clear()
  
      logging.info("Out of range")
      raise StopIteration
  
imports: import re
  import ast
  import os
  import copy
  import threading
  import itertools
  import functools
  import random
  from collections import defaultdict
  import librosa
  import numpy
  import pandas
  import delta.compat
  from absl import logging
  from sklearn.model_selection import train_test_split
  from delta import utils
  from delta.data import feat
  from delta.utils.register import registers
  from delta.data.task.base_speech_task import SpeechTask
label_desc: Use image node_id 26 for calling the SpeechClsTask obj's underlying member method code with example usage: obj.generate_data() without return types