How to get the length of wav file?
am 16.05.2006 07:01:22 von lgj573I have tried Audio::Wav module,but it cann't get the length of a
compressed file such as u-law 8bit 8khz.Is there any other module will
do?
I have tried Audio::Wav module,but it cann't get the length of a
compressed file such as u-law 8bit 8khz.Is there any other module will
do?
Hi!
Maybe you can use
-s $filename
or
filestat?
/Bjoern
news:1147755682.037544.231790@i39g2000cwa.googlegroups.com.. .
>I have tried Audio::Wav module,but it cann't get the length of a
> compressed file such as u-law 8bit 8khz.Is there any other module will
> do?
>
Here is the code.But here will be some problem if I is called.
public static double getLength(String path) throws Exception {
AudioInputStream stream;
stream = AudioSystem.getAudioInputStream(new URL(path));
AudioFormat format = stream.getFormat();
if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true); // big endian
stream = AudioSystem.getAudioInputStream(format, stream);
}
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat(), ((int)
stream.getFrameLength() * format.getFrameSize()));
Clip clip = (Clip) AudioSystem.getLine(info);
clip.close();
return clip.getBufferSize() / (clip.getFormat().getFrameSize()
* clip.getFormat().getFrameRate());
}
"lgj573@gmail.com"
> Here is the code.But here will be some problem if I is called.
> public static double getLength(String path) throws Exception {
This looks like Java. If you want help with Java code, you should
probably ask your question on a Java newsgroup. If you're using Perl,
File::Headerinfo::WAV will probably do what you want; I haven't used
it, but it claims to "extract useful information like their duration
and filesize" from WAV files. Audio::WAV also includes methods for
that, but it's more oriented towards working with the contents of WAV
files. If you need to do that sort of thing, it looks useful.
-=Eric