从音频文件中获取字节流? [英] Get byte stream from an audio file?

查看:1288
本文介绍了从音频文件中获取字节流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法让从音频文件中的音频数据流中的Java(尤其是wav文件)?

Is there any way to get audio stream from an audio file (wav file in particular) in Java?

我想获得一个特定的时间间隔流,即从的startTime 结束时间,其中的startTime 不为零。例如,从5秒获得音频流到20秒长的音频文件的10秒(5秒持续时间)。

I am trying to get the stream of a particular interval i.e from startTime to endTime where startTime is not zero. For example, to get the audio stream from 5 sec to 10 sec (5 sec duration) of a 20 sec long audio file.

该怎么做?

推荐答案

您可以用标准的Java音色库做到这一点:javax.sound.sampled中

You can do this with the standard Java sound library: javax.sound.sampled.

读.wav文件已被很好这里所覆盖,以及如何将字节转化为相应的帧。如果你勾选相关就对了,你会发现如何读取的音频数据信息,一个缓冲区的同时价值,以及如何通过这些缓冲区迭代和字节转换为PCM数据。

Reading .wav files has been well covered here, as well as how to convert bytes to the corresponding frames. If you check the "Related" on the right, you will find info on how to read audio data, one buffer's worth at a time, and how to iterate through those buffers and convert the bytes to PCM data.

假设你知道帧速率(例如,44100 fps)的它然后就变为计数字节或音频数据的帧的问题。在音响,在44100 fps的16位编码,例如,每个帧由4个字节,所以字节(5 * 4 * 44100)将是5第二点的开始,和(10 * 4 * 44100)将是10第二位。

Assuming you know the frame rate (e.g., 44100 fps) it then just becomes a matter of counting bytes or frames of audio data. At stereo, 16-bit encoding at 44100 fps, for example, each frame consists of 4 bytes, so byte (5 * 4 * 44100) would be the start of the 5 second point, and (10 * 4 * 44100) would be the 10 second spot.

化java声教程是一个艰难的读取。下面的链接有头阅读声音文件下的一个非常有用的code例子。
http://docs.oracle.com/javase/tutorial/sound/converters.html

The java sound tutorials are a tough read. The following link has a very useful code example under the header "Reading Sound Files". http://docs.oracle.com/javase/tutorial/sound/converters.html

有这么读取注释行
//这里做一些事情与现在的audioBytes数组中的音频数据有用的......

There's a comment line that reads "// Here, do something useful with the audio data that's now in the audioBytes array..."

这就是你会算你个字节,并从组装字节PCM数据。

That's where you would count your bytes, and assemble the PCM data from bytes.

这篇关于从音频文件中获取字节流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