Using audio feedback for non-cursive text

From Nokia Developer Wiki
Jump to: navigation, search

This code was used in our JavaME app BlindSMS (the code has been simplified for the sake of clarity and ease of explanation), an SMS and note taking application for the blind, to provide audio feedback. It is compatible with all devices that support these minimum specifications - MIDP 2.0, CLDC 1.0, JSR 135

This can find use wherever non-cursive text input or similar feedback is required as for instance a talking calculator.

Package to be included in the build: Mobile Media API 1.1 (JSR 135)
mp3 sounds stored as raw resource files


Author: kuroshtech
Version: 1.0.0
Date: 29 June 2011

The basic media packages to be imported:

import javax.microedition.media.*; 
import javax.microedition.media.control.*;


private Player player;   //Media player to play audio sounds
public String newSymbolA = "noaudio"; //the default value is no audio
public int vol; // this parameter is adjustable in 'Audio Settings' saved to RMS

Sample usage:

public void oneSound() {   
// speak sound 'one'
newSymbolA = "1";
if (vol > 0) { stopPlayer(); onStart(); }
newSymbolA = "noaudio"; //reset to default value
delay(30); // delay till sound finishes playing

The main play, stop methods exposed to all classes in the package

public void stopPlayer() {
// stop the player
try {
if(player != null) { player.stop(); player.deallocate(); player.close(); player = null; }
} catch(Exception e) {}

public void onStart()  
String audioFile = "/raw/noaudio.mp3";
if (newSymbolA.equals("1")) {audioFile = "/raw/one.mp3";}
//play sound only if volume is not off
if (vol > 0)
try {
//get the raw mp3 file for playback
InputStream in = getClass().getResourceAsStream(audioFile);
player = Manager.createPlayer(in, "audio/mpeg");
// a listener to handle player events
player.prefetch(); // prefetch
player.realize(); // realize
VolumeControl vc = (VolumeControl)player.getControl("VolumeControl");
if(vc!=null) { vc.setLevel(vol); }
player.start(); // and start playing sound
} catch (Exception e) {

public void delay(int delayval)  { 
//thread to sleep for delayval
try {
} catch (Exception e) {}


This code is distributed under the MIT License

Article Metadata
Tested with
SDK: NetBeans IDE 6.8, Nokia Series 40 SDK
Created: Display as link kuroshtech (29 Jun 2011)
Last edited: hamishwillee (30 Jul 2013)
This page was last modified on 30 July 2013, at 03:42.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.