getAudioInputStream 无法将 [立体声,4 字节/帧] 流转换为 [单声道,2 字节/帧]
我正在使用 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 formatPCM_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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是否可以在每次 read() 调用后手动转换此流?如果是,怎么做?
我不确定你想做什么,但这似乎没有必要。一旦您实际创建了音频输入流,缓冲数据并进行格式转换就更有意义了。
在我看来,您正在从立体声切换到单声道,以尝试节省数据传输大小。您可以通过适当的编码(GSM、mu-law 或 A-law)实现相同的目的。请注意,您可能需要一个插件来实现此转换。更多信息请点击这里:
Java 声音资源
可以在每次 read() 调用后转换流,但是如果您的流无法转换,它就无法转换。
一般来说,如何比较两种格式并判断是否可以进行转换?
您定义两种格式并使用 AudioSystem 检查转换是否可行。
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.