1

Is it possible to play basic BIOS sounds with Javascript or Java?
I need sounds that can be played on PC computers without Sound Card.
Every PC has built-in PC speaker that can be useful in this case.

Ilya
  • 29,135
  • 19
  • 110
  • 158
  • http://stackoverflow.com/questions/269657/how-to-make-a-noise-on-the-pc-speaker-with-java – James Scholes Apr 24 '13 at 21:38
  • @JamesScholes Sound Card is required for this sound. I need something like `Sticky Keys` sound (press 5 times `Shift` to listen it) – Ilya Apr 24 '13 at 21:39
  • For what it's worth, in Linux, you can do `try (OutputStream out = Files.newOutputStream(Paths.get("/dev/console"))) { out.write(7); }` (but even that might require the "pcspkr" kernel module to be loaded). – VGR Apr 24 '13 at 23:19
  • I would believe that it would be impossible to control the system speaker in Javascript, however you could in Java. – Qantas 94 Heavy Apr 25 '13 at 05:30

2 Answers2

0

I would use Java and exec an external program:

Runtime.getRuntime().exec("beep.exe"); //not sure Beep.exe is a real thing

Which program to exec? Not sure, but look here for inspiration:

https://superuser.com/questions/227939/how-to-make-the-pc-speaker-beep-from-the-windows-7-command-prompt

or write your own:

http://www.frank-buss.de/beep/

Note that using exec is inherently platform-specific and thus frowned upon in Java. However, what you are trying to do is platform specific, so this is your best option.

Other things worth trying/thinking about:

java.awt.Toolkit.getDefaultToolkit().beep();

But I think that beeps on the soundcard.

And

System.out.print( (char)7 );

but I'm not sure that will always work.

Community
  • 1
  • 1
Bjorn Roche
  • 11,279
  • 6
  • 36
  • 58
0

pyx4j-native library was helpful for me.

  <dependency>
     <groupId>com.pyx4j</groupId>
     <artifactId>pyx4j-native</artifactId>
     <version>1.0.1</version>
  </dependency>

It have class Beep method beep(int,int).

Play any sound is so easy with this library!

Ilya
  • 29,135
  • 19
  • 110
  • 158