Wtk 2.5 : Manager.createPlayer("capture://audio"); throws IO.Exception

hi
in wtk 2.5, i am creating the player with locator "capture://audio" for recording
purpose ...
But it gives java.IO.Exception in Manager.createPlayer(locator);
fuction.
Is there any way to come out of this problem?
Waiting for reply..

Hi
Please try the code below
Player player = Manager.createPlayer("capture://audio");
player.realize ();
player.start();
Thread.currentThread().sleep(10000*2);
player.close();
try this

Similar Messages

  • CreatePlayer --  //capture:audio

    Hi
    MMAPI JSR (135) latest documentation , explains a way to capture audio from microphone in various formats , am able to save it in pcm format but gsm or ulaw gives error.
    encoding="pcm / gsm / ulaw " of which pcm is default , But upon specifying gsm or ulaw as parameters , I get a runtime error in class WavCapture , I decompiled this class to see it clearly dosent support gsm and ulaw inside
    java.io.IOException: Invalid locator
    at com.sun.mmedia.protocol.WavCapture.connect(+16)
    at javax.microedition.media.Manager.createDataSource(+118)
    at javax.microedition.media.Manager.createPlayer(+93)
    at socket.recordData.run(+5)
    Then why does the documentation says about gsm / ulaw
    Would really appretiate for any tips .

    I get an error if I try to do any kind of settings to capture://audio like this:
    player = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8&channels=1");
    It just does not accept it at run time. I even upgraded my system to XP and still does not see it.
    Without settings like this (capture://audio), I am able go through start record, stop record, commit, and saving to RMS. I am writing to ByteArrayOutputStream. I don't think I am capturing anything from the microphone. Because the size of the array is 0.
    I appreciate any thoughts or feedback on this one.
    Thanks,
    Elian

  • WTK SDK 3.0 for OSX problem with capturing audio, emulator

    Hello all,
    i'm installed the WTK SDK 3.0 for osx and everything works well. Some test applications also work.
    Now I'm trying to realize my project and get strange error.
    I want to capture some audio form the microphone. But when i do so the Emulator strikes with this error:
    javax.microedition.media.MediaException: Player cannot be created for capture://audio
    so i tried this: System.getProperty("supports.recording") and it returns false. But when i read over the specification of the WTK it says that it should support the Audio capturing. Is this error based on the implementation of the WTK on OSX or have some Windows users also the same problem?
    here is my implementation for the Audio recording:
    public void commandAction(Command comm, Displayable disp){
            if(comm==recordCommand){
                try{
                    p = Manager.createPlayer("capture://audio");
                    p.realize();
                    RecordControl rc = (RecordControl)p.getControl("RecordControl");
                    ByteArrayOutputStream output = new ByteArrayOutputStream();
                    rc.setRecordStream(output);
                    rc.startRecord();
                    p.start();
                    messageItem.setText("recording...");
                    Thread.currentThread().sleep(5000);
                    messageItem.setText("done!");
                    rc.commit();
                    recordedSoundArray = output.toByteArray();
                    p.close();
                } catch (IOException ioe) {
                    errorItem.setLabel("Error");
                    errorItem.setText(ioe.toString());
                } catch (MediaException me) {
                    errorItem.setLabel("Error");
                    errorItem.setText(me.toString());
                } catch (InterruptedException ie) {
                    errorItem.setLabel("Error");
                    errorItem.setText(ie.toString());
            } else if(comm == playCommand) {
                try {
                    ByteArrayInputStream recordedInputStream = new ByteArrayInputStream
                          (recordedSoundArray);
                    Player p2 = Manager.createPlayer(recordedInputStream,"audio/basic");
                    p2.prefetch();
                    p2.start();
                }  catch (IOException ioe) {
                    errorItem.setLabel("Error");
                    errorItem.setText(ioe.toString());
                } catch (MediaException me) {
                    errorItem.setLabel("Error");
                    errorItem.setText(me.toString());
        any help would be grateful!
    thx and greetings
    Edited by: nYmou on Jun 1, 2010 3:44 AM

    Note: This thread was originally posted in the [Sun Java Wireless Toolkit|http://forums.sun.com/forum.jspa?forumID=82] forum, but moved to this forum for closer topic alignment.

  • Variable bitrate while capturing audio although rate is set in player URL

    Hello.
    I'm building an application that requires me to calculate the time between to amplitude peaks in an audio stream recorded on the spot using JSR-135. To calculate the time difference I figured I could simply count how many samples that were sampled between the amplitude peaks. To do this I need to know how many samples per second the audio was recorded in. I thought that setting the rate parameter in the player URL (capture://audio?encoding=pcm&rate=*8000*&bits=8&channels=1) would do this, but when I commit the RecordControl I don't always get the same amount of bytes even though I always record for the same amount of time. I use the following code to record the audio stream:
    Player player = Manager.createPlayer("capture://audio?encoding=pcm&rate=8000&bits=8&channels=1");
    player.realize();
    RecordControl recordControl = (RecordControl) player.getControl("RecordControl");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    recordControl.setRecordStream(outputStream);
    recordControl.startRecord();
    player.start();
    Thread.sleep(1000); // Record for one second
    recordControl.stopRecord();
    recordControl.commit();
    player.stop();
    player.deallocate();
    System.out.println(outputStream.toByteArray().length + " samples");Running the code four times gave me four different bitrates, or length of returned byte array; 8724, 8476, 7044 and 8972. Why is this? What have I missed?
    Kind Regards.
    Edited by: enoook on Sep 7, 2009 4:24 AM

    also i want to specify something............if am using loopback address,the sender and receiver(in this typical code,capture and receive files) ought to have diff. ports( i suppose as their ips are already same)
    or am i wrong???
    i have given same ports.......i had tried once with diff. ports........miraculously perhaps it worked (the sound was echoed through my headphone),....but next time when i tried i failed......and still failing........any suggestions please waiting eagerly

  • Supported formats for capturing audio

    I need to capture audio in PCM format.
    According to the JDE 4.6.0 Multimedia Guide:
    "The BlackBerry® smartphone uses two formats to record audio: Adaptive Multi-Rate (AMR) and 8 kHz mono-16-bit pulse code modulation (PCM). By default, the format is AMR.
    PCM: capture://audio?encoding=pcm or capture://audio?encoding=audio/basic"
    However, when I run the code:
    Manager.createPlayer( "capture://audio?encoding=pcm" );
    This works on a Pearl 8100, but on a Pearl 8330, I get a MediaException, with the error:
    Unsupported record encoding type
    Do all handsets support PCM encoding? If not, where would I find out the capabilities of the different models?

    Supported audio formats by BlackBerry -
     The following audio formats (including extensions) are supported:
    ACC - audio compression formats AAC, AAC+, and EAAC+
    AMR - Adaptive Multi Rate-Narrow Band (AMR-NB) speech coder standard Supported AMR-NB rates are 4.75 KBps, 5.15 KBps, 5.9 KBps, 6.7 KBps, 7.4 KBps, 7.95 KBps, 10.2 KBps, and 12.2 KBps. AMR
    files must conform to the standards specified in the Internet
    Engineering Task Force (IETF) Request for Comments (RFC) document
    RFC3267, Section 5, on the Internet RFC Archive web site.
    MIDI - Polyphonic MIDI (.mid, .midi, or .smf)
    MP3 - encoded using MPEG Part 1 and Part 2 audio layer 3 Supported sample rates are 16kHz, 22.050kHz, 24kHz, 32kHz, 44.1kHz, and 48kHz.
    WAV
    - supports sample rates of 8 kHz, 16 kHz, 22.05 kHz, 32 kHz, 44.1 kHz,
    and 48 kHz with 8-bit and 16-bit depths in mono or stereo WAV files
    created using audio codec GSM6.10 are supported. However, BlackBerry
    8830 series smartphones do not natively support Global Systems for
    Mobile Communications® (GSM®) encoding and require the BlackBerry
    Attachment Service from either the BlackBerry® Enterprise Server or the
    BlackBerry® Internet Service. See KB13547 for more information. Note:
    Playback of WAV files received as email message attachments requires
    BlackBerry Enterprise Server software version 4.1 Service Pack 2
    (4.1.2). Note: If the BlackBerry smartphone
    user has a BlackBerry Internet Service 2.3 account with BlackBerry
    Device Software 4.2 or later, WAV voice mail files will work.
    Windows Media Audio (WMA 9) Standard Profile Decoder WMA 10 Professional M0 Profile Decoder WMA 9 Profile Decoder and WMA 10 M0 Profile Decoder are only supported by BlackBerry Device Software 4.2.1 or later. See KB05419 for more information.
    The
    following audio file extensions are also supported (depending on
    BlackBerry smartphone model and BlackBerry Device Software version):
    .avi containing PCM, MP3, AAC, AAC+, eAAC+, H.263, MPEG4-SP, MPEG4-ASP, uLaw/aLaw, GSM610
    .3gp containing MP3, AMR-NB, AAC, AAC+, eAAC+, H.263, MPEG4-SP, MPEG4-ASP, uLaw/aLaw, AMR-NB
    .mp4 containing MP3, AMR-NB, AAC, AAC+, eAAC+, H.263, MPEG4-SP, MPEG4-ASP, uLaw/aLaw, AMR-NB
    >.mov containing MP3, AMR-NB, AAC, AAC+, eAAC+, H.263, MPEG4-SP, MPEG4-ASP, uLaw/aLaw, AMR-NB
    .wmv containing WMV, WMA9/10Pro
    .aac and .m4a containing AAC, AAC+, eAAC+
    .wav containing PCM, uLaw/aLaw, GSM610
    Note:
    Support is available for streaming stereo audio over a Bluetooth®
    connection (A2DP and AVRCP Bluetooth profiles) on the following
    BlackBerry smartphone models:
    BlackBerry® 8800 Series smartphones (running BlackBerry Device Software 4.2.2 or later)
    BlackBerry Curve 8300 Series smartphone (running BlackBerry Device Software 4.2.2 or later)
    BlackBerry Pearl 8100 Series smartphones (running BlackBerry Device Software 4.2.2 or later)
     Note: DRM (Digital Rights Management) copyright protected files will not play on BlackBerry smartphones.
    Source: KB05482 
    tanzim                                                                                  
    If your query is resolved then please click on “Accept as Solution”
    Click on the LIKE on the bottom right if the post deserves credit

  • I am capturing audio(my voice)and want to transmit to other machine in LAN.

    I am capturing audio(my voice)and want to transmit to other machine in LAN...USING JMF...
    But few errors are coming like-----
    ----java.lang.Error: Error opening DSound for capture
    ----javax.media.NoDataSourceException: Error instantiating class: com.sun.media.protocol.dsound.DataSource : java.lang.Error: Error opening DSound for capture
    at javax.media.Manager.createDataSource(Manager.java:1017)
    at MediaTransmitter.main(MediaTransmitter.java:69)
    can some one tell me how should i transmit voice to other ip address????
    My transmitter.java is program is :---
    import javax.media.*;
    import javax.media.control.*;
    import javax.media.protocol.*;
    import javax.media.format.*;
    import java.io.IOException;
    import java.io.File;
    import java.util.Vector;
    public class MediaTransmitter {
    private MediaLocator mediaLocator = null;
    private DataSink dataSink = null;
    private Processor mediaProcessor = null;
    private static final Format[] FORMATS = new Format[] {
    new AudioFormat(AudioFormat.ULAW_RTP)};
    private static final ContentDescriptor CONTENT_DESCRIPTOR =
    new ContentDescriptor(ContentDescriptor.RAW_RTP);
    public MediaTransmitter(MediaLocator locator) {
    mediaLocator = locator;
    public void startTransmitting() throws IOException {
    mediaProcessor.start();
    dataSink.open();
    dataSink.start();
    public void stopTransmitting() throws IOException {
    dataSink.stop();
    dataSink.close();
    mediaProcessor.stop();
    mediaProcessor.close();
    public void setDataSource(DataSource ds) throws IOException,
    NoProcessorException, CannotRealizeException, NoDataSinkException {
    mediaProcessor = Manager.createRealizedProcessor(
    new ProcessorModel(ds, FORMATS, CONTENT_DESCRIPTOR));
    dataSink = Manager.createDataSink(mediaProcessor.getDataOutput(),
    mediaLocator);
    public static void main(String[] args) {
    try {
    MediaLocator locator = new MediaLocator("rtp://192.168.1.75:333/audio");
    MediaTransmitter transmitter = new MediaTransmitter(locator);
    System.out.println("-> Created media locator: '" +
    locator + "'");
    Vector devices=CaptureDeviceManager.getDeviceList ( null );
    CaptureDeviceInfo cdi= (CaptureDeviceInfo) devices.elementAt ( 0 );
    DataSource source = Manager.createDataSource(cdi.getLocator());
    transmitter.setDataSource(source);
    System.out.println("-> Set the data source on the transmitter");
    transmitter.startTransmitting();
    System.out.println("-> Transmitting...");
    System.out.println(" Press the Enter key to exit");
    System.in.read();
    System.out.println("-> Exiting");
    transmitter.stopTransmitting();
    } catch (Throwable t) {
    t.printStackTrace();
    System.exit(0);
    }

    OT
    Thanks for the suggestion . As soon as they hand me my laptop at the store  in 45 minutes time I shall try the disable and then re boot as you suggest.
    so far they sent me this; Disk  has no problem.They may have more to say to me re the flash drive and results of storage diagnostics and ASDs ( what is this? ) when I see them .
    The case repair is redundant to the problem I am having  but if they give me a new one worth $399 i will not complain,eh.
    Problem Description/Diagnosis
    Issue: MacBook Pro is running extremely slow. Specifically IPhoto
    Steps to Reproduce: Attempted to repair disk, no issues found.
    Cosmetic Condition: Scratches to enclosure and clamshell.
    Proposed Resolution: Tighten MagSafe board. Run storage diagnostics and ASDs if no trouble found with flash drive.
    Estimated Turn Around Time: We'll call you in 3 - 5 days
    Mac OS Version: 10.10.x
    Hard Drive Size: 251 GB
    Memory Size: 8 GB
    iLife Version: Unknown
    Employee 1178255246
    Repair Estimate
    Item Number
    Description
    Price
    Amount Due
    Customer KBB
    661-8154
    Housing, Top Case with Battery
    $ 399.00
    $ 0.00
    S1490LL/A
    Hardware Repair Labor
    $ 39.00
    $ 0.00
    Tax
    $ 0.00
    Total
    $ 438.00
    $ 0.00

  • Capturing audio from soundcard!

    Can anybody help me? When i compile this code no problems appears, however when i execute the program this is shown to:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    c:\Sun\SDK\jdk\bin>java JCapture
    javax.media.NotConfiguredError: setContentDescriptor cannot be called before con
    figured
    at com.sun.media.ProcessEngine.setContentDescriptor(ProcessEngine.java:3
    42)
    at com.sun.media.MediaProcessor.setContentDescriptor(MediaProcessor.java
    :123)
    at JCapture.doIt(JCapture.java:69)
    at JCapture.main(JCapture.java:27)
    Exception in thread "main" javax.media.NotConfiguredError: setContentDescriptor
    cannot be called before configured
    at com.sun.media.ProcessEngine.setContentDescriptor(ProcessEngine.java:3
    42)
    at com.sun.media.MediaProcessor.setContentDescriptor(MediaProcessor.java
    :123)
    at JCapture.doIt(JCapture.java:69)
    at JCapture.main(JCapture.java:27)
    The code is this:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.Iterator;
    import java.util.Vector;
    import javax.media.CaptureDeviceInfo;
    import javax.media.CaptureDeviceManager;
    import javax.media.DataSink;
    import javax.media.Manager;
    import javax.media.MediaLocator;
    import javax.media.Processor;
    import javax.media.datasink.DataSinkEvent;
    import javax.media.datasink.DataSinkListener;
    import javax.media.datasink.EndOfStreamEvent;
    import javax.media.protocol.DataSource;
    import javax.media.protocol.FileTypeDescriptor;
    public class JCapture
    CaptureDeviceInfo captureDeviceInfo = null;
    DataSink dataSink = null;
    public static void main(String[] args)
    JCapture jCapture = new JCapture();
    jCapture.doIt();
    System.exit(0);
    private void doIt()
    // retrieve list of available capture devices
    Vector vector = CaptureDeviceManager.getDeviceList(null);
    Iterator it = vector.iterator();
    while(it.hasNext())
    CaptureDeviceInfo deviceInfo = (CaptureDeviceInfo)it.next();
    if("DirectSoundCapture".equals(deviceInfo.getName()))
    captureDeviceInfo = deviceInfo;
    break;
    // exit if no capture devices found
    if(captureDeviceInfo == null)
    System.err.println("No capture devices found!");
    System.exit(-1);
    try
    // get media locator from capture device
    MediaLocator mediaLocator = captureDeviceInfo.getLocator();
    // create processor
    Processor p = Manager.createProcessor(mediaLocator);
    // configure the processor
    p.configure();
    // set the content type
    p.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.WAVE));
    // realise the processor
    p.realize();
    // get the output of processor
    DataSource dataSource = p.getDataOutput();
    // create medialocator with output file
    MediaLocator dest = new MediaLocator("file://c:\\myFile.wav");
    // create datasink passing in output source and medialocator specifying our output file
    dataSink = Manager.createDataSink(dataSource,dest);
    // create dataSink listener
    dataSink.addDataSinkListener
    // anonymous inner class to handle DataSinkEvents
    new DataSinkListener()
    // if end of media, close data writer
    public void dataSinkUpdate(DataSinkEvent dataEvent)
    // if capturing stopped, close DataSink
    if(dataEvent instanceof EndOfStreamEvent)
    dataSink.close();
    // open the datasink
    dataSink.open();
    // start the datasink
    dataSink.start();
    // start the processor
    p.start();
    getConsolePress();
    // stop the processor
    p.stop();
    // close the processor
    p.close();
    catch(Exception e)
    e.printStackTrace();
    System.exit(-1);
    System.out.println("Finished!!");
    public void getConsolePress() throws Exception
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader input = new BufferedReader(isr);
    String line;
    System.out.println("Press x to stop capturing...");
    while (!(line = input.readLine()).equals("x"))
    System.out.println("Press x to stop capturing...");
    return;
    }

    I compiled and ran your code and saw
    the error you described, but could not fix it ..
    OTOH - here is some code I was mucking
    about with recently (it was adapated from an
    example I found on a forum, but I cannot recall
    where), it seemed to work quite well, without
    ever creating a processor.
    Maybe that might help?
    import java.awt.FlowLayout;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JButton;
    import javax.swing.JOptionPane;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.InputStream;
    import java.io.FileOutputStream;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioFileFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.TargetDataLine;
    public class AudioRecorder extends JFrame{
      boolean stopCapture = false;
      ByteArrayOutputStream byteArrayOutputStream;
      AudioFormat audioFormat;
      TargetDataLine targetDataLine;
      AudioInputStream audioInputStream;
      SourceDataLine sourceDataLine;
      File file;
    //  AudioFileFormat.Type fileType;
      /** The recorder will request enough memory for this lengh
      of time of audio recording.More might be possible.*/
      static int minutes = 4;
      /** channels - 1 for mono, 2 for stereo. */
      static int channels = 2;
      /** bytes - 1 means 8 bit, 2 means 16 bit, 3 means 24 bit. */
      static int bytes = 2;
      /** Samples per second, sample rate in Hertz. */
      static int samplerate = 44100;
      /** Default size of the audio array before expansion.
      Guarantees there is 'minutes' of memory for recording
      'bytes' of sound depth in 'channels' at 'samplerate'. */
      static int size = samplerate*channels*bytes*60*minutes;
      /** Make the temp buffer, for this fraction of a second. */
      static int timeperiod = 20;
      /** An arbitrary-size temporary holding
      buffer
      enough for 3 minutes of sampling in
      stereo at 16 bit, 44100Hz */
      //static byte tempBuffer[];
      static byte tempBuffer[] = new byte[samplerate*channels*bytes/timeperiod];
      public static void main(
        String args[]){
        if (args.length==0) {
          new AudioRecorder(null);
        } else {
          new AudioRecorder(args[0]);
      }//end main
      public AudioRecorder(String outputFileName){//constructor
        setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        setLocation(100,50);
        final JButton captureBtn =
          new JButton("Capture");
        final JButton stopBtn =
          new JButton("Stop");
        final JButton playBtn =
          new JButton("Save");
        captureBtn.setEnabled(true);
        stopBtn.setEnabled(false);
        playBtn.setEnabled(false);
        captureBtn.addActionListener(
          new ActionListener(){
            public void actionPerformed(
            ActionEvent e){
              captureBtn.setEnabled(false);
              stopBtn.setEnabled(true);
              playBtn.setEnabled(false);
              captureAudio();
        getContentPane().add(captureBtn);
        stopBtn.addActionListener(
          new ActionListener(){
            public void actionPerformed(
              ActionEvent e){
              captureBtn.setEnabled(true);
              stopBtn.setEnabled(false);
              playBtn.setEnabled(true);
              //Terminate the capturing of
              // input data from the
              // microphone.
              stopCapture = true;
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()
        getContentPane().add(stopBtn);
        playBtn.addActionListener(
          new ActionListener(){
            public void actionPerformed(
              ActionEvent e){
              //Play back all of the data
              // that was saved during
              // capture.
              saveAudio();
            }//end actionPerformed
          }//end ActionListener
        );//end addActionListener()
        getContentPane().add(playBtn);
        getContentPane().setLayout(new FlowLayout());
        setTitle("IMAR");
        setDefaultCloseOperation(
          EXIT_ON_CLOSE);
        setSize(250,70);
        setVisible(true);
        if ( outputFileName==null ) {
          JFileChooser fc = new JFileChooser();
          int returnVal = fc.showSaveDialog(null);
          if(returnVal == JFileChooser.APPROVE_OPTION) {
            outputFileName = fc.getSelectedFile().toString();
          } else {
            outputFileName = "default.wav";
        file = new File(outputFileName);
        FileOutputStream fout;
        try {
          fout=new FileOutputStream(file);
        } catch (FileNotFoundException e1) {
          e1.printStackTrace();
      }//end constructor
      //This method captures audio input
      // from a microphone and saves it in
      // a ByteArrayOutputStream object.
      private void captureAudio(){
        try{
          //Get everything set up for
          // capture
          audioFormat = getAudioFormat();
    /*      AudioFormat.Encoding[] encodings =
            AudioSystem.getTargetEncodings(audioFormat);
          for(int ii=0; ii<encodings.length; ii++) {
            System.out.println( encodings[ii] );
          DataLine.Info dataLineInfo =
            new DataLine.Info(
              TargetDataLine.class, audioFormat);
          targetDataLine = (TargetDataLine)
            AudioSystem.getLine(dataLineInfo);
          targetDataLine.open(audioFormat);
          targetDataLine.start();
          System.out.println( "AR.cA: " + targetDataLine );
          audioInputStream = new
            AudioInputStream(targetDataLine);
          //Create a thread to capture the
          // microphone data and start it
          // running.It will run until
          // the Stop button is clicked.
          CaptureThread ct = new CaptureThread();
          Thread captureThread =
            new Thread(ct);
          captureThread.start();
        } catch (Exception e) {
          e.printStackTrace();
          System.exit(0);
        }//end catch
      }//end captureAudio method
      //This method plays back the audio
      // data that has been saved in the
      // ByteArrayOutputStream
      private void saveAudio() {
        try{
          //Get everything set up for
          // playback.
          //Get the previously-saved data
          // into a byte array object.
          byte audioData[] =
            byteArrayOutputStream.
            toByteArray();
          //Get an input stream on the
          // byte array containing the data
          InputStream byteArrayInputStream
            = new ByteArrayInputStream(audioData);
          AudioFormat audioFormat =
            getAudioFormat();
          AudioInputStream audioInputStreamTemp =
            new AudioInputStream(
              byteArrayInputStream,
              audioFormat,
              audioData.length/audioFormat.
                getFrameSize());
          audioInputStream =
            AudioSystem.getAudioInputStream(
              AudioFormat.Encoding.PCM_SIGNED,
              audioInputStreamTemp );
          DataLine.Info dataLineInfo =
            new DataLine.Info(
            SourceDataLine.class,
            audioFormat);
          sourceDataLine = (SourceDataLine)
            AudioSystem.getLine(dataLineInfo);
          sourceDataLine.open(audioFormat);
          sourceDataLine.start();
          //Create a thread to play back
          // the data and start it
          // running.It will run until
          // all the data has been played
          // back.
          Thread saveThread =
            new Thread(new SaveThread());
          saveThread.start();
        } catch (Exception e) {
          e.printStackTrace();
          System.exit(0);
        }//end catch
      }//end playAudio
      //This method creates and returns an
      // AudioFormat object for a given set
      // of format parameters.If these
      // parameters don't work well for
      // you, try some of the other
      // allowable parameter values, which
      // are shown in comments following
      // the declarations.
      private AudioFormat getAudioFormat(){
        float sampleRate = 44100.0F;
        //8000,11025,16000,22050,44100
        int sampleSizeInBits = channels*8;
        //8,16
    //    int channels = 2;
        //1,2
        boolean signed = true;
        //true,false
        boolean bigEndian = false;
        //true,false
        return new AudioFormat(
          sampleRate,
          sampleSizeInBits,
          channels,
          signed,
          bigEndian);
      }//end getAudioFormat
      //===================================//
      /** Inner class to capture data from
      microphone */
      class CaptureThread extends Thread{
        public void run(){
          byteArrayOutputStream =
             new ByteArrayOutputStream(size);
          stopCapture = false;
          try{//Loop until stopCapture is set
            // by another thread that
            // services the Stop button.
            while(!stopCapture){
              //Read data from the internal
              // buffer of the data line.
              int cnt = targetDataLine.read(
                tempBuffer,
                0,
                tempBuffer.length);
              if(cnt > 0){
                //Save data in output stream
                // object.
                byteArrayOutputStream.write(
                  tempBuffer, 0, cnt);
              }//end if
            }//end while
            byteArrayOutputStream.close();
          }catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
          }//end catch
        }//end run
      }//end inner class CaptureThread
      /** Inner class to play back the data
      that was saved. */
      class SaveThread
        extends Thread {
        public void run(){
          try{
            if (AudioSystem.isFileTypeSupported(
              AudioFileFormat.Type.WAVE,
                audioInputStream)) {
              AudioSystem.write(audioInputStream,
                AudioFileFormat.Type.WAVE, file);
            JOptionPane.showMessageDialog(null,"Clip Saved!");
          } catch (Exception e) {
            e.printStackTrace();
            System.exit(0);
          }//end catch
        }//end run
      }//end inner class PlayThread
      //===================================//
    }//end outer class AudioCapture.java

  • Capture Audio from Line-In or Mic (no CaptureDevice)

    Hi,
    I'm trying to capture Audio Data from my SoundCard, but I don't know how to find the correct CaptureDevice (or even ANY CaptureDevice...)
    I'm using JMF 2.1.1 (all-java) this is my test code:
         public static void main(String[] args) {
              try {
                   //Fallback error sound
                   MediaLocator errorSound = new MediaLocator(new File("error.wav").toURL());
                   //Find Capture Device
                   Format captureFormat = new AudioFormat(AudioFormat.LINEAR, 44100, 16, 2);
                   boolean capDevFound = false;
                   CaptureDeviceInfo di = null;
                   Vector deviceList = CaptureDeviceManager.getDeviceList(captureFormat);
                   if (deviceList.size() > 0) {
                        System.out.println("- devices -");
                        for (int i=0; i<deviceList.size(); i++) {
                             di = (CaptureDeviceInfo)deviceList.get(i);
                             System.out.println(di.getName());
                        di = (CaptureDeviceInfo)deviceList.firstElement();
                        capDevFound = true;
                   } else {
                        System.out.println("No Capture Device found");
                   //Playback captured audio or error sound
                   MediaLocator ml = capDevFound
                                         ? di.getLocator()
                                         : errorSound;
                   DataSource ds = Manager.createDataSource(ml);
                   Player pl = Manager.createPlayer(ds);
                   ControllerState playerState = new ControllerState();
                   playerState.exitOnEOM = true;
                   //The Realizer class implements the blocking realize and prefetching I found in the tutorials...
                   Realizer realizer = new Realizer(playerState);
                   pl.addControllerListener(realizer);
                   realizer.realizePlayer(pl);
                   realizer.prefetchPlayer(pl);
                   System.out.println("- start -");
                   pl.start();
              } catch (Exception e) {
                   e.printStackTrace();
         }I always get a "no capture device found" and hear my error sound!
    Could a wrong Format in getDeviceList(..) be the reason for this? Or should I better use a native version of JMF instead of the pure java one?
    Any Hints?
    Thanks in advance,
    lupo

    From the JMF javaDocs for CaptureDeviceManager
    public static java.util.Vector getDeviceList(Format format)Gets a list of CaptureDeviceInfo objects that correspond to devices that can capture data in the specified Format. If no Format is specified, this method returns a list of CaptureDeviceInfo objects for all of the available capture devices
    So
    CaptureDeviceManager.getDeviceList(null);
    will return ALL available capture devices - this is as described in SUN code examples & does indeed work
    re
    javax.media.format.AudioFormat
    does not provide a parameterless constructor
    OOPS sorry - didn't check before posting

  • Capture Audio in gsm or ulaw format using MMAPI

    Hi ,
    I have tried to use the latesr MMAPI with the Java Tool Kit latest versoin
    My Requirement is to capture voice through a Manager in "gsm" and "ulaw format" , I have seen examples in javax.microedition.media.Manager documentation like that came along latest version of J2ME wireless 2.1 toolkit .
         capture://audio (default audio)
         capture://audio?encoding=pcm (default audio in PCM format)
    when i try to give
         capture://audio?encoding=gsm or ulaw i get runtime error saying invalid locators
         Can somebody please help me to figure how i can save voice in gsm or ulaw format into a wav file , thru emulator , i am able to save in PCM i.e. the default format .
         Any tips would be highly appretiated.

    Hi ,
    I have used this Mobile Media API (JSR-135) latest documentation that comes with WTK 2.0 and documentation of javax.microedition.media.Manager Class which says
    1. Locators for Live-media Capture
    The locators for capturing live media are defined by the following syntax in Augmented BNF notations:
    "capture://" device [ "?" params]
    A. Identifying the type or the specific name of the device:
    device = "audio" / "video" / "audio_video" / dev_name
    dev_name = alphanumeric
    alphanumeric = 1*( ALPHA / DIGIT )
    B. Describing the media and capture parameters:
    params = audio_params / video_params /
    audio_video_params / custom_params
    C. Describing the audio media format:
    audio_params = audio_param *( "&" audio_param )
    audio_param = 1*( "encoding=" audio_enc / "rate=" rate /
    "bits=" bits / "channels=" channels /
    "endian=" endian / "signed=" signed )
    audio_enc = "pcm" / "ulaw" / "gsm"
    rate = "96000" / "48000" / "44100" / "22050" / "16000" /
    "11025" / "8000"
    bits = "8" / "16" / "24"
    channels = pos_integer
    endian = "little" / "big"
    signed = "signed" / "unsigned"
    pos_integer = 1*DIGIT
    Example:
    encoding=pcm&rate=11025&bits=16&channels=1
    In point "C" it clearly tells that encoding format pcm/gsm/ulaw can be used . But i get invalid locator at runtime for gsm and ulaw format .
    I am not sure wether the Emulator is not supporting this format or whats the cause , i am basically recording the voice from mic into a wav file .
    Thanks
    Sameer

  • J2ME MMAPI: capture audio in AMR with given bitrate

    Colleagues,
    I'm facing issue while trying to record audio in AMR. While I successfully record audio in AMR 12.2 kbps I can not change the bitrate. It is always 12.2 kbps regardless of what I specify in media locator string.
    Could anybody help me to figure out what parameters should I specify to record audio, for example, in AMR 4.75 kbps?
    Thank you in advance.

    The code is:
    String uri = "capture://audio?encoding=amr&rate=8000&bits=16";
    // Get player object
    _player = Manager.createPlayer(uri);
    _player.realize();
    // Get Record Control to be able to record audio
    RecordControl  rc = (RecordControl)_player.getControl("RecordControl");
    // Set destination file
    rc.setRecordLocation(rec_file);
    // Begin recording from standard input
    rc.startRecord();
    // Transfer audio from microphone to standard input
    _player.start();Actually AMR bitrate depends on the size of frame which repeats each 20 ms. For 4.75 kbit/s frame is 95 bits long.
    I'm not sure how to specify this by 'rate' and 'bits' parameters. I already tried some combinations but in vain. The default for my Motorola Z3 is 12.2 kbit/s. Maybe it even does not support capturing in other bit rates (I'm not sure), though it is able to play AMR files of other bit rates.
    Maybe you can point me to the emulator which supports AMR capturing in different bit rates?
    Thank you for interest in my question.

  • Problem in Manager.createPlayer()

    hi to all,i have some problem in javax.media.Player interface.
          javax.swing.JFileChooser jfc=new javax.swing.JFileChooser();
                             int res=jfc.showOpenDialog(null);
                             if(res==javax.swing.JFileChooser.APPROVE_OPTION){
                                  URL mediaURL = null;
                                try
                                   // get the file as URL
                                   mediaURL = new URL("file",null,jfc.getSelectedFile().getAbsolutePath());
                                } // end try
                                catch ( MalformedURLException malformedURLException )
                                   System.err.println( "Could not create URL for the file" );
                                javax.media.MediaLocator ml=new javax.media.MediaLocator(mediaURL);
                                try {
                                     player = Manager.createRealizedPlayer(ml);
                                  } catch (NoPlayerException noplayer) {
                                       System.out.println("No player "+noplayer);
                                       // TODO: handle exception
                                  }catch(CannotRealizeException cant){
                                       System.out.println("Cannot "+cant);
                                  catch(java.io.IOException ioe){
                                       System.out.println("Error "+ioe);
    In above code,
    player=Manager.createPlayer(ml);
    is not working , it shows exception : NoPlayer exception is raised.
    What can i do for run the video file. Any one give me good suggestion for me..
    Reply as soon as possible,
    Thanking you,
    Azharudeen Ahmed M.Sc
    [email protected]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    >
    how to use all the formats in JMF....>Ahhh.. (sighs) the 'learning curve of media'.
    The answer is both simple (to say) and complex (to program).
    To play 'all formats' simply write a decoder for any format that JMF does not support 'out of the box', as well as any formats to be released.
    I think the reason people are fooled into thinking it is 'easy' to play all formats is that the Win. media player has a very clever mechanism to pretend that it can. If the Win. media player encounters a format it does not understand, it opens a connection back to microsoft, and tells MS what the file reports as its format, in the hope that the MS website can provide the decoders 'on the fly'.
    That is one way to provide support for (previously unknown) formats.
    Java (or rather, the JMF) uses a different mechanism to add new formats, the Service Provider Interface - I doubt it would be compatible with active downloading of the new decoders, as the Services for JMF need to be registered at application start-up.
    The FMJ (note the reversal of letters) is a project aimed at providing the 'extra' encoding support for more formats, but even it does not cover 'every format'.
    To be blunt, I would not use JMF for a 'general player' like you seem to want. JMF is good for dealing with media over which you have total control, and can thereby encode the media in whatever format that is compatible with JMF, best suits your application.
    As far as a general player of 'anything the user might throw into it', JMF fails badly. :-(

  • Why the capture audio program can't work in the phone?

    Our capture audio program witch used MMA can run normally on the WTK simulator, but when we down the program into Motorola V303, it can�t work! The document says V303 support JSR-135, why it can�t capture audio by use MMA? The program also can�t work in Nokia 6600! Please give some suggestions!

    Hiii
        In main program you have dclared subscreen area.
    now First of all you have to declare a selection screen in your main program
    selection-screen begin of screen 1005 as subscreen.
    SELECT-OPTIONS s_bukrs1 for  v_bukrs.   "whatever you want in selection screen
    selection-screen end of screen 1005.
    IN PBO of your main screen (not in 1005) write
    call subscreen SUB1 including sy-repid '1005'.
    where SUB1 is your subscreen area name. And remember don't touch PBO or PAI of your 1005 screen, otherwise it will give you error. Yuo can just put text in layout of 1005 screen. but don't disturb other things.

  • Trying To Draw The Wav Form of captured audio

    hi all , im trying to get into audio proccessing at j2me platform
    as a start , i made an application that records audio through the phones microhone and after that drawing the bytearray with its wave form on the canvas.
    i used the following capture encoding:
    "capture://audio?encoding=pcm&rate=8000&bits=8&channels=1"
    the application worked great on the emulators...
    after i tried the application on my mobile (motorola E-1000)
    i realized that my mobile does not support PCM encoding as for audio capturing the device only supports AMR to capture audio :|
    so my question what am i suppose to do to draw the WAveForm of the recorded audio if its stored in bytearray encoded as AMR??
    do i need to convert it to wav?
    is there any other techinque?
    any info will be highly welcome!
    thanks in advance.

    Did u manage to draw waveform of amr file? I've the same task and i 've the same questions: "do i need to convert it to wav? is there any other techinque?"

  • Using Flex to capture audio from Flash

    Hi!
    I've been trying for a while to figure out how to capture audio from a flash-application (http://www.delorean.se/mixer)
    and store it as a mp3-file.
    Since I've studied Java for 2 years I thought I'd try and use it to capture the audio but I'm running into problems all the time,
    and I've been advised to look up Flex by other Java users.
    So, I got some questions:
    Is Flex a good tool to use to capture audio from flash-applications and store the audio as a mp3-file?
    Is Flex hard to learn (I've been working with Eclipse for a long time so the IDE shouldn't be a problem and learning another language/framework is always nice)
    Any tips in general?
    Any answers would make me very happy!
    Thanks!

    physical are closed : how will it managed the queues and overspill queues when target is not present? Also the data dictionary must reflect the primary but If you run capture, then you introduce rules that are not on primary: How ?

  • Getting echo when capturing audio with JMF

    Hello.
    I have just downloaded JMF 2.1.1 and have cribbed one of the examples to produce an application that will capture audio input, process it and pass it straight to the speakers. However, I am getting echo, i.e. the input signal appears twice at the speakers, shifted by about half a second.
    Now, before you tell me that it is due to feedback from the speakers to the microphone, I must tell you that my audio signal is from a radio plugged into the mike socket of my PC, so there is no chance of any external feedback.
    Below is the code:
    import javax.media.*;
    import javax.media.protocol.*;
    import javax.media.control.*;
    import javax.media.format.*;
    public class ExampleClass2 implements ControllerListener {
         private Object waitSync = new Object();
    private boolean stateTransitionOK = true;
         private Processor proc;
         public ExampleClass2 () {
              MediaLocator locator = getLocatorByName ("JavaSound audio capture");
              try {
                   proc = Manager.createProcessor(locator);
                   proc.addControllerListener(this);
                   proc.configure();
                   waitForState (Processor.Configured);
                   proc.setContentDescriptor(null);
                   proc.start();
    //               waitForState(Processor.Started);
    //          proc.getGainControl().setMute(true);
              } catch (Exception ex) {
                   ex.printStackTrace();
                   System.exit(1);
    * Block until the processor has transitioned to the given state.
    * Return false if the transition failed.
    boolean waitForState(int state) {
         synchronized (waitSync) {
         try {
              while (proc.getState() != state && stateTransitionOK)
              waitSync.wait();
         } catch (Exception e) {}
         return stateTransitionOK;
    * Controller Listener.
    public void controllerUpdate(ControllerEvent evt) {
         if (evt instanceof ConfigureCompleteEvent ||
         evt instanceof RealizeCompleteEvent ||
         evt instanceof PrefetchCompleteEvent) {
         synchronized (waitSync) {
              stateTransitionOK = true;
              waitSync.notifyAll();
         } else if (evt instanceof ResourceUnavailableEvent) {
         synchronized (waitSync) {
              stateTransitionOK = false;
              waitSync.notifyAll();
         } else if (evt instanceof EndOfMediaEvent) {
         proc.close();
         System.exit(0);
         public static void main (String [] args) {
              ExampleClass2 two = new ExampleClass2();
    Now, the really interesting thing is that if I uncomment the lines that mute the processor, I get only a single signal out of the speakers. It appears as if there is some connection between the mike input and speaker output.
    Just to make sure, I tried this with JMStudio and got the same result. When I captured input, I got two signals output until I pressed the mute button, when I got one signal.
    I also get the same problem if I use a Player, rather than a Processor.
    I am running on Win95, JDK1.3.
    Any thoughts?

    i'm having the same problem. but i tried with teh audio property settings. and get resolved. wat solution u found? i would like to know how u solved your problem, plz let me know very soon.
    Thanks,
    Parth Pandya
    Hello.
    I have just downloaded JMF 2.1.1 and have cribbed one
    of the examples to produce an application that will
    capture audio input, process it and pass it straight
    to the speakers. However, I am getting echo, i.e. the
    input signal appears twice at the speakers, shifted by
    about half a second.
    Now, before you tell me that it is due to feedback
    from the speakers to the microphone, I must tell you
    that my audio signal is from a radio plugged into the
    mike socket of my PC, so there is no chance of any
    external feedback.
    Below is the code:
    import javax.media.*;
    import javax.media.protocol.*;
    import javax.media.control.*;
    import javax.media.format.*;
    public class ExampleClass2 implements
    ControllerListener {
         private Object waitSync = new Object();
    private boolean stateTransitionOK =
    ansitionOK = true;
         private Processor proc;
         public ExampleClass2 () {
    MediaLocator locator = getLocatorByName ("JavaSound
    d audio capture");
              try {
                   proc = Manager.createProcessor(locator);
                   proc.addControllerListener(this);
                   proc.configure();
                   waitForState (Processor.Configured);
                   proc.setContentDescriptor(null);
                   proc.start();
    //               waitForState(Processor.Started);
    //          proc.getGainControl().setMute(true);
              } catch (Exception ex) {
                   ex.printStackTrace();
                   System.exit(1);
    * Block until the processor has transitioned to
    d to the given state.
    * Return false if the transition failed.
    boolean waitForState(int state) {
         synchronized (waitSync) {
         try {
    while (proc.getState() != state &&
    & stateTransitionOK)
              waitSync.wait();
         } catch (Exception e) {}
         return stateTransitionOK;
    * Controller Listener.
    public void controllerUpdate(ControllerEvent evt)
    vt) {
         if (evt instanceof ConfigureCompleteEvent ||
         evt instanceof RealizeCompleteEvent ||
         evt instanceof PrefetchCompleteEvent) {
         synchronized (waitSync) {
              stateTransitionOK = true;
              waitSync.notifyAll();
    } else if (evt instanceof ResourceUnavailableEvent)
         synchronized (waitSync) {
              stateTransitionOK = false;
              waitSync.notifyAll();
         } else if (evt instanceof EndOfMediaEvent) {
         proc.close();
         System.exit(0);
         public static void main (String [] args) {
              ExampleClass2 two = new ExampleClass2();
    Now, the really interesting thing is that if I
    uncomment the lines that mute the processor, I get
    only a single signal out of the speakers. It appears
    as if there is some connection between the mike input
    and speaker output.
    Just to make sure, I tried this with JMStudio and got
    the same result. When I captured input, I got two
    signals output until I pressed the mute button, when I
    got one signal.
    I also get the same problem if I use a Player, rather
    than a Processor.
    I am running on Win95, JDK1.3.
    Any thoughts?

Maybe you are looking for

  • Sale order bom explosion in delivery doc

    hi all there is an urgent requirement for my clint issue is my clint want the BOM should not expolde in sales order, should expolde at the time of delivery only. is there any possibility please suggest thanks sridhar

  • I have a problem with the icon in the menu bar MacBooster Beta 3 I can not delete

    I have a problem with the icon in the menu bar MacBooster Beta 3 I can not delete www.advancedmaccare.com and installed and uninstalled the program and past cleanApp or ccleaner programs and nothing works <Link Edited By Host>

  • Problem during the changing of  Password in Active Directory

    Hello All ! I am facing a problem during the password modification in active directory, i got the same exception as other are getting i.e javax.naming.OperationNotSupportedException: [LDAP: error code  53 - 00002077: SvcErr: DSID-03190959, problem 50

  • Re: OBIEE 10.1.3.4.1 integration with Hyperion shared services 11.1.1.3

    I am working on OBIEE authentication using hyperion shared services. To achieve this I did the following steps, 1) Registered the shared services in Answers using 'Manage EPM workspace' 2)Modified config.xml to enable HSSauthenticator 3)Modified inst

  • Photoshop CS5 Actions Error

    When running a favorite action of mine using CS5, I get the error "The Command Name Is Not Currently Available".  Exactly what is missing from CS5 that was there in previous versions?