简体   繁体   English

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

[英]getAudioInputStream can not convert [stereo, 4 bytes/frame] stream to [mono, 2 bytes/frame]

I am using javasound and have an AudioInputStream of format PCM_SIGNED 8000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian 我正在使用javasound并具有格式为PCM_SIGNED 8000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian的AudioInputStream

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 当target_format为PCM_SIGNED 8000.0 Hz, 16 bit, mono, 2 bytes/frame, little-endianAudioSystem.getAudioInputStream(target_format, original_stream)使用AudioSystem.getAudioInputStream(target_format, original_stream)会产生“ IllegalArgumentException:不支持的转换”

Is it possible to convert this stream manually after every read() call? 是否可以在每次read()调用之后手动转换此流? And if yes, how? 如果是的话,怎么办?
In general, how can you compare two formats and tell if a conversion is possible? 通常,如何比较两种格式并判断是否可以转换?

Is it possible to convert this stream manually after every read() call? 是否可以在每次read()调用之后手动转换此流? 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). 您可以使用正确的编码(针对GSM,mu-law或A-law)实现相同的编码。 Note that you might need a plugin to achieve this conversion. 请注意,您可能需要一个插件来实现此转换。 More information here: Java Sound Resources 这里的更多信息: Java声音资源

It is possible to convert the stream after each read() call, but if your stream can't convert, it can't convert. 可以在每次read()调用之后转换流,但是如果您的流不能转换,则不能转换。

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. 您定义两种格式,然后使用AudioSystem检查是否可以进行转换。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM