Link to home
Start Free TrialLog in
Avatar of q_bic
q_bic

asked on

Audio problems

My problem really is adding some sound to my piece of code. What i really want to know is how do I record my voice to a file i can use on my piece of code that will execute at a given time.Example: when the an applet color changes from blue to pink, my recorded voice should shout "Pink" as it corresponds to the change of colors.

Oh! and by the way, I am using Visual J++ as my compiler..
Thanx!!
ASKER CERTIFIED SOLUTION
Avatar of mzimmer74
mzimmer74

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mzimmer74
mzimmer74

That's how you play a clip.  Of course, you'll have to call it as appropriate.
> Oh! and by the way, I am using Visual J++ as my compiler..

in JDK1.1 you need

AudioClip clip = applet.getAudioClip(url);
clip.play();
Avatar of q_bic

ASKER

Yeah, but how do i change existing sound files to .au files so that they can be recognised by java coz i failed to find any .au files in my system.
How do i make my own .au files that i can use on my code
mzimmer74?
thanx...
That I don't know...I supose there are some programs out there that will convert files to .au type.  However, if you want to use .midi or .wav files you can play them in this manner:

private void playMidi()
{
  try
  {
    File file = new File("soundOne.mid");
    // OR:
    // File file = new File("sounDTwo.wav");
    currentSound = MidiSystem.getSequence(file);
    player = MidiSystem.getSequencer();
    player.open();
    player.setSequence(currentSound);
    player.start();
    while (player.isRunning())
    {
      System.out.print(". ");
    }
    player.close();
  }
  catch (Exception ex)
  {
    ex.printStackTrace();
  }
}


I don't remember all the info about this method (ie, what is player) as I don't use it anymore in some code I've written.  However, I do remember that it worked.

You might look at
http://java.sun.com/products/java-media/sound/
for some examples of this.  Hope that helps.
q_bic:

what is the target Java version ?
Avatar of q_bic

ASKER

Thanx mzimmer74, finally it worked!!