siewwing
asked on
Recording sound in VB
I need to record a 2 second spoken voice (in wav format) in VB with a click of a button. The code should automatically save the recorded voice into a wave file. How do I do that? I don't want to use the Windows Sound Recorder to do that.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub Command1_Click()
On Local Error Resume Next
Dim i As Long, RS As String, cb As Long, t#
Dim start
RS = Space$(500)
Kill "c:\cdtest.wav" 'Delete old wav file there
start = Timer
Do While Timer < (start + 2)
DoEvents
i = mciSendString("open new type waveaudio alias capture", RS, 128, cb)
i = mciSendString("record capture", RS, 128, cb)
Loop
i = mciSendString("stop capture", RS, 128, cb)
i = mciSendString("save capture c:\cdtest.wav", RS, 128, cb)
i = mciSendString("close capture", RS, 128, cb)
End Sub