Getting a click from the PC-speaker?

G

gentsquash

Can javascript (easily) produce a click from the PC-speaker?
This is the speaker that is (well, used to be) directly on
the CPU-card and was -I believe- intended to give feedback
to the typist, making a click-sound on each keypress.

On Unix/Linux/MacOSX systems, you can hear this click by
typing ^g (control g) into a shell/terminal. This is also
the click made by ^g when it is typed in Emacs, or when
Emacs signals an error.

This doesn't involve the PC's sound card, nor downloading
".wav" files to the user's system.

My general question is: Can javascript make an audible
sound on the user's system (typically, as a consequence of
an "onclick=" event when user clicks on certain parts of
the window) WITHOUT some kind of sound file being
downloaded? (Indeed, the user's computer wouldn't even
need to HAVE a sound card; the PC-speaker is [or, used to
be] directly driven by the kernel.)

Sincerely, -Jonathan King, Mathematics, Univ. of Florida
 
G

gentsquash

Can javascript (easily) produce a click from the PC-speaker? This is the
speaker that is (well, used to be) directly on the CPU-card and was -I
believe- intended to give feedback to the typist, making a click-sound
on each keypress.

Easily? Not in a cross-platform way.

Your shell/terminal combo can do it because ^g is the ASCII character
for the bell, interpreted by the terminal. In days of old, it rang a
very literal bell on dumb teletype machines.
This doesn't involve the PC's sound card, nor downloading ".wav" files
to the user's system.

On my X11 setup, it does play a WAV file, even in the console. I don't
have a PC speaker so I set up my xterm that way. I have no true console
beep.
My general question is: Can javascript make an audible sound on the
user's system (typically, as a consequence of an "onclick=" event when
user clicks on certain parts of the window) WITHOUT some kind of sound
file being downloaded? (Indeed, the user's computer wouldn't even need
to HAVE a sound card; the PC-speaker is [or, used to be] directly driven
by the kernel.)

You might be able to embed the audio in the 'data' IRL. I've never tried
that though -- and it would fail under IE. (At least version 6, but I
don't think 7 or 8 support the data IRL either.)
 
G

gentsquash

(I apologize for my erroneous post.)

Easily? Not in a cross-platform way. ...
On my X11 setup, it does play a WAV file, even in the console. ...

Thank you Jeremy. Weakening my request...

* Can anyone point me to public-domain WAV (or other common
audio format) files that have a gentle click or beep?

* How do I attach the playing of the file to an "onclick="
event? (At least, under Firefox on MacOS.)

As a javascript beginner, I web-searched and found postings
on JS audio, which I did not understand. The only one that
worked for me was

<embed src="file.wav" autostart="true"
name="sound1" id="sound1"
Worked for my FF on MacOSX</embed>

However, I have read that <embed> is deprecated.
 
J

Jeremy J Starcher

(I apologize for my erroneous post.)

Tis OK, I've done enough of that myself here. Some day I'll learn how to
cancel posts.


Thank you Jeremy. Weakening my request...

* Can anyone point me to public-domain WAV (or other common
audio format) files that have a gentle click or beep?

I can't help you on that one.
* How do I attach the playing of the file to an "onclick="
event? (At least, under Firefox on MacOS.)

There was a fairly big discussion about that here earlier.

You can read it at

<URL: http://groups.google.com/group/comp.lang.javascript/browse_frm/
thread/42ee834db6d5ad7a/2460fe781cbcb7f3?lnk=st&q=play+audio+group%
3Acomp.lang.javascript#2460fe781cbcb7f3 >


(If that URL does not work, go to
groups.google.com and search for:

why is "how to play a sound with Javascript" such a rare topic?
)


That said, may I ask why you want to play a sound with every keypress?

In most applications I can't see this being a good idea.. sound tends to
annoy most users. (But I can see doing this in a typing tutor program or
a typewriter emulator ;) )
 
G

gentsquash

* How do I attach the playing of the file to an "onclick="
event? (At least, under Firefox on MacOS.)

There was a fairly big discussion about that here earlier [at]

<URL:http://groups.google.com/group/comp.lang.javascript/browse_frm/
thread/42ee834db6d5ad7a/2460fe781cbcb7f3?lnk=st&q=play+audio+group%
3Acomp.lang.javascript#2460fe781cbcb7f3 >

Jeremy, I appreciate the pointer, but it is too involved for my
knowledge
of JS, which started a week ago. I'm hoping that someone running
MacOS
and Firefox can post code that works just for that combination
(assuming
that Quicktime, Flash, and realplayer are installed).
.. may I ask why you want to play a sound with every keypress?

In most applications I can't see this being a good idea.. sound tends to
annoy most users.

The sound is not for a user --it is for ME, as I develop the program.
For
a future abstract algebra class I'll be teaching, I'm converting an
algebraic game that I wrote in Common Lisp into a graphical
version in JS, that my students can use.

It involves clicking on fairly smaller regions in a <table>, and
sometimes
the click isn't registered (it currently uses a "bubbling-up"
technique
that was kindly posted on c.l.j). The click (or rather, its lack) is
so
that *I* know, while developing the program, when a click was not
registered.

