Link to home
Start Free TrialLog in
Avatar of siewwing
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.
Avatar of jbil
jbil

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
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
ASKER CERTIFIED SOLUTION
Avatar of Eugeny
Eugeny
Flag of Afghanistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial