0

I'm trying to make a program that roughly does the following:

produceBeepSound(double loudness);

can I do such a thing in Java? I need it to be very precise. What about matlab? Which language would be best for this task. The language must have a GUI component.

juliomalegria
  • 24,229
  • 14
  • 73
  • 89
CodeGuy
  • 28,427
  • 76
  • 200
  • 317

4 Answers4

5

You can use Java Media Framework to produce sound but it is not necessary because you can work with javax.sound.sampled package and integrate it with Java Swing.

In python take a look at pyaudio library and also take a look at PythonInMusic it has a whole lot of collection of various A/V module.

Also, take a look at Beeper.

It is a GUI program, using only J2SE classes, that can produce a sound of configurable tone & duration, and (with a bit of tweaking) at different raw volumes

Thanks to @Andrew for once again correcting me.

Community
  • 1
  • 1
RanRag
  • 48,359
  • 38
  • 114
  • 167
  • The JMF has not been necessary for making sound in Java since 1.3 and the introduction of the `javax.sound.sampled` package. Please get with the times. ;) My 1st comment links to code with a GUI, using *only J2SE classes,* that can produce a sound of configurable tone & duration, and (with a bit of tweaking) at different raw volumes. – Andrew Thompson Feb 02 '12 at 01:43
  • Great edit, but it could be better to qualify the 'is not in use' to 'has not been *necessary* to work with *sampled sound*'. The reason for the clarification is that I used JMF within the last few months (in a 1.6 JRE) to make MOV files from JPEGs (and I don't want to feel like a dinosaur for using an abandoned API). – Andrew Thompson Feb 02 '12 at 01:58
  • @AndrewThompson: thanks once again. Lot to learn..lot to learn :). – RanRag Feb 02 '12 at 02:06
  • 1
    Yep. The answer is now to a point where I just got to +1. :) – Andrew Thompson Feb 02 '12 at 02:16
1

In MATLAB, just use the SOUND function:

http://www.mathworks.com/help/techdoc/ref/sound.html

You can specify a vector which represents your signal, and the amplitude on that vector will determine loudness, so its a matter of simple scaling.

eternaln00b
  • 1,043
  • 9
  • 18
0

you can try Csound. There is API for java.

You should also check this wiki page: http://en.wikipedia.org/wiki/Comparison_of_audio_synthesis_environments.

But if you need somthing simple you can try:

java.awt.Toolkit.beep();

or

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

But you won't have volume control.

Probably my favourite approach would be HTML 5 audio api - https://wiki.mozilla.org/Audio_Data_API#Writing_Audio

Maciek Sawicki
  • 6,717
  • 9
  • 34
  • 48
0

on windows actually any language can emit a sound just outputting ascii character "\007". Here is a nice article about how to do it in java.

savionok
  • 485
  • 4
  • 11