最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
如何捕获音频及输出音频。
时间:2022-07-02 17:24:11 编辑:袖梨 来源:一聚教程网
这是我原来用过的两段代码,输出音频和捕获音频。
构造器里的socket是用来接受来自网络的音频数据。不做网络音频可以去掉它。
希望能与大家分享经验。8-)
import java.io.*;
import javax.sound.sampled.*;
import java.net.*;
/**
* Title: VoiceChat
* Description: 输出音频(放音程序)
* Copyright: Copyright (c) 2001
* Company:
* @author 你猜!
* @version 1.0
*/
class Playback implements Runnable {
final int bufSize = 16384;
SourceDataLine line;
Thread thread;
Socket s;
Playback(Socket s){//构造器 取得socket以获得网络输入流
this.s=s;
}
public void start() {
thread = new Thread(this);
thread.setName("Playback");
thread.start();
}
public void stop() {
thread = null;
}
public void run() {
AudioFormat format =new AudioFormat(8000,16,2,true,true);//AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
构造器里的socket是用来接受来自网络的音频数据。不做网络音频可以去掉它。
希望能与大家分享经验。8-)
import java.io.*;
import javax.sound.sampled.*;
import java.net.*;
/**
* Title: VoiceChat
* Description: 输出音频(放音程序)
* Copyright: Copyright (c) 2001
* Company:
* @author 你猜!
* @version 1.0
*/
class Playback implements Runnable {
final int bufSize = 16384;
SourceDataLine line;
Thread thread;
Socket s;
Playback(Socket s){//构造器 取得socket以获得网络输入流
this.s=s;
}
public void start() {
thread = new Thread(this);
thread.setName("Playback");
thread.start();
}
public void stop() {
thread = null;
}
public void run() {
AudioFormat format =new AudioFormat(8000,16,2,true,true);//AudioFormat(float sampleRate, int sampleSizeInBits, int channels, boolean signed, boolean bigEndian)
相关文章
- 复苏的魔女推图攻略 复苏的魔女新手开荒攻略 07-01
- NEX(NEX币)近期会暴涨? 07-01
- Odaily专访Jarsy:“Pre-IPO领域Robinhood”如何用10美元打破私募投资门槛? 07-01
- 复苏的魔女战斗技巧攻略 复苏的魔女灵魂印记怎么触发 07-01
- 复苏的魔女装备获得攻略 复苏的魔女时空精粹怎么获取 07-01
- 新三国志曹操传孟德新书民兵追乱军攻略 07-01