Win32::Sound has direct access to the various Windows sounds: to test that everything's working okay,

perl -MWin32::Sound -le "print($_), Win32::Sound::Play($_) for qw/Syst +emDefault SystemAsterisk SystemExclamation SystemExit SystemHand Syst +emQuestion SystemStart/"
... when I did that, all but SystemHand were the same -- probably because I don't have a lot of those sounds defined on my machine (I like a quiet machine).

If you go to cpanm --look Win32::Sound, which (if you have cpanminus (*)) will put you into the distro-directory for Win32::Sound, then cd into the samples directory, you should be able to run sinus.pl and hear a tone (the note A). Then perl -MWin32::Sound -le "Win32::Sound::Play('welcome.wav')" should play a small sound. (*: if you don't have cpanminus, download the Win32::Sound tarball and untar it, then go into the samples subdirectory.)

My guess is what's happening in your example is that it's not finding $wav_file. In the same directory as welcome.wav above, run

perl -MWin32::Sound -le "for(qw/welcome.wav DNE.wav/) { print qq(With +Default: $_); Win32::Sound::Play($_); sleep(1); print qq(No Default: +$_); Win32::Sound::Play($_,SND_NODEFAULT); sleep(1); }"
. This should play the welcome sound twice, then play the system default (because it didn't find DNE.wav), then play nothing (because it didn't find DNE.wav and was set to no default)


In reply to Re: Playing wav files by pryrt
in thread Playing wav files by merrymonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.