gpt4 book ai didi

java - AudioInputStream - 寻找更快

转载 作者:行者123 更新时间:2023-11-30 10:29:18 24 4
gpt4 key购买 nike

我有一个 AudioInputStream 不支持 skip()。它由 jflac 支持。

因此,我正在使用 read ( byte[] ) 调用并转储数据,以在文件中向前跳转。

不幸的是,搜索 17MB 大约需要 1 秒(搜索一分钟大约需要 0.25 秒),这对我来说太慢了。

我可以做些什么来尝试更快地搜索文件吗?为了获得良好的用户体验,我需要比目前快 20-30 倍的速度。

这是我的代码:

private void openStreamsAtRequestedOffset ( ) {
encodedInput = AudioSystem.getAudioInputStream( file );

AudioFormat baseFormat = encodedInput.getFormat();
AudioFormat decoderFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(),
16, baseFormat.getChannels(), baseFormat.getChannels() * 2,
baseFormat.getSampleRate(), false );

decodedInput = AudioSystem.getAudioInputStream ( decoderFormat, encodedInput );

if ( seekRequestPercent != NO_SEEK_REQUESTED ) {
long seekPositionByte = getBytePosition ( file, seekRequestPercent );
int bytesRead = 0;

byte[] skippedData = new byte[ 256 ];
while ( bytesRead < seekPositionByte ) {
int bytesSkipped = decodedInput.read ( skippedData );
bytesRead += bytesSkipped;
}
}

DataLine.Info info = new DataLine.Info ( SourceDataLine.class, decoderFormat );
audioOutput = (SourceDataLine) AudioSystem.getLine(info);
audioOutput.open( decoderFormat );
}

我尝试读取多于和少于 256 字节,似乎没有任何有意义的影响。

我还尝试使用 BufferedInputStream 打开文件,调用 skip(),然后通过几种不同的方式将 BufferedInputStream 传递给 AudioSystem.getAudioInputStream(),但那些也失败了。每当我调用 skip 时,jflac 都会声称流已关闭。

有什么想法吗?

最佳答案

AudioInputStream.skip() 时,您当然不应该尝试自己滚动已经存在。如果您有一个不支持它的,请向供应商投诉。所有要做的就是在底层流上调用“skip()”,因为它是一个文件输入流,所以应该是即时的。

关于java - AudioInputStream - 寻找更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44065772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com