class_docstr: Factory class for Speedy Speech encoder enables different encoder types internally.
  
  Args:
      num_chars (int): number of characters.
      out_channels (int): number of output channels.
      in_hidden_channels (int): input and hidden channels. Model keeps the input channels for the intermediate layers.
      encoder_type (str): encoder layer types. 'transformers' or 'residual_conv_bn'. Default 'residual_conv_bn'.
      encoder_params (dict): model parameters for specified encoder type.
      c_in_channels (int): number of channels for conditional input.
  
  Note:
      Default encoder_params...
  
      for 'transformer'
          encoder_params={
              'hidden_channels_ffn': 128,
              'num_heads': 2,
              "kernel_size": 3,
              "dropout_p": 0.1,
              "num_layers": 6,
              "rel_attn_window_size": 4,
              "input_length": None
          },
  
      for 'residual_conv_bn'
          encoder_params = {
              "kernel_size": 4,
              "dilations": 4 * [1, 2, 4] + [1],
              "num_conv_blocks": 2,
              "num_res_blocks": 13
          }
class_docstr_tok: ["Factory","class","for","Speedy","Speech","encoder","enables","different","encoder","types","internally",".","Args",":","num_chars","(","int",")",":","number","of","characters",".","out_channels","(","int",")",":","number","of","output","channels",".","in_hidden_channels","(","int",")",":","input","and","hidden","channels",".","Model","keeps","the","input","channels","for","the","intermediate","layers",".","encoder_type","(","str",")",":","encoder","layer","types",".","'transformers","'","or","'residual_conv_bn","'",".","Default","'residual_conv_bn","'",".","encoder_params","(","dict",")",":","model","parameters","for","specified","encoder","type",".","c_in_channels","(","int",")",":","number","of","channels","for","conditional","input",".","Note",":","Default","encoder_params","...","for","'transformer'","encoder_params=","{","'hidden_channels_ffn","'",":","128",",","'num_heads","'",":","2",",","``","kernel_size","''",":","3",",","``","dropout_p","''",":","0.1",",","``","num_layers","''",":","6",",","``","rel_attn_window_size","''",":","4",",","``","input_length","''",":","None","}",",","for","'residual_conv_bn'","encoder_params","=","{","``","kernel_size","''",":","4",",","``","dilations","''",":","4","*","[","1",",","2",",","4","]","+","[","1","]",",","``","num_conv_blocks","''",":","2",",","``","num_res_blocks","''",":","13","}"]
code: def __init__(
      self,
      in_hidden_channels,
      out_channels,
      encoder_type="residual_conv_bn",
      encoder_params={
          "kernel_size": 4,
          "dilations": 4 * [1, 2, 4] + [1],
          "num_conv_blocks": 2,
          "num_res_blocks": 13,
      },
      c_in_channels=0,
  ):
      super().__init__()
      self.out_channels = out_channels
      self.in_channels = in_hidden_channels
      self.hidden_channels = in_hidden_channels
      self.encoder_type = encoder_type
      self.c_in_channels = c_in_channels
  
      # init encoder
      if encoder_type.lower() == "transformer":
          # text encoder
          self.encoder = RelativePositionTransformerEncoder(
              in_hidden_channels,
              out_channels,
              in_hidden_channels,
              encoder_params,
          )  # pylint: disable=unexpected-keyword-arg
      elif encoder_type.lower() == "residual_conv_bn":
          self.encoder = ResidualConv1dBNEncoder(
              in_hidden_channels,
              out_channels,
              in_hidden_channels,
              encoder_params,
          )
      else:
          raise NotImplementedError(" [!] unknown encoder type.")
  
imports: import math
  import torch
  from torch import nn
  from TTS.tts.layers.glow_tts.transformer import RelativePositionTransformer
  from TTS.tts.layers.generic.res_conv_bn import ResidualConv1dBNBlock
label_desc: Use image node_id 1 to create a new Encoder object from inherited base classes: nn with example: obj = Encoder(in_hidden_channels, out_channels, encoder_type, encoder_params, c_in_channels)