17/01/13 12:58
luigi7
Salve, mi sapete dir come posso fare ad calcolare la lunghezza del file registrato al volo?.
Mi potete aiutarmi?
Ho questo codice e vorrei inserire il file che mi rileva quando e lunga la registrazione .
codice:
Mi potete aiutarmi?
Ho questo codice e vorrei inserire il file che mi rileva quando e lunga la registrazione .
codice:
import java.io.*; import javax.sound.sampled.*; public class SimpleAudioRecorder extends Thread { private TargetDataLine m_line; private AudioFileFormat.Type m_targetType; private AudioInputStream m_audioInputStream; private File m_outputFile; public SimpleAudioRecorder(TargetDataLine line, AudioFileFormat.Type targetType, File file) { m_line = line; m_audioInputStream = new AudioInputStream(line); m_targetType = targetType; m_outputFile = file; } public void start() { m_line.start(); super.start(); } public void stopRecording() { m_line.stop(); m_line.close(); } public void run() { try { AudioSystem.write( m_audioInputStream, m_targetType, m_outputFile); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { if (args.length != 1 || args[0].equals("-h")) { System.out.println("SimpleAudioRecorder: usage:"); System.out.println("\tjava SimpleAudioRecorder -h"); System.out.println("\tjava SimpleAudioRecorder <audiofile>"); System.exit(0); } String strFilename = args[0]; File outputFile = new File(strFilename); AudioFormat audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 2, 4, 44100.0F, false); DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat); TargetDataLine targetDataLine = null; try { targetDataLine = (TargetDataLine) AudioSystem.getLine(info); targetDataLine.open(audioFormat); } catch (LineUnavailableException e) { System.out.println("unable to get a recording line"); e.printStackTrace(); System.exit(1); } AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE; SimpleAudioRecorder recorder = new SimpleAudioRecorder( targetDataLine, targetType, outputFile); System.out.println("Press ENTER to start the recording."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } recorder.start(); System.out.println("Recording..."); System.out.println("Press ENTER to stop the recording."); try { System.in.read(); } catch (IOException e) { e.printStackTrace(); } recorder.stopRecording(); System.out.println("Recording stopped."); } }
aaa