Solved

Audio problems

Posted on 2002-03-05
7
151 Views
Last Modified: 2010-03-31
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!!
0
Comment
Question by:q_bic
  • 3
  • 2
  • 2
7 Comments
 
LVL 2

Accepted Solution

by:
mzimmer74 earned 100 total points
ID: 6842217
   try
    {
      URL file = new URL(filename);
      AudioClip clip = Applet.newAudioClip(file);
      clip.play();
    }
    catch (MalformedURLException mue)
    {
    }
0
 
LVL 2

Expert Comment

by:mzimmer74
ID: 6842219
That's how you play a clip.  Of course, you'll have to call it as appropriate.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6843727
> 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();
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:q_bic
ID: 6846748
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...
0
 
LVL 2

Expert Comment

by:mzimmer74
ID: 6847149
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.
0
 
LVL 16

Expert Comment

by:heyhey_
ID: 6850010
q_bic:

what is the target Java version ?
0
 

Author Comment

by:q_bic
ID: 6855689
Thanx mzimmer74, finally it worked!!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now