Here is a simple
Audio::DSP script for wave playback. Remember, you need to initialize the soundcard, to accept the audio data you pump in. The program
Sox will help you detecting wav information.
On Ubuntu, with the Alsa sound system, you have a great utility called aplay. It will auto-detect the soundfile stats, for proper playing, so all you need to play a wav is
#!/usr/bin/perl
# fork off, so the playback is non-blocking
if(fork() == 0){exec("aplay $my_sound_file")}
Or with Perl......
#!/usr/bin/perl
use warnings;
use strict;
use Audio::DSP;
#alsamixer must be setup right, just turn everything up :-)
# use the channel count, bitrate, and samplerate of the wave
# you want to play
my ($buf, $chan, $fmt, $rate) = (4096, 1, 8, 22050);
my $dsp = new Audio::DSP(buffer => $buf,
channels => $chan,
format => $fmt,
rate => $rate);
$dsp->init() || die $dsp->errstr();
my $file = shift || 'Om.wav';
open(IN, "<$file") or warn $!;
while ( 4096 == read( IN, my $buffer, 4096 ) ) {
$dsp->dwrite($buffer);
}
$dsp->close();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.