Results 1 to 1 of 1
Thread: Capture audio problem
- 01-10-2011, 10:57 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 1
- Rep Power
- 0
Capture audio problem
Hi all, this is my first time in this forum :)
My problem is that i have to do multiples sounds captures with 10sec between witch capture. At the first time the capture is done without any problem but in the other's captures the file '.wav' is created but only with 1kb and no sound is captured. I'm trying to reduce the time since the "this.somG1.Gravacao(this.somG1);" is called and the sound capture really start "this.recorder.start();", so my idea is to "pause" the line and to a capture when i want. Anyone know why this only do a right capture at the first time?
Ty all
This class have the timer to do the 10sec time, the capture constructor and its invocation.
Java Code:private String retorno; private GravarSom grava = new GravarSom(); private File outputFile = new File("c:\\ola.wav"); private AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,44100.0F, 16, 1, 2, 44100.0F, false); private AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE; private DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); private TargetDataLine targetDataLine = null; public void run() { try { Thread t = new Thread(); t.setPriority(MAX_PRIORITY); this.targetDataLine = (TargetDataLine) AudioSystem.getLine(this.info); this.targetDataLine.open(this.audioFormat); this.timer = new Timer(true); this.timer.scheduleAtFixedRate(new RemindTask(this.targetType, this.outputFile, this.targetDataLine), this.tempoGravar, this.tempoRepetir); } catch(Exception e) { System.out.println(e.getMessage()); } } class RemindTask extends TimerTask { private AudioFileFormat.Type targetType; private File outputFile; private TargetDataLine targetDataLine; private GravarSom somG1; private long e; RemindTask(AudioFileFormat.Type targetType2, File outputFile2, TargetDataLine targetDataLine2) { this.targetType = targetType2; this.outputFile = outputFile2; this.targetDataLine = targetDataLine2; } public void run() { //(AudioFileFormat.Type targetType, File outputFile,TargetDataLine targetDataLine) try { this.somG1 = new GravarSom(this.targetDataLine, this.targetType, this.outputFile); Thread t = new Thread(); t.setPriority(MAX_PRIORITY); e = System.currentTimeMillis(); //to check the time since the next function is called and the capture starts this.somG1.Gravacao(this.somG1); System.out.println(e); } catch (Exception ex) { System.out.println(ex.getMessage()); } } }
This is the class to do the capture and starts the capture.
Java Code:package som; import java.io.IOException; import java.io.File; import javax.sound.sampled.TargetDataLine; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioFileFormat; public class GravarSom extends Thread { private TargetDataLine m_line; private AudioFileFormat.Type m_targetType; private AudioInputStream m_audioInputStream; private GravarSom recorder; private File m_outputFile; private int segundosgravacao = 2; private long e; public GravarSom() {} public GravarSom(TargetDataLine line,AudioFileFormat.Type targetType,File file) { m_line = line; m_audioInputStream = new AudioInputStream(line); m_targetType = targetType; m_outputFile = file; } @Override public void start() { m_line.start(); super.start(); } public void stopRecording() { m_line.stop(); //m_line.close(); this way the line will stay alive? } @Override public void run() { try { Thread t = new Thread(); t.setPriority(MAX_PRIORITY); AudioSystem.write(m_audioInputStream,m_targetType,m_outputFile); } catch (IOException e) { e.getMessage(); } } public void Gravacao(GravarSom recorder2) { try { this.recorder = recorder2; //to see when the capture really starts e = System.currentTimeMillis(); this.recorder.start(); this.recorder.sleep(2000); this.recorder.stopRecording(); System.out.println("\t" + e); } catch (Exception ex) { ex.getMessage(); } } }
Similar Threads
-
audio capture from sound card
By kievari in forum Advanced JavaReplies: 0Last Post: 11-03-2010, 07:00 PM -
Capture
By PhQ in forum New To JavaReplies: 7Last Post: 10-17-2010, 05:26 PM -
DVB-T capture
By krato in forum Advanced JavaReplies: 0Last Post: 08-03-2010, 11:46 PM -
playing audio in J-App??
By ashton in forum New To JavaReplies: 3Last Post: 01-30-2009, 08:50 AM -
Audio Recorder
By elizabeth in forum Java AppletsReplies: 1Last Post: 08-06-2007, 09:21 PM


LinkBack URL
About LinkBacks

Bookmarks