You can use MCI functions if you want to record a WAV file. The main MCI function is mciSendString
, that sends command strings to the system and execute them.
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
The first argument is the command string, lpstrReturnString
receives return information (if needed), uReturnLength
is the number of characters in lpstrReturnString, and hwndCallback
is used for system notifications. Remember that every command string described in this tip must be sent to the system as follows:
CommandString = "your MCI command here"
RetVal = mciSendString(CommandString, vbNullString, 0, 0&)
The first thing to do when working with WAV files is open the WAV device with this statement:
CommandString = "Open new type waveaudio alias RecWavFile"
where "RecWavFile" is an alias, that is an arbitrary name that you'll use in the next command strings to refer to a particular MCI memory buffer (and that you later save to disk). Then you can start, pause or resume and stop recording with one of the following statements:
' start recording
CommandString = "Record RecWavFile"
' pause recording
CommandString = "Pause RecWavFile "
' resume recording
CommandString = "Resume RecWavFile "
' stop recording
CommandString = "Stop RecWavFile"
You can also set the time format in milliseconds:
CommandString = "Set RecWavFile time format milliseconds"
and you can record for a number of milliseconds and then terminate:
' record for only 2 seconds
CommandString = "Record RecWavFile to 2000 wait"
When you have completed your recording homework, you must save the WAV file to file, which you do with
CommandString = "Save RecWavFile " & FileName
Finally, always remember to close the device with Close command:
CommandString = "Close RecWavFile"