- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用Java / HTML5 / JSF前端和Glassfish(Java)后端编写基于Web的录音机。
我需要使用ULAW编码保存记录的.WAV文件。但是据我所知,以HTML5 / Javascript(带有getUserMedia()
)录制音频的唯一方法是采用PCM编码。我希望有一种简单的方法来捕获ULAW中的客户端记录,但是一直找不到任何方法。
所以现在我一直想做的是:
Record in PCM wav (client side)
Upload to server using JSP
Pass the received FileItem into a JAVA converter method that returns a byte array in ULAW
convertPCMtoULAW(FileItem file)
Java方法:
//read the FileItem's InputStream into a byte[]
InputStream uploadedStream = file.getInputStream();
byte[] pcmBytes = new byte[(int) file.getSize()];
uploadedStream.read(pcmBytes);
//extract the number of PCM Samples from the header
int offset =40;
int length =4;
int pcmSamples = 0;
for (int i = 0; i < length; i++)
{
pcmSamples += ((int) pcmBytes[offset+i] & 0xffL) << (8 * i);
}
//create the UlawEncoderInputStream (class in link above)
is = new UlawEncoderInputStream(
file.getInputStream(),
UlawEncoderInputStream.maxAbsPcm(pcmBytes, 44, pcmSamples/2)
);
//read from the created InputStream into another byte[]
byteLength = is.read(ulawBytes);
//I then add the ULAW header to the beginning of the byte[]
//and pass the entire byte[] through a pre-existing Wav Verifier method
//which serializes the byte[] later on
最佳答案
我相信您面临的问题与转码无关,而是与Java的InputStream.read
的契约(Contract)无关。从documentation:
Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.
read(byte[] b, int off, int len)
直到关闭流,或者将流包装为 DataInputStream
并使用 readFully
。
关于java - 在JAVA中将PCM WAV转换为ULAW WAV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31813753/
我正在调试一段处理 uLaw 或 aLaw 格式的 RTP 语音流的代码。我想捕获通过我的代码的样本并将它们存储到一个文件中。 那很简单。我的问题是:有没有一种文件格式可以让我轻松封装原始数据,以便它
我正在尝试在 tvOS(.au 文件)上播放 uLaw 声音。我知道声音文件没有损坏,因为将其放入 Audacity 可以正常播放。 我尝试了多种方法,从AVAudioPlayer到较低级别的Audi
我需要实时捕获麦克风语音输入并通过 RTSP 向上流传输。音频格式需要在 ulaw 中。我需要获取原始字节,以便将其提供给 Live 555 RTSP 库。鉴于 Core Audio 和 AV Fou
我在 asterisk 服务器上工作,它使用 ulaw 文件在通话中播放 IVR,但我们的客户只提供需要转换为 ulaw 的 mp3 文件,因为我是新手,不知道有任何此类程序还有什么方法可以更快地实现
当我们需要流式传输音频时,没有太多关于应用此编解码器的信息。在不应用编解码器的情况下,我的代码就像在两个设备之间建立通信的魅力一样工作,但我需要以该格式进行编码/解码,因为我需要使用服务器而不是在两个
试图在 python 中将 wav 文件转换为 wav uLaw。 使用 pydub 的 AudioSegment,我可以使用以下命令转换为 mp3: AudioSegment.from_wav(fr
我一直在查看 NAudio 示例,试图了解如何获得适合打包为 RTP 负载的 ulaw 样本。我正在尝试使用下面的代码从 mp3 文件生成示例。毫不奇怪,因为我真的不知道我在用 NAudio 做什么,
我正在尝试将包含 8kHz 8 位单声道 ulaw 数据 (64kbps) 的波形文件转换为 PCM。我正在查看文档并找到 audioop,ulaw2lin 似乎是我想要的,但文档对如何获取文件的正确
我是一名优秀的程序员,十分优秀!