Namespaces
Variants
Actions

Using audio feedback for non-cursive text

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


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);
}
}
}


public void delay(int delayval)  { 
//thread to sleep for delayval
try {
Thread.sleep(delayval*10);
} catch (Exception e) {}
}



License

This code is distributed under the MIT License


SignpostIcon FilmReel 52.png
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)
This page was last modified on 10 May 2013, at 08:50.
81 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved