how to play pcm raw data in java [closed]

狂风中的少年 提交于 2019-11-27 18:18:32

问题


I 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)

Thanks


回答1:


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

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.

Then you open an output stream (SourceDataLine) and copy the bytes from the audio stream into that stream.




回答2:


Check out this article - http://download.oracle.com/javase/tutorial/sound/playing.html.

More specifically, read about SourceDataLine and how to set up AudioFormat.



来源:https://stackoverflow.com/questions/1157356/how-to-play-pcm-raw-data-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!