Making progress. I just ran the following on my computer: It played the wave once when it created it, once each for 'sinus.wav', './sinus.wav', and for the tempdir version, then finally played the WindowsDefault / error chime when it could not find 'DoesNotExist'. So, that means as long as the file exists and is readable (and is a valid wave file, presumably), Win32::Sound::Play() does what I expect.

Please add a fourth and a fifth entry to the for-loop: once for a local copy of your .wav, and once for the copy that's in some other directory. Then run the following script, and report the results.

use warnings; use strict; use Win32::Sound; # Create the object my $WAV = new Win32::Sound::WaveOut(44100, 8, 2); my $data = ""; my $counter = 0; my $increment = 440/44100; # Generate 44100 samples ( = 1 second) for my $i (1..44100) { # Calculate the pitch # (range 0..255 for 8 bits) my $v = sin($counter*2*3.14) * 127 + 128; # "pack" it twice for left and right $data .= pack("CC", $v, $v); $counter += $increment; } $WAV->Load($data); # get it $WAV->Write(); # hear it 1 until $WAV->Status(); # wait for completion $WAV->Save("sinus.wav"); # write to disk my $otherFile = $ENV{TEMP} . '/sinus.wav'; $WAV->Save($otherFile); # write to disk elsewhere $WAV->Unload(); # drop it ############ $|++; for('sinus.wav', './sinus.wav', $otherFile, 'DoesNotExist') { sleep(1); printf "'%s' does%s exist and is%s readable\n", $_, (-f $_ ? '' : +' not'), (-r $_ ? '' : ' not'); Win32::Sound::Play($_); (my $f = $_) =~ s{/}{\\}; print qx(cmd.exe /c dir /N "$f"); print "\n" x 4; } __END__ 'sinus.wav' does exist and is readable Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free './sinus.wav' does exist and is readable Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free 'C:\Users\pryrt\AppData\Local\Temp/sinus.wav' does exist and is readab +le Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\Users\pryrt\AppData\Local\Temp 02/08/2019 03:08 PM 96,278 sinus.wav 1 File(s) 96,278 bytes 0 Dir(s) 113,186,381,824 bytes free 'DoesNotExist' does not exist and is not readable File Not Found Volume in drive C is Windows Volume Serial Number is XXXX-XXXX Directory of C:\usr\local\share\PassThru\perl\perlmonks

As you might be able to guess, since I am able to access a .wav in my local directory and in a different directory, I see no reason why it should not work for you; thus, I added the file-exists / file-readable test and dir output to give some clue as to what's going wrong for you.


In reply to Re^2: 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.