hola alguien me podria ayudar a probar este applet.. Estoy tratando de implementarlo en <applet></applet> pero no me corre, bueno nesecito ver ejemplos acerca de mi problema
(grabar voz en web) y este codigo quisiera revisarlo e ir probando .
Creditos del codigo:
Pagina Fuente
Código Javascript
:
Ver originalpackage CapturarMic;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.sound.sampled.*;
public class CapturarMic extends JApplet{
AudioFormat audioFormat;
TargetDataLine targetDataLine;
final JButton captureBtn = new JButton("Capturar");
final JButton stopBtn = new JButton("Parar");
final JPanel btnPanel = new JPanel();
final ButtonGroup btnGroup = new ButtonGroup();
final JRadioButton aiffBtn = new JRadioButton("AIFF");
final JRadioButton waveBtn = new JRadioButton("WAV",true);
public void init( String args[]){
new CapturarMic();
}
public CapturarMic(){
captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
captureBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(false);
stopBtn.setEnabled(true);
captureAudio();
}
}
);
stopBtn.addActionListener(
new ActionListener(){
public void actionPerformed(
ActionEvent e){
captureBtn.setEnabled(true);
stopBtn.setEnabled(false);
targetDataLine.stop();
targetDataLine.close();
}
}
);
getContentPane().add(captureBtn);
getContentPane().add(stopBtn);
btnGroup.add(aiffBtn);
btnGroup.add(waveBtn);
btnPanel.add(aiffBtn);
btnPanel.add(waveBtn);
getContentPane().add(btnPanel);
getContentPane().setLayout(new FlowLayout());
setSize(300,220);
setVisible(true);
}
private void captureAudio(){
try{
audioFormat = getAudioFormat();
DataLine.Info dataLineInfo =
new DataLine.Info(
TargetDataLine.class,
audioFormat);
targetDataLine = (TargetDataLine)
AudioSystem.getLine(dataLineInfo);
new CaptureThread().start();
}catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
private AudioFormat getAudioFormat(){
float sampleRate = 44100.0F;
int sampleSizeInBits = 16;
int channels = 1;
boolean signed = true;
boolean bigEndian = false;
return new AudioFormat(sampleRate,
sampleSizeInBits,
channels,
signed,
bigEndian);
}
class CaptureThread extends Thread{
public void run(){
AudioFileFormat.Type fileType = null;
File audioFile = null;
if(aiffBtn.isSelected()){
fileType = AudioFileFormat.Type.AIFF;
audioFile = new File("prueba.aif");
}else if(waveBtn.isSelected()){
fileType = AudioFileFormat.Type.WAVE;
audioFile = new File("c:/test1/testfermdp.wav");
}
try{
targetDataLine.open(audioFormat);
targetDataLine.start();
AudioSystem.write(
new AudioInputStream(targetDataLine),
fileType,
audioFile);
}catch (Exception e){
e.printStackTrace();
}
}
}
}
Aqui tengo otro codigo q encontre surfeando por casi toda la red.. a ver quien me da una mano..
Creditos del codigo:
Pagina fuente
Código Javascript
:
Ver originalimport java.io.File;
import javax.sound.sampled.*;
public class Main {
AudioFileFormat.Type aFF_T = AudioFileFormat.Type.WAVE;
AudioFormat aF = new AudioFormat(8000.0F, 16, 1, true, false);
TargetDataLine tD;
File f = new File("Grabacion.wav");
public Main() {
try {
DataLine.Info dLI = new DataLine.Info(TargetDataLine.class,aF);
tD = (TargetDataLine)AudioSystem.getLine(dLI);
new CapThread().start();
System.out.println("Grabando durante 10s...");
Thread.sleep(10000);
tD.close();
}catch (Exception e) {}
}
class CapThread extends Thread {
public void run() {
try {
tD.open(aF);
tD.start();
AudioSystem.write(new AudioInputStream(tD), aFF_T, f);
}catch (Exception e){}
}
}
public static void main(String[] args) { new Main(); }
}