code: def build_text_encoder(cls, args, src_dictionary, spch_encoder):
      if args.encoder_shared_layers > 0:
          mx_shared_layers = (
              args.speech_encoder_layers
              if args.speech_encoder_layers < args.text_encoder_layers
              else args.text_encoder_layers
          )
          args.encoder_shared_layers = (
              args.encoder_shared_layers
              if args.encoder_shared_layers <= mx_shared_layers
              else mx_shared_layers
          )
      cfg = {
          "encoder_embed_dim": args.encoder_text_embed_dim,
          "encoder_ffn_embed_dim": args.encoder_ffn_embed_dim,
          "encoder_layers": args.text_encoder_layers,
          "encoder_layerdrop": args.encoder_layerdrop,
          "encoder_attention_heads": args.encoder_attention_heads,
          "encoder_learned_pos": args.encoder_learned_pos,
          "max_source_positions": args.max_source_positions,
          "dropout": args.dropout,
          "encoder_normalize_before": args.encoder_normalize_before,
          "activation_dropout": args.activation_dropout,
          "attention_dropout": args.attention_dropout,
          "activation_fn": args.activation_fn,
          "adaptive_input": args.adaptive_input,
          "no_token_positional_embeddings": args.no_token_positional_embeddings,
          "no_scale_embedding": args.no_scale_embedding,
          "quant_noise_pq": args.quant_noise_pq,
      }
      model_args = namedtuple("args", cfg.keys())(*cfg.values())
      enc_emb = nn.Embedding(
          len(src_dictionary),
          model_args.encoder_embed_dim,
          src_dictionary.pad(),
      )
      text_encoder = TransformerEncoder(
          model_args, src_dictionary, enc_emb
      )
      if args.add_speech_eos:
          spch_encoder = spch_encoder.encoder
      if args.encoder_shared_layers > 0:
          text_encoder.layer_norm = cls.set_shared_layer(
              args.encoder_shared_layer_level,
              text_encoder.layer_norm,
              spch_encoder.layer_norm,
          )
          for i, ly in enumerate(
              spch_encoder.transformer_layers[
                  -args.encoder_shared_layers :
              ]
          ):
              ly_id = (
                  i
                  + args.text_encoder_layers
                  - args.encoder_shared_layers
              )
              if not isinstance(text_encoder.layers[ly_id], type(ly)):
                  if text_encoder.layers[ly_id]._get_name() not in (
                      "TransformerEncoderLayerBase",
                      "TransformerEncoderLayer",
                  ):
                      raise ValueError(
                          "The shared layers are expected from the same class"
                      )
              text_encoder.layers[ly_id] = cls.set_shared_layer(
                  args.encoder_shared_layer_level,
                  text_encoder.layers[ly_id],
                  ly,
              )
      return text_encoder
  
imports: import logging
  from collections import namedtuple
  import torch
  import torch.nn
  from fairseq import checkpoint_utils
  from fairseq import utils
  from fairseq.models import FairseqEncoder, FairseqDecoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.models.fairseq_encoder import EncoderOut
  from fairseq.models.speech_to_text import TransformerDecoder, S2TTransformerEncoder
  from fairseq.models.transformer import TransformerEncoder
  from fairseq.modules import TransformerEncoderLayer, GradMultiply, LayerNorm
label_desc: Use image node_id 4 for calling the DualInputEncoder obj's underlying member method code with example usage: obj.build_text_encoder(cls, args, src_dictionary, spch_encoder) and returns: text_encoder