Using audio feedback for non-cursive text
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
Code
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.*;
Parameters:
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.addPlayerListener(this);
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) {
System.err.println(e);
}
}
}
License
This code is distributed under the MIT License
Article Metadata
Tested with
SDK: NetBeans IDE 6.8, Nokia Series 40 SDK
Compatibility
Platform(s): Series 40, S60
Device(s): MIDP 2.0, CLDC 1.0, JSR 135
Article
Created: kuroshtech (29 Jun 2011)
Last edited: hamishwillee
(10 May 2013)


Hamishwillee - MIT License?
When you upload content to the wiki you must comply with the terms and conditions of the site. Is there any reason this needs explicitly to be under MIT Licence?