in reply to Can perl read a byte from a microphone stream ?

What you are looking for is Audio::DSP. You must have your mixer settings setup right to receive input from the mic,
#!/usr/bin/perl use Audio::DSP; #alsamixer must be setup right, just turn everything up :-) $|++; ($buf, $chan, $fmt, $rate) = (4096, 1, 16, 22050); #($buf, $chan, $fmt, $rate) = (4096, 1, AFMT_U16_LE, 44100); #use the formats from soundcard.h, plain 16 wont work with sblive $dsp = new Audio::DSP(buffer => $buf, channels => $chan, format => $fmt, rate => $rate); $dsp->init() || die $dsp->errstr(); # this buffers print to file so that you need ~ 10 secs of audio or t +he file is 0 # like when you hit control-c after a couple of seconds # open(OUT, "| speexenc -n --rate 22050 - test.spx "); ##this works for small low Q ogg open(OUT, "| oggenc -r -R 8000 -B 8 -C 1 -q 0 - | cat > zztest.ogg ") + or warn "No oggenc $!\n"; while ( $buffer = $dsp->dread(4096) ) { syswrite( OUT, $buffer, length($buffer) ); } $dsp->close(); # If you don't set the output of the dsp with arecord, or this # module, the dsp will go to it's lowest setting # speexenc --rate 8000 --le --8bit /dev/dsp - | cat > 1.spx # it works but it sounds lousy. # to convert to wave # sox -r 44100 -u -w -c 1 out1.raw out1.wav # arecord -f S16_LE -c1 -r 22050 -t wav -d 3600 -D hw:0,0 # | speexenc -n --rate 22.05 - - > /home/zentara/`date +%d%b%y%H +%M%S`.spx

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Can perl read a byte from a microphone stream ?
by thenetfreaker (Friar) on Feb 27, 2006 at 20:23 UTC
    Thank you a lot for such an interesting approach, though i have only question about it - I checked on CPAN, and found out that Audio::DSP is a Perl interface to *NIX digital audio device, but i need it to work on Win32, so is there a module that's capable of doing the same task as Audio::DSP under Win32 ?
      Well there is Win32::Sound, and Win32-SoundRec ,but I don't use windows, so I have no experience with it. There are various microsoft help sites-> win32 scripts On linux, you can read directly from /dev/dsp like it's a filehandle, but it must be properly initialized to the bitrate, bytesize, frequency, etc. That is all Audio::DSP does, is the initialization. So you should be able to find out how to do it on windows.

      I'm not really a human, but I play one on earth. flash japh