getAudioInputStream 无法将 [立体声,4 字节/帧] 流转换为 [单声道,2 字节/帧]

发布于 2024-09-01 10:55:29 字数 242 浏览 2 评论 0原文

我正在使用 javasound 并有一个 AudioInputStream 格式 PCM_SIGNED 8000.0 Hz、16 位、立体声、4 字节/帧、小尾数

当target_format 为 PCM_SIGNED 8000.0 Hz、16 位、单声道、2 字节/帧、小端字节序

是否可以在每次 read() 调用后手动转换此流?如果是,怎么做?
一般来说,如何比较两种格式并判断是否可以进行转换?

I am using javasound and have an AudioInputStream of format
PCM_SIGNED 8000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian

Using AudioSystem.getAudioInputStream(target_format, original_stream) produces an 'IllegalArgumentException: Unsupported Conversion' when the target_format is PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian

Is it possible to convert this stream manually after every read() call? And if yes, how?
In general, how can you compare two formats and tell if a conversion is possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网白 2024-09-08 10:55:29

是否可以在每次 read() 调用后手动转换此流?如果是,怎么做?

我不确定你想做什么,但这似乎没有必要。一旦您实际创建了音频输入流,缓冲数据并进行格式转换就更有意义了。

在我看来,您正在从立体声切换到单声道,以尝试节省数据传输大小。您可以通过适当的编码(GSM、mu-law 或 A-law)实现相同的目的。请注意,您可能需要一个插件来实现此转换。更多信息请点击这里:
Java 声音资源

可以在每次 read() 调用后转换流,但是如果您的流无法转换,它就无法转换。

一般来说,如何比较两种格式并判断是否可以进行转换?
您定义两种格式并使用 AudioSystem 检查转换是否可行。

boolean bConversionSupported = AudioSystem.isConversionSupported(targetFormat, sourceFormat);

Is it possible to convert this stream manually after every read() call? And if yes, how?

I'm not sure what you want to do, but this seems unnecessary. It makes more sense to buffer your data and to do the format conversion once you actually create the audio input stream.

It appears to me like you are switching from stereo to mono to try and save data transfer sizes. You can achieve the same with proper encoding (to GSM, mu-law or A-law). Note that you might need a plugin to achieve this conversion. More information here:
Java Sound Resources

It is possible to convert the stream after each read() call, but if your stream can't convert, it can't convert.

In general, how can you compare two formats and tell if a conversion is possible?
You define your two formats and use AudioSystem to check if the conversion is possible.

boolean bConversionSupported = AudioSystem.isConversionSupported(targetFormat, sourceFormat);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文