Yes, the audio feedback might be useful for a user too, but right now
it
is for me.
--gentsquash, Mathematics dept, Univ. of Florida
 
J

Jeremy J Starcher

[URL and discussion snipped]
Jeremy, I appreciate the pointer, but it is too involved for my
knowledge
of JS, which started a week ago. I'm hoping that someone running MacOS
and Firefox can post code that works just for that combination (assuming
that Quicktime, Flash, and realplayer are installed).

That should be a fairly easy combo to find code for. Alas, I've never
actually worked with sound and HTML before so I can't point you towards a
good easy reference.

[On why the sound]
It involves clicking on fairly smaller regions in a <table>, and
sometimes
the click isn't registered (it currently uses a "bubbling-up" technique
that was kindly posted on c.l.j). The click (or rather, its lack) is so
that *I* know, while developing the program, when a click was not
registered.

Ah -- that makes perfect sense.

In similar settings I set up a one-line DIV at the top of the document
and use the much-debated innerHTML to set its status.

Something akin to this -- untested
(onclick -- assuming your table cells have IDs, or however you identify
them)
document.getElementById("status_div").innerHTML = "Click registered on
element " + this.id

(on mousemove)
document.getElementById("status_div").innerHTML = ""
 
V

VK

I'm hoping that someone running
MacOS
and Firefox can post code that works just for that combination
(assuming
that Quicktime, Flash, and realplayer are installed).

That supposes to work on any computer able to play .wav files: though
with MacOS and especially with Safari one never can be sure in
anything.
http://transmodal.sourceforge.net/tmp/click.html

Also note that the current Gecko media interfaces are _very_ slow so
it gives a noticeable delay on Firefox and Co. even on a quick
computer, and with quick typing stops playing at all. IE's interfaces
are quick enough unless one is a professional typer.
 
G

gentsquash

That supposes to work on any computer able to play .wav files: though
with MacOS and especially with Safari one never can be sure in
anything.http://transmodal.sourceforge.net/tmp/click.html

Also note that the current Gecko media interfaces are _very_ slow so
it gives a noticeable delay on Firefox and Co. even on a quick
computer, and with quick typing stops playing at all. IE's interfaces
are quick enough unless one is a professional typer.
 
G

gentsquash

(Somehow I'm misusing the G.G. interface; I'm reposting)


[On getting feedback for mouse-clicks]
In similar settings I set up a one-line DIV at the top of the
document and use the much-debated innerHTML to set its status.

Something akin to this -- untested (onclick -- assuming your
table cells have IDs, or however you identify them)

document.getElementById("status_div").innerHTML =
"Click registered on element " + this.id

Thanks Jeremy; that's a good technique that I've noted for future
use. My current need though is for a no-eyes method.

================================================================

That supposes to work on any computer able to play .wav files:
though with MacOS and especially with Safari one never can be sure
in anything. http://transmodal.sourceforge.net/tmp/click.html

Well this is interesting. Typing in the box of "click.html"
produces no sound on FF (and no error in the Error Console) nor
on Camino. However it _does_ produce a click under Safari.
However, when I copy the small file (and put the sound file in
the appropriate place) then it produces no sound even in Safari.

The file has

<script type="text/javascript">
/*@cc_on @*/
/*@if (@_jscript)
var IE = true;
document.write(''.concat(
'<bgsound src="click.wav" id="Player">'
));
@else @*/
var IE = false;
document.write(''.concat(
'<embed src="click.wav" autostart="false" width="0" height="0" ',
'name="Player" enablejavascript="true"></embed>'
));
/*@end @*/
</script>

Are these @-constructions some kind of macro?

================================================================

A few days ago I accidentally came across a webpage that played
a little whoosh every time the pointer passed over the word
"script". The source loaded tons of external
incomprehensible-to-me javascript files (which didn't seem to do
much, since the page was full of static advertising).

I got the impression that the page invoked Flash to play the
sound. Do any of you know how to do that --perhaps with the
`embed' tag?

Sincerely, -gentsquash, Mathematics dept, Univ. of Florida

Footnote: Unfortunately, I did not bookmark the page, and I
haven't been able to find it again.
 
J

Jeremy J Starcher

On Wed, 28 May 2008 05:36:17 -0700, gentsquash wrote:

[Snip]
Well this is interesting. Typing in the box of "click.html" produces no
sound on FF (and no error in the Error Console) nor on Camino. However
it _does_ produce a click under Safari. However, when I copy the small
file (and put the sound file in the appropriate place) then it produces
no sound even in Safari.

The file has

<script type="text/javascript">
/*@cc_on @*/
/*@if (@_jscript)
var IE = true;
document.write(''.concat(
'<bgsound src="click.wav" id="Player">' ));
@else @*/
var IE = false;
document.write(''.concat(
'<embed src="click.wav" autostart="false" width="0" height="0" ',
'name="Player" enablejavascript="true"></embed>' ));
/*@end @*/
</script>

Are these @-constructions some kind of macro?


Those are a "conditional comment", an MSHTML (Internet explorer) specific
thing. In short, you wrap code in comments (so other browsers will
ignore it) and then tell IE that it is really code and not a comment
after all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top