[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Stille aus Audio-Files entfernen



Moin Volker!
Volker Cordes schrieb am Sunday, den 29. September 2002:

> Ich möchte von meinen WAV-Dateien automatisch Stille an Anfang und Ende 
> entfernen. Mit welchem Programm mache ich das am besten? Ich hab mir 
> schon SoX angeschaut aber keine entsprechendes Beispiel gefunden.

Mein 2 Jahre alter Hack... das für Analyze des Anfangs anzupasse sollte
nicht weiter kompliziert sein.

Gruss/Regards,
Eduard.
-- 
#include <welt_ist_doch_ein_dorf.h>
#!/usr/bin/perl
# cut-zeroes by Eduard Bloch <blade@debian.org>
#
# Changes by Sebastian Kaps <toyland@babylon.sauerland.de>
# and Jens Guenther <Jenz.Guenther@t-online.de>

die(
'
USAGE: '.$0.' file [files] [directory]
This script will analyze the end of given WAVE files and remove zeroes
from the end of this files. Zero bytes are equal to the absolute silence.

If the last argument is a directory, the new file(s) will be stored there,
otherwise the original file(s) will be modified.

WARNING: The new filesize are not equal with the size noticed in the
header of the file. This may confuse some software, so use this tool
only if you know what you do.
'
) if($#ARGV lt 0);

print "
WARNING: The new filesize are not equal with the size noticed in the
header of the file. This may confuse some software, so use this tool
only if you know what you do. Continue? [Y/n]" ;

while (<STDIN>) {
  die "exiting...\n" if ($_=~/n/i);
  goto go if (/y/i); 
}

go:
$dirmode=0;
$dirmode=1 if (-d $ARGV[$#ARGV]);

LOOP: foreach $i (0..$#ARGV) {
   my $file = $ARGV[$i];
   exit if (($i eq $#ARGV) && $dirmode);
   my $filesize = (stat($file))[7];
   my $c=0;
   if(!open(FILE, "+<$file")) {
      print "$file could not be opened, skipping...\n";
      next LOOP;
   }

   do {
      $c++;
      seek(FILE, -$c, 2);
      $byte = getc(FILE);
   } while (ord($byte) == 0);

   print $c-1, " trailing Zeroes (",$file,")\n";
   if($dirmode){
      $basename = (@names=split("/",$file)) ? $names[$#names] : $file;
      system ("dd bs=1 count=".($c-1)." if=".$file." of=".$ARGV[$#ARGV]."/$basename");
   }
   else {
      truncate(FILE, $filesize+1-$c);
   }
}
#:wq

Reply to: