錄音
\ 11307Re: [win32forth] Listening code
\ Expand Messages
\ Bruno GauthierJun 3, 2006
\ Frank Russo a ecrit :
\ > Is there any Forth Code for Audio / Recording - Listening, checking to see if a microphone input is available and / or receiving input via the same port?
\ >
\ > Frank
\ >
\ >
\ >
\ >
\ Hi Franck
\ a short example to record a voice (from microphone) to a wav file and
\ then playback it.
\ samplepersec, bitspersample,channels could be set.
\ That use winmm.dll and the mciSendString calls.
\ bruno
WinLibrary winmm.dll
: CloseAll
0 0 0 z" close all" Call mciSendString drop ;
: OpenCapture
0 0 0 z" open new type waveaudio alias capture" Call mciSendString drop ;
: SeekCapture
0 0 0 z" seek capture to start" Call mciSendString drop ;
: SamplepersecCapture
0 0 0 z" set capture samplepersec 44100" Call mciSendString drop ;
: SetCaptureBitspersample
0 0 0 z" set capture bitspersample 16" call mciSendString drop ;
: SetCaptureChannels
0 0 0 z" set capture channels 2" call mciSendString drop ;
: recordCapture
0 0 0 z" record capture" call mciSendString drop ;
: stopcapture
0 0 0 z" stop capture" call mciSendString drop ;
: savecapture ( i -- )
>R
0 0 0
\ z" save capture test.wav"
s" save capture test" temp$ place
\ s" 5" temp$ +place
r> 0 <# # # # #> temp$ +place
s" .wav" temp$ +place
temp$ +null
temp$ 1 + call mciSendString drop ;
: savecapture1
0 0 0 z" save capture test1.wav" call mciSendString drop ;
: opentest
0 0 0 z" open test.wav alias capture1" call mciSendString drop ;
: playcapture1
0 0 0 z" play capture1" call mciSendString drop ;
: closecapture
0 0 0 z" close capture1" call mciSendString drop ;
0 value wav_count
: test
0 to wav_count
\ 5 0 do
begin
closeall
opencapture
seekcapture
sampleperseccapture
setcapturebitspersample
setcapturechannels
recordcapture
1000 ms winpause
stopcapture
wav_count savecapture
wav_count 1 + to wav_count
wav_count 5 >
until
\ loop
opentest
playcapture1
1000 ms winpause
closecapture
;
test