Search This Blog

Saturday, 2 June 2012

Make your app talkative,by using speech for messages

Hello friends,
                   Still using those old style Dialog box for giving message , or showing error in your app???.....Old school Out! here it is make your app play verbal messages on any event you want....follow the code...
And yes use this link to convert text into voice...http://www2.research.att.com/~ttsweb/tts/demo.php


CODE:

Copy your wave file that you get from this link....into res folder of your app.

Now, just do this as below.....

try {
                     
                    InputStream stream = (InputStream)this.getClass().getResourceAsStream("/messagesent.wav");
                   
                    Player p = javax.microedition.media.Manager.createPlayer(stream,"audio/wav");
                    p.realize();
                    VolumeControl _volume = (VolumeControl)p.getControl("VolumeControl");
                    _volume.setLevel(100);
                    p.prefetch();
                    p.start();
                } catch (IOException e) {
                    System.out.println("Error :"+e.toString());
                    e.printStackTrace();
                } catch (MediaException e) {
                    System.out.println("Error :"+e.toString());
                    e.printStackTrace();
                }


BINGO!!! its done and ready to roll....see your app is saying something to you....

1 comment: