本文介绍了音频格式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在转换WAV文件的音频格式的麻烦。

I am having trouble in converting the audio format of a WAV file.

我从我的麦克风录制声音和声音记录的格式如下:
PCM_SIGNED 44100.0赫兹,16位,单声道,2个字节/帧

I am recording sound from my microphone and the sound is recorded in the following format:PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame

我想上面的格式转换,
ULAW 8000.0赫兹,8位,单声道,1个字节/帧

I want to convert the above format to,ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame

我用下面的code,

InputStream is = request.getInputStream();
            AudioInputStream ais = AudioSystem.getAudioInputStream(is);
            AudioFormat oldFormat = ais.getFormat();
            AudioFormat newFormat = new AudioFormat(AudioFormat.Encoding.ULAW, 8000, 8, 1, 1, 8000, false) ;
AudioInputStream lowResAIS = AudioSystem.getAudioInputStream(newFormat, ais); //Getting the below Exception on this line

和我收到以下错误,

java.lang.IllegalArgumentException异常:不支持的转换:ULAW 8000.0赫兹,8位,单声道,1个字节/帧,从PCM_SIGNED 44100.0赫兹,16位,单声道,2个字节/帧,小尾数

java.lang.IllegalArgumentException: Unsupported conversion: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, from PCM_SIGNED 44100.0 Hz, 16 bit, mono, 2 bytes/frame, little-endian

有人可以帮我解决这个问题!

Can someone please help me solve this problem!!!

由于一吨!

推荐答案

你看看的的?

抛出
  IllegalArgumentException - 如果不支持转换#see #getTargetEncodings(AudioFormat的)

不是每个系统将安装转换到你所要求的特定格式足以codeCS。你认为你的做法,但它引发异常,因为它无法转换为这种格式。

Not every system will have sufficient codecs installed to transform to the specific format you've asked for. You've assumed yours does, but it's throwing the exception because it can't transform to that format.

您可以使用 getTargetEncodings 来检查编程定格式的适用性,不依赖于异常,然后就可以采取适当的行动,如果你所需的输出格式不可用(如回落到另一个,present反馈用户,这是不可能的,等等)。

You can use getTargetEncodings to check the suitability of a given format programatically, without relying on an exception, and then can take appropriate action if you desired output format isn't available (e.g. fall back to another one, present the user with feedback that this is impossible, etc.).

这篇关于音频格式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 03:24