本文共 1824 字,大约阅读时间需要 6 分钟。
本人网上收集的两个java
录音程序,文章出处不记得了.
程序1:
import javax.sound.sampled.*;
import javax.swing.JFrame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Toolkit;
import javax.swing.JPanel;
import java.awt.event.ActionListener;
import javax.sound.sampled.AudioInputStream;
import javax.swing.JButton;
import java.io.File;
import java.util.Vector;
import java.awt.BorderLayout;
import javax.swing.border.EmptyBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.BoxLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.AudioSystem;
import java.io.IOException;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
/**
* @see java录音程序
*
*
*/
public class RecordTest extends JPanel implements ActionListener {
final int bufSize = 16384;
Capture capture = new Capture();
AudioInputStream audioInputStream;
JButton captB;
String fileName = "untitled";
String errStr;
double duration, seconds;
File file;
Vector lines = new Vector();
public RecordTest() {
setLayout(new BorderLayout());
EmptyBorder eb = new EmptyBorder(5, 5, 5, 5);
SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED);
setBorder(new EmptyBorder(5, 5, 5, 5));
JPanel p1 = new JPanel();
p1.setBorder(sbb);
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
JPanel buttonsPanel = new JPanel();
buttonsPanel.setBorder(new EmptyBorder(10, 0, 5, 0));
captB = addButton("Record", buttonsPanel, true);
p1.add(buttonsPanel);
add(p1);
}
public void open() {
}
public void close() {
if (capture.thread != null)
captB.doClick(0);
}
priva
转载地址:http://zaspa.baihongyu.com/