问题描述
喜
我有一个短阵PCM样本。什么是玩这个最好的出路?
格式为8000Hz的,单声道,16位,大端。
(PCM样是在code产生并通过某些文件无法读取)
HiI have PCM samples in a short array. What is the best way to play this out?The format is 8000Hz, Mono, 16 bit, big endian.(The PCM samples are generated in the code and not read through some file)
感谢
推荐答案
随着的包是pretty多简单,但你必须使用一些样板。
With the javax.sound.sampled package it's pretty much straightforward, but you have to use some boilerplate.
下面是上一个很好的教程:
Here's a good tutorial on that: www.wikijava.org/wiki/Play_a_wave_sound_in_Java
基本上,你必须从你的阵列创建一个的InputStream
并用它来创建一个的AudioInputStream
。在那里,您必须指定音频数据的格式。
Basically you have to create an InputStream
from your array and use that to create an AudioInputStream
. There you have to specify the format of your audio data.
然后你打开一个输出流(的SourceDataLine
),并从音频流成流复制字节。
Then you open an output stream (SourceDataLine
) and copy the bytes from the audio stream into that stream.
这篇关于如何发挥在Java PCM原始数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!