jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Voice in a program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Voice in a program" Watch "Voice in a program" New topic
Author

Voice in a program

Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
I have a program which does some thing like this.
when you enter 10.39 it gives Ten point three nine in a text area,
I use an array to get the strings. I just want to know can i store voice fragements in an array, or how can i do it so when you enter 10.39 it will say "ten point three nine".
Thank you in advance.........


SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You can certainly store individual sound files for the digits and play them back to create the effect you want. You might look at the Java Madia Framework to do this from an application. From a browser-based applet, you can just use the java.applet.AudioClip class and the Applet.getAudioClip() method to do the same thing. There are several examples in the %JDKHOME%\demo\applets subdirectory of your JDK installation that use sound.
Note that JMF is fairly complicated, and if you're a Java beginner, you probably want to stay away from it for now.


[Jess in Action][AskingGoodQuestions]
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Thank you very much for the reply. I can't be considered as a beginer. A little bit expreienced and very adicted to programming so hopefully I will be able to get to done.
Thank you for the reply...
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy,
Since this *is* the beginner forum, I think it's OK to talk about sound, but only at the basic level. Unfortunately, if you want to use the JavaSound API (standard part of J2SE since 1.3), it's a little more involved than using the Applet sound capability. But it's very powerful, and if you just copy and paste the code right now without trying to understand it, it *will* play your sound file. I'm going to assume it is a standard .aif. You can use other formats, but some of them require a little processing. So this example assumes a standard .aif file in the same directory where this class is...

I think playing with sound is fun. I'm *not* very familiar with the sampled audio part of the API... the JavaSound API comes in two parts: sampled audio (to play things like .aif files, as well as record in.) and MIDI audio, which I'm much more familiar with (lets you create and play MIDI files). In Head First Java, there's an exercise to build a MIDI drum machine.
Cheers and good luck,
Kathy
p.s. please post your code here when you get something working. A very simple app that can play back based on the value of a text field or something would be fun.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello,
Thank you for all the replies. According to my requirement, I think I am not able to do from the details provided from you. The thing is I have written a program which will give a 'String representaion of the Numeric value'. for example if the user enters 10.5, the program will display "Ten point five".
Now I want to improve my program to, when a user enters '10.5', the program will play a sound clip which says "Ten point five".
If you get what I mean , please help me.
Thank you.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You could likely take Kathy's example, apply a big ol' switch construct a la the Cattle Drive's Assignment 4b and get it to work just fine.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello all,
I think Dirk Schreckmann didn't get what I said.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello all,
Thank you for the reply. But I think Dirk Schreckmann didn't get what I said, I already have done the program. What I want to know is how to add sound so it will not show, but will SAY 'ten point zero' some thing like that.
Hope you got it.
Thank you again for the reply.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Both I and Dirk understand exactly what you said.
Kathy showed you how to play one sound file. All you need to do is invoke that code appropriately.
Version 1:
You need to create eleven sound files: ten containing your voice saying each digit, and one saying "point". Then, when you need to say "nine point four", use Kathy's code to play the file for "nine", the file for "point", and the file for "four".
Version 2:
The last version wouldn't say "ten point four", it would say "one zero point four." So now you need to make sound files for "ten", "eleven", "twelve"... "nineteen", "twenty", "thirty", "fourty", etc. Then, again, just use Kathy's code to play the right sound files in order to compose the numbers.
Version 3:
Add even more sound files: "hundred", "thousand", "million", etc.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
I am sorry, I am the one who played the fool. I didn't read the program. Any way thank you very much for the reply. Certainly I will check the programs.
Thanks
 
Consider Paul's rocket mass heater.
 
subject: Voice in a program
 
Similar Threads
problem with multi select box with horizontal scroll bar
Method Creation and debugging.
Array Data Print Out
Hey guys, A little help with binary trees
problem on number to alphabet conversion