class_docstr: Discrete unit Synthesizer related modules for speech-to-speech translation.
  
  This is a module of discrete unit prediction network in discrete-unit described
  in `Direct speech-to-speech translation with discrete units`_,
  which converts the sequence of hidden states into the sequence of
  discrete unit (from SSLs).
  
  .. _`Direct speech-to-speech translation with discrete units`:
     https://arxiv.org/abs/2107.05604
docstr: Integrate speaker embedding with hidden states.
  
  Args:
      hs (Tensor): Batch of hidden state sequences (B, Tmax, eunits).
      spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim).
  
  Returns:
      Tensor: Batch of integrated hidden state sequences (B, Tmax, eunits) if
          integration_type is "add" else (B, Tmax, eunits + spk_embed_dim).
docstr_tok: ["Integrate","speaker","embedding","with","hidden","states",".","Args",":","hs","(","Tensor",")",":","Batch","of","hidden","state","sequences","(","B",",","Tmax",",","eunits",")",".","spembs","(","Tensor",")",":","Batch","of","speaker","embeddings","(","B",",","spk_embed_dim",")",".","Returns",":","Tensor",":","Batch","of","integrated","hidden","state","sequences","(","B",",","Tmax",",","eunits",")","if","integration_type","is","``","add","''","else","(","B",",","Tmax",",","eunits","+","spk_embed_dim",")","."]
code: def _integrate_with_spk_embed(
      self, hs: torch.Tensor, spembs: torch.Tensor
  ) -> torch.Tensor:
      """Integrate speaker embedding with hidden states.
  
      Args:
          hs (Tensor): Batch of hidden state sequences (B, Tmax, eunits).
          spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim).
  
      Returns:
          Tensor: Batch of integrated hidden state sequences (B, Tmax, eunits) if
              integration_type is "add" else (B, Tmax, eunits + spk_embed_dim).
  
      """
      if self.spk_embed_integration_type == "add":
          # apply projection and then add to hidden states
          spembs = self.projection(F.normalize(spembs))
          hs = hs + spembs.unsqueeze(1)
      elif self.spk_embed_integration_type == "concat":
          # concat hidden states with spk embeds
          spembs = (
              F.normalize(spembs)
              .unsqueeze(1)
              .expand(-1, hs.size(1), -1)
          )
          hs = torch.cat([hs, spembs], dim=-1)
      else:
          raise NotImplementedError("support only add or concat.")
  
      return hs
  
imports: import logging
  from typing import Any, Dict, List, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.asr.decoder.transformer_decoder import TransformerDecoder
  from espnet2.s2st.synthesizer.abs_synthesizer import AbsSynthesizer
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.scorer_interface import BatchScorerInterface
label_desc: Use image node_id 4 for calling the TransformerDiscreteSynthesizer obj's underlying member method code with example usage: obj._integrate_with_spk_embed(hs, spembs) and returns: hs