Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Convert WAV to MP3 in J2ME or other compressed format!!!

Posted on 2003-03-21
Medium Priority
Last Modified: 2009-07-29
Hi all,

I have created an audio capture player within my MIDlet using:

player = Manager.createPlayer("capture://audio");

I am then recording using the RecordControl object that is obtainable from the player. As default it is recording using a sample rate of 44khz. This creates very large *.wav files. (is itr possible to change this sample rate?)

These files are too large and i need them to be smaller, therefore i need to compress them, possibly into MP3.

(Average wav size = 2meg, required file size less than 400k)

Either that or something smaller, which i can then make back into a WAVE at my ASP Side.

Has anybody solved this problem before.

Help will be very greatfully appreciated.


Question by:Rashimus
  • 3

Expert Comment

ID: 8212888
Should your OEM device *always* default to a high format rate use this function:

private RateControl getRateControl()
   return (RateControl) player.getControl("RateControl");

then try and set the rate against the capture player...

RateControl rtc = getRateControl();
rtc.setRate(int rate);

Works well with my large-scale TTS/Reco implementation processing many-to-many formats for devices that support WAV, AU, GSM, MP3 in conjunction w/back-end services.  (Also works via JMF and applets for J2SE/JDK1.1.)  For more on this, here's an article (incl. function models) for a media brokering approach I wrote published at the Australian Developer's Magazine this year (should be in the U.S. at WDJ soon):


Hope this helps.

Dale Schalow
AMN Corporation (USA)
+1 301.496.5120


Author Comment

ID: 8213715

As i am using "capture://audio" as the player type, when i try and get a RateControl from it, it is null.

Will i be able to get this RateControl a different way or will i be able to set the rate via my RecordControl.


Expert Comment

ID: 8217492
From an audio engineering perspective, you can do some interesting things with rate control in general.  For the JSR's MIDP spec. work RateControl (interface) was probably viewed more as a precise way to toggle "player rate" of a stream.  For that matter, pitch control (I believe the PitchControl interface class) can also bend frequencies for audio samples & MIDI as such (Hey, it sounds like Mickey Mouse -or- Hey, it sounds like it's in slow-motion).  More like adjusting "player speed"... In any event, setting a rate can also shape sound based from its sample rate.

Nothing *documented* for RecordControl indicates an easy approach for setting a capture sampling rate (but hey, it's an interface so anything's possible, right?).

My tests have revealed mostly 22kHz in emulation and below for OEM devices. Since I'm assuming you're using an Emulator (or maybe not) here's some recent MIDP 2.0 info regarding emulation support for all audio formats (ref. <WTK 2.0 home>\docs\BasicCustomizationGuide_HTML\ch_creating-property-files.html):


The Emulator supports all sound file formats currently supported by JDK1.4:

Audio file formats: AIFF, AU and WAV
Music file formats: MIDI Type 0, MIDI Type 1, and Rich Music Format (RMF)
Sound formats: 8-bit and 16-bit audio data, in mono and stereo, with sample rates from 8 kHz to 48 kHz
Linear, A-law, and mu-law encoded data in any of the supported audio file formats


To incorporate MP3 you'll need to address at a codec level (i.e. covert from PCM/Wav).  I seem to recall a WTK I looked at a couple months ago that delivered JMF with it most likely for these purposes (among others).  JMFRegistry can give you more info on this.


Dale Schalow
AMN Corporation (USA)
+1 301.496.5120

Accepted Solution

schalow earned 940 total points
ID: 8256652
...Okay, let's try to make this a little 'easier' on you.

(Ref. javax.microedition.media.Manager):

"capture://" device [ "?" params]


capture://audio (default audio)
capture://audio?encoding=pcm (default audio in PCM format)
capture://devmic0?encoding=pcm&rate=11025&bits=16&channels=1 (audio from a specific device--devmic0)


Dale Schalow
AMN Corporation (USA)
+1 301.496.5120

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Need WiFi? Often, there are perfectly good networks that don't have WiFi capability - and there's a need to add it.  - Perhaps you have an Ethernet port into a network but no WiFi nearby. - Perhaps you have a powerline extender and no WiFi at the…
Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question