Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java playing sounds. Is there a default system sound?

Hi I am trying to write an application that will play morse code. I just wanted to know if there was a default system sound in java like some beep, or do I have to download some sound file from the internet?

like image 861
user69514 Avatar asked Mar 03 '10 14:03

user69514


3 Answers

You can:

Print the ASCII bell character to the console (will emit a beep sound):

public class DoBeep {
    public static main(String args[]) {
        System.out.print("\007"); // bell ASCII char
        System.out.flush();
    }
}

Use the beep() method that will use the buzzer on the motherboard:

import java.awt.*;

public class DoBeep {
    public static void main(String args[]) {
        Toolkit.getDefaultToolkit().beep();     
    }
}
like image 138
rogeriopvl Avatar answered Sep 19 '22 17:09

rogeriopvl


Have a look at the Java Sound API, which can play MIDI tones.

like image 26
kgiannakakis Avatar answered Sep 17 '22 17:09

kgiannakakis


You may want to look at jMorse for some tips. This isn't to discourage you from your effort, but rather to provide a reference.

like image 21
Michael Easter Avatar answered Sep 20 '22 17:09

Michael Easter