最新下载
热门教程
- 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)
相关文章
- 7月3日XRP(瑞波币)价格预测 07-03
- 剑星地图怎么打开-剑星地图打开方式 07-03
- 剑星钓鱼换鱼饵怎么操作-剑星钓鱼换鱼饵操作要点 07-03
- 币圈:Gate.io LABS孵化器和Startup首发空投币领取教学 07-03
- Celsius获准起诉Tether,索赔40亿美元 07-03
- 剑星水底工厂宝箱怎么激活-剑星水底工厂宝箱激活攻略 07-03