class_docstr: FastSpeech2 module.
  
  This is a module of FastSpeech2 described in `FastSpeech 2: Fast and
  High-Quality End-to-End Text to Speech`_. Instead of quantized pitch and
  energy, we use token-averaged value introduced in `FastPitch: Parallel
  Text-to-speech with Pitch Prediction`_.
  
  .. _`FastSpeech 2: Fast and High-Quality End-to-End Text to Speech`:
      https://arxiv.org/abs/2006.04558
  .. _`FastPitch: Parallel Text-to-speech with Pitch Prediction`:
      https://arxiv.org/abs/2006.06873
class_docstr_tok: ["FastSpeech2","module",".","This","is","a","module","of","FastSpeech2","described","in","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`","_",".","Instead","of","quantized","pitch","and","energy",",","we","use","token-averaged","value","introduced","in","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`","_",".","..","_","`","FastSpeech","2",":","Fast","and","High-Quality","End-to-End","Text","to","Speech","`",":","https",":","\/\/arxiv.org\/abs\/2006.04558","..","_","`","FastPitch",":","Parallel","Text-to-speech","with","Pitch","Prediction","`",":","https",":","\/\/arxiv.org\/abs\/2006.06873"]
docstr: Integrate speaker embedding with hidden states.
  
  Args:
      hs (Tensor): Batch of hidden state sequences (B, T_text, adim).
      spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim).
  
  Returns:
      Tensor: Batch of integrated hidden state sequences (B, T_text, adim).
docstr_tok: ["Integrate","speaker","embedding","with","hidden","states",".","Args",":","hs","(","Tensor",")",":","Batch","of","hidden","state","sequences","(","B",",","T_text",",","adim",")",".","spembs","(","Tensor",")",":","Batch","of","speaker","embeddings","(","B",",","spk_embed_dim",")",".","Returns",":","Tensor",":","Batch","of","integrated","hidden","state","sequences","(","B",",","T_text",",","adim",")","."]
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, T_text, adim).
          spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim).
  
      Returns:
          Tensor: Batch of integrated hidden state sequences (B, T_text, adim).
  
      """
      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 and then apply projection
          spembs = (
              F.normalize(spembs)
              .unsqueeze(1)
              .expand(-1, hs.size(1), -1)
          )
          hs = self.projection(torch.cat([hs, spembs], dim=-1))
      else:
          raise NotImplementedError("support only add or concat.")
  
      return hs
  
imports: import logging
  from typing import Dict, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.torch_utils.initialize import initialize
  from espnet2.tts.abs_tts import AbsTTS
  from espnet2.tts.fastspeech2.loss import FastSpeech2Loss
  from espnet2.tts.fastspeech2.variance_predictor import VariancePredictor
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.conformer.encoder import Encoder
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictor
  from espnet.nets.pytorch_backend.fastspeech.length_regulator import LengthRegulator
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask, make_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
label_desc: Use image node_id 5 for calling the FastSpeech2 obj's underlying member method code with example usage: obj._integrate_with_spk_embed(hs, spembs) and returns: hs