|
Posted by lgj573@gmail.com on May 16, 2006, 1:01 am
Please log in for more thread options
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?
|
|
Posted by bdj on May 16, 2006, 3:06 pm
Please log in for more thread options
Hi!
Maybe you can use
-s $filename
or
filestat?
/Bjoern
>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?
>
|
|
Posted by lgj573@gmail.com on May 17, 2006, 2:12 am
Please log in for more thread options
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());
}
|
|
Posted by Eric Schwartz on May 17, 2006, 11:55 am
Please log in for more thread options
> 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
|
| Similar Threads | Posted | | invalid COMMPROP block length= 100...... | November 16, 2005, 8:21 am |
| archive::zip addtree creates zero-length files | November 6, 2005, 9:35 pm |
| Net::SNMP - ERROR: Invalid IpAddress length (8 bytes) | January 20, 2006, 1:41 pm |
| install HTML::Template - Problem reading cache file / Bad file number | July 24, 2004, 7:55 pm |
| Reading contents of an excel file from a test file | May 15, 2007, 2:49 am |
| A do-file location: how the code inside that do-file find it? | January 20, 2008, 12:32 am |
| DBD:mysql doesn't read mysql option file /etc/my.cnf file | January 27, 2005, 11:19 pm |
| Win32::File | August 29, 2004, 9:08 pm |
| SGI::FAM and File::PathConvert | June 14, 2005, 10:58 am |
| file upload | January 5, 2006, 7:00 am |
|