Getting a click from the PC-speaker?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gentsquash@gmail.com

    Getting a click from the PC-speaker?

    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
  • Jeremy J Starcher

    #2
    Re: Getting a click from the PC-speaker?

    On Wed, 21 May 2008 22:03:44 -0700, gentsquash wrote:
    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.)

    Comment

    • gentsquash@gmail.com

      #3
      Re: Getting a click from the PC-speaker?

      On May 22, 12:04 pm, Jeremy J Starcher <r3...@yahoo.co mwrote:
      On Wed, 21 May 2008 22:03:44 -0700, gentsquash wrote:
      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.)

      Comment

      • gentsquash@gmail.com

        #4
        Re: Getting a click from the PC-speaker?

        (I apologize for my erroneous post.)

        On May 22, 12:04 pm, Jeremy J Starcher wrote:
        On Wed, 21 May 2008 22:03:44 -0700, gentsquash wrote:
        Can javascript (easily) produce a click from the PC-speaker? ...
        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 <embedis deprecated.

        Comment

        • Jeremy J Starcher

          #5
          Re: Getting a click from the PC-speaker?

          On Thu, 22 May 2008 14:05:53 -0700, gentsquash wrote:
          (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.


          On May 22, 12:04 pm, Jeremy J Starcher wrote:
          >
          >On Wed, 21 May 2008 22:03:44 -0700, gentsquash wrote:
          Can javascript (easily) produce a click from the PC-speaker? ...
          >
          >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?
          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....pt/browse_frm/
          thread/42ee834db6d5ad7 a/2460fe781cbcb7f 3?lnk=st&q=play +audio+group%
          3Acomp.lang.jav ascript#2460fe7 81cbcb7f3 >


          (If that URL does not work, go to
          groups.google.c om 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 ;) )

          Comment

          • gentsquash@gmail.com

            #6
            Re: Getting a click from the PC-speaker?

            On May 22, 7:50 pm, Jeremy J Starcher <r3...@yahoo.co mwrote:
            On Thu, 22 May 2008 14:05:53 -0700, gentsquash wrote: ...
            * 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....pt/browse_frm/
            thread/42ee834db6d5ad7 a/2460fe781cbcb7f 3?lnk=st&q=play +audio+group%
            3Acomp.lang.jav ascript#2460fe7 81cbcb7f3 >
            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

            Comment

            • Jeremy J Starcher

              #7
              Re: Getting a click from the PC-speaker?

              On Tue, 27 May 2008 06:10:32 -0700, gentsquash wrote:
              On May 22, 7:50 pm, Jeremy J Starcher <r3...@yahoo.co mwrote:
              >On Thu, 22 May 2008 14:05:53 -0700, gentsquash wrote: ...
              >
              * How do I attach the playing of the file to an "onclick="
              [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.getEle mentById("statu s_div").innerHT ML = "Click registered on
              element " + this.id

              (on mousemove)
              document.getEle mentById("statu s_div").innerHT ML = ""

              Comment

              • VK

                #8
                Re: Getting a click from the PC-speaker?

                On May 27, 5:10 pm, gentsqu...@gmai l.com wrote:
                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.


                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.

                Comment

                • gentsquash@gmail.com

                  #9
                  Re: Getting a click from the PC-speaker?

                  On May 27, 11:48 am, VK <schools_r...@y ahoo.comwrote:
                  On May 27, 5:10 pm, gentsqu...@gmai l.com wrote:
                  >
                  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.

                  Comment

                  • gentsquash@gmail.com

                    #10
                    Re: Getting a click from the PC-speaker?

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

                    On May 27, 9:40 am, Jeremy J Starcher <r3...@yahoo.co mwrote:
                    On Tue, 27 May 2008 06:10:32 -0700, gentsquash wrote:
                    On May 22, 7:50 pm, Jeremy J Starcher <r3...@yahoo.co mwrote:
                    [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.getEle mentById("statu s_div").innerHT ML =
                    "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.

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

                    On May 27, 11:48 am, VK <schools_r...@y ahoo.comwrote:
                    On May 27, 5:10 pm, gentsqu...@gmai l.com wrote:
                    >
                    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
                    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="fals e" width="0" height="0" ',
                    'name="Player" enablejavascrip t="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
                    incomprehensibl e-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.

                    Comment

                    • Jeremy J Starcher

                      #11
                      Re: Getting a click from the PC-speaker?

                      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="fals e" width="0" height="0" ',
                      'name="Player" enablejavascrip t="true"></embed>' ));
                      /*@end @*/
                      </script>
                      >
                      Are these @-constructions some kind of macro?

                      Those are a "conditiona l 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.

                      Comment

                      Working...