Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jython: Making a simple beep on Windows

I'm working with Sikuli, which (I think) is build on Jython. I want to make a script that does a small gentle beep to attract the user's attention. (This is on Windows.)

How can I do this? I see that the winsound module is not available on Jython.

(Note that I want to use the sound card, not the built-in beeper.)

like image 838
Ram Rachum Avatar asked Nov 02 '10 14:11

Ram Rachum


3 Answers

If its Jython, then just use any of the Java classes that play sound. There are tons of them.

from java import net
from java.applet.Applet import newAudioClip
from java import io
url = io.File("fileName").toURL()
audio = newAudioClip(url)
audio.play()

import sun.audio
import java.io
inputStream = java.io.FileInputStream("test.wav")
audioStream = sun.audio.AudioStream(inputStream)
sun.audio.AudioPlayer.player.start(audioStream)

like image 67
user489041 Avatar answered Oct 13 '22 18:10

user489041


You may do the fllowing using command line:

Execute "copy con beep.txt" type [ctrl+G] as input and then [ctrl+Z] followed by [Enter] to exit

Then run "type beep.txt" and you will hear a beep.

You may place "type beep.txt" in a batch file or use Ctrl+G directly in batch (which would produce error in command line with sound)

like image 40
Sergey Stefurak Avatar answered Oct 13 '22 17:10

Sergey Stefurak


Since we have access to the Java level in Sikuli (thanks to Jython), this should principally work:

import java.awt.Toolkit # only once per script
java.awt.Toolkit.getDefaultToolkit().beep()

Test passed on windows 7. You may get some detailed explanation here.

like image 24
David Avatar answered Oct 13 '22 17:10

David