code: def main(args):
      assert not os.path.exists(
          args.outdir
      ), f"Error: Output path exists already {args.outdir}"
  
      transcripts = []
      with open(args.text_filepath) as f:
          transcripts = [line.strip() for line in f]
      print(
          "Read {} lines from {}".format(
              len(transcripts), args.text_filepath
          )
      )
  
      norm_transcripts = [
          text_normalize(line.strip(), args.lang)
          for line in transcripts
      ]
      tokens = get_uroman_tokens(
          norm_transcripts, args.uroman_path, args.lang
      )
  
      model, dictionary = load_model_dict()
      model = model.to(DEVICE)
      if args.use_star:
          dictionary["<star>"] = len(dictionary)
          tokens = ["<star>"] + tokens
          transcripts = ["<star>"] + transcripts
          norm_transcripts = ["<star>"] + norm_transcripts
  
      segments, stride = get_alignments(
          args.audio_filepath,
          tokens,
          model,
          dictionary,
          args.use_star,
      )
      # Get spans of each line in input text file
      spans = get_spans(tokens, segments)
  
      os.makedirs(args.outdir)
      with open(f"{args.outdir}/manifest.json", "w") as f:
          for i, t in enumerate(transcripts):
              span = spans[i]
              seg_start_idx = span[0].start
              seg_end_idx = span[-1].end
  
              output_file = f"{args.outdir}/segment{i}.flac"
  
              audio_start_sec = seg_start_idx * stride / 1000
              audio_end_sec = seg_end_idx * stride / 1000
  
              tfm = sox.Transformer()
              tfm.trim(audio_start_sec, audio_end_sec)
              tfm.build_file(args.audio_filepath, output_file)
  
              sample = {
                  "audio_start_sec": audio_start_sec,
                  "audio_filepath": str(output_file),
                  "duration": audio_end_sec - audio_start_sec,
                  "text": t,
                  "normalized_text": norm_transcripts[i],
                  "uroman_tokens": tokens[i],
              }
              f.write(json.dumps(sample) + "\n")
  
      return segments, stride
  
file_path: fairseq/examples/mms/data_prep/align_and_segment.py
imports: import os
  import torch
  import torchaudio
  import sox
  import json
  import argparse
  from examples.mms.data_prep.text_normalization import text_normalize
  from examples.mms.data_prep.align_utils import get_uroman_tokens, time_to_frame, load_model_dict, merge_repeats, get_spans
  import torchaudio.functional
label_desc: Use image node_id 3 for calling a global function with example usage: main(args) and returns: segments,  stride