Results 1 to 10 of 10
  1. #1
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Problem code audio

    Hi, my problem code my class audiotool.java

    warnings:
    PHP Code:
    D:\java>javac AudioTool.java
    AudioTool.java:5: warning: WaveFileWriter is internal proprietary API and may be
     removed in a future release
    import com.sun.media.sound.WaveFileWriter;
                              ^
    AudioTool.java:105: warning: WaveFileWriter is internal proprietary API and may
    be removed in a future release
                   final AudioFileWriter afw = new WaveFileWriter();
                                                   ^
    2 warnings
    my code experiment for jdk 7.07update:

    Java Code:
    import java.io.*;
    
    import javax.sound.sampled.*;
    import javax.sound.sampled.spi.AudioFileWriter;
    import com.sun.media.sound.WaveFileWriter;
    
    public class AudioTool {
       private static  final long serialVersionUID = 1L;
        protected boolean running;
        ByteArrayOutputStream out;
        /**
         * Catturazione Audio - CaptureAudio
         */
        public void captureAudio() {
               try {
                   final AudioFormat format = getFormat();
                   DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
                   final TargetDataLine line = (TargetDataLine)AudioSystem.getLine(info);
                   line.open(format);
                   line.start();
                   Runnable runner = new Runnable() {
                       int bufferSize = (int)format.getSampleRate() * format.getFrameSize();
                       byte buffer[] = new byte[bufferSize];
                   
                       public void run() {
                           out = new ByteArrayOutputStream();
                           running = true;
                           try {
                               while (running) {
                                   int count = line.read(buffer, 0, buffer.length);
                                   if (count > 0) {
                                       out.write(buffer, 0, count);
                                   }
                               }
                               out.close();
    						   line.close();
                           } catch (IOException e) {
                               System.err.println("I/O problems: " + e);
                               System.exit(-1);
                           }
                       }
                   };
                   Thread captureThread = new Thread(runner);
                   captureThread.start();
               } catch (LineUnavailableException e) {
                   System.err.println("Line unavailable: " + e);
                   System.exit(-2);
               }
           }
        /**
            * Suona Audio - playAudio
            */
           public void playAudio() {
               try {
                   byte audio[] = out.toByteArray();
                   InputStream input = new ByteArrayInputStream(audio);
                   final AudioFormat format = getFormat();
                   final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize());
                   DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
                   final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
                   line.open(format);
                   line.start();
               
                   Runnable runner = new Runnable() {
                       int bufferSize = (int) format.getSampleRate() 
                       * format.getFrameSize();
                       byte buffer[] = new byte[bufferSize];
                   
                       public void run() {
                           try {
                               int count;
                               while ((count = ais.read(
                                   buffer, 0, buffer.length)) != -1) {
                                   if (count > 0) {
                                       line.write(buffer, 0, count);
                                   }
                               }
                               line.drain();
                               line.stop();
                               line.close();
                           } catch (IOException e) {
                               System.err.println("I/O problems: " + e);
                               System.exit(-3);
                           }
                       }
                   };
                   Thread playThread = new Thread(runner);
                   playThread.start();
               } catch (LineUnavailableException e) {
                   System.err.println("Line unavailable: " + e);
                   System.exit(-4);
               } 
           }
    
           /**
            * Salva Audio - saveAudio (Path).
            */
           public void saveAudio(String Path) {
               File file = new File(Path);
               try {
                   byte audio[] = out.toByteArray();
                   InputStream input = new ByteArrayInputStream(audio);
                   final AudioFormat format = getFormat();
                   final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize());
                   final AudioFileWriter afw = new WaveFileWriter();
                   afw.write(ais, AudioFileFormat.Type.WAVE, file );
                   ais.close();
                  } catch (IOException e) {
                   System.err.println("Impossibile salvare il file '"+file+"': " + e);
                   System.exit(-4);
               }
           }
           /**
            * Configurazione Audio - 
            */
           private AudioFormat getFormat() {
               float sampleRate = 8000;
               int sampleSizeInBits = 8;
               int channels = 1;
               boolean signed = true;
               boolean bigEndian = true;
               return new AudioFormat(sampleRate,sampleSizeInBits, channels, signed, bigEndian);
           }
    }
    Sorry , my languagge italian.

    My User system Windows 7 64bit ..

    Help help.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Problem code audio

    Moved from Other IDEs.

    What exactly is your question? Evidently your code compiles without errors; does it or doesn't it run without errors?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Problem code audio

    my problem .. remove to warnings for code.. solution?
    thanks.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Problem code audio

    If you need to use a com.sun... proprietary class, then no, you can't remove the warnings.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Problem code audio

    Quote Originally Posted by DarrylBurke View Post
    If you need to use a com.sun... proprietary class, then no, you can't remove the warnings.

    db
    ok, import .* ?? how to import necessary proprietary class?
    thanks.

  6. #6
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Problem code audio

    ok, problem 1 ..:

    Java Code:
    import javax.sound.sampled.*;
    import javax.sound.sampled.spi.*;
    import com.sun.media.sound.*;
    import java.lang.*;
    import java.io.*;
    
       
    public class AudioTool {
       private static  final long serialVersionUID = 1L;
        protected boolean running;
        ByteArrayOutputStream out;
        /**
         * Catturazione Audio - CaptureAudio
         */
        public void captureAudio() {
               try {
                   final AudioFormat format = getFormat();
                   DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
                   final TargetDataLine line = (TargetDataLine)AudioSystem.getLine(info);
                   line.open(format);
                   line.start();
                   Runnable runner = new Runnable() {
                       int bufferSize = (int)format.getSampleRate() * format.getFrameSize();
                       byte buffer[] = new byte[bufferSize];
                   
                       public void run() {
                           out = new ByteArrayOutputStream();
                           running = true;
                           try {
                               while (running) {
                                   int count = line.read(buffer, 0, buffer.length);
                                   if (count > 0) {
                                       out.write(buffer, 0, count);
                                   }
                               }
                               out.close();
    						   line.close();
                           } catch (IOException e) {
                               System.err.println("I/O problems: " + e);
                               System.exit(-1);
                           }
                       }
                   };
                   Thread captureThread = new Thread(runner);
                   captureThread.start();
               } catch (LineUnavailableException e) {
                   System.err.println("Line unavailable: " + e);
                   System.exit(-2);
               }
           }
        /**
            * Suona Audio - playAudio
            */
           public void playAudio() {
               try {
                   byte audio[] = out.toByteArray();
                   InputStream input = new ByteArrayInputStream(audio);
                   final AudioFormat format = getFormat();
                   final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize());
                   DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
                   final SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
                   line.open(format);
                   line.start();
               
                   Runnable runner = new Runnable() {
                       int bufferSize = (int) format.getSampleRate() 
                       * format.getFrameSize();
                       byte buffer[] = new byte[bufferSize];
                   
                       public void run() {
                           try {
                               int count;
                               while ((count = ais.read(
                                   buffer, 0, buffer.length)) != -1) {
                                   if (count > 0) {
                                       line.write(buffer, 0, count);
                                   }
                               }
                               line.drain();
                               line.stop();
                               line.close();
                           } catch (IOException e) {
                               System.err.println("I/O problems: " + e);
                               System.exit(-3);
                           }
                       }
                   };
                   Thread playThread = new Thread(runner);
                   playThread.start();
               } catch (LineUnavailableException e) {
                   System.err.println("Line unavailable: " + e);
                   System.exit(-4);
               } 
           }
    
           /**
            * Salva Audio - saveAudio (Path).
            */
           public void saveAudio(String Path) {
               File file = new File(Path);
               try {
                   byte audio[] = out.toByteArray();
                   InputStream input = new ByteArrayInputStream(audio);
                   final AudioFormat format = getFormat();
                   final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize());
                   final AudioFileWriter afw = new WaveFileWriter();
                   afw.write(ais, AudioFileFormat.Type.WAVE, file );
                   ais.close();
                  } catch (IOException e) {
                   System.err.println("Impossibile salvare il file '"+file+"': " + e);
                   System.exit(-4);
               }
           }
           /**
            * Configurazione Audio - 
            */
           private AudioFormat getFormat() {
               float sampleRate = 8000;
               int sampleSizeInBits = 8;
               int channels = 1;
               boolean signed = true;
               boolean bigEndian = true;
               return new AudioFormat(sampleRate,sampleSizeInBits, channels, signed, bigEndian);
           }
    }
    info warning:

    Java Code:
    D:\java>javac AudioTool.java
    AudioTool.java:106: warning: WaveFileWriter is internal proprietary API and may
    be removed in a future release
                   final AudioFileWriter afw = new WaveFileWriter();
                                                   ^
    1 warning
    
    D:\java>
    help my solution?
    thanks

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Problem code audio

    I've already answered that.

    Did you write the code or is this something you found and copied without understanding it?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Problem code audio

    My code works on java 2.6. With JAVA 2.7 mi says those warnings.

    help?

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Problem code audio

    Quote Originally Posted by jLimone View Post
    My code works on java 2.6. With JAVA 2.7 mi says those warnings.

    help?
    There isn't any Java 2.6 or 2.7, so once again, I have no idea what you're on about.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    jLimone is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Problem code audio

    abandonment classes audiotool.. thank you.

Similar Threads

  1. Audio conferencing using JMF
    By sathishkumar in forum Advanced Java
    Replies: 0
    Last Post: 03-10-2011, 03:02 PM
  2. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  3. Capture audio problem
    By Ang3lo in forum New To Java
    Replies: 0
    Last Post: 01-10-2011, 10:57 PM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. Audio Recorder
    By elizabeth in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 09:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •