fabgonber

mejorador_de_transcripciones_teams

Oct 14th, 2024
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2.  
  3. if ($argc !== 3) {
  4.     echo "Uso: php {$argv[0]} transcripcion_original.txt transcripcion_unificada.txt\n";
  5.     exit(1);
  6. }
  7.  
  8. $input_file = $argv[1];
  9. $output_file = $argv[2];
  10.  
  11. $lines = file($input_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
  12. $result = [];
  13. $last_name = '';
  14.  
  15. foreach ($lines as $line) {
  16.     // Si la línea empieza con un nombre
  17.     if (preg_match('/^\[.*\]/', $line)) {
  18.         // Si el último nombre es diferente al actual, lo almacenamos
  19.         if ($last_name !== $line) {
  20.             $result[] = "\n".trim($line);
  21.             $last_name = $line;
  22.         }
  23.     } else {
  24.         // Agregar la línea de diálogo
  25.         $result[] = trim($line);
  26.     }
  27. }
  28.  
  29. // Escribir el resultado en el archivo de salida
  30. file_put_contents($output_file, implode("\n", $result));
  31.  
Advertisement
Add Comment
Please, Sign In to add comment