当前位置:编程学习 > JSP >>

如何捕获音频及输出音频。

这是我原来用过的两段代码,输出音频和捕获音频。
构造器里的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)
补充:Jsp教程,Application与Applet
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,