How to Write WAV File With Vb6

Developed and maintained by Microsoft, VB -- short for Visual Basic -- is an event-driven programming language and IDE (Integrated Development Environment). It is a very flexible language and can even be used to write WAV (Waveform Audio) files easily, by using the MCI functions. You can start, pause, resume and stop the video playback and can even set the time format to milliseconds. If you want to record for just milliseconds, VB6 allows you to do so.

Instructions

    • 1

      Start a new VB6 project and declare the MCI function, using this code:

      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 "lpstrReturnString" is used to receive return information, "uReturnLength" stores the number of characters in the "lpstrReturnString." You can use the last function, "hwndCallback" for system notifications.

    • 2

      Open the WAV device by using this code:

      CommandString = "Open new type waveaudio alias YourWavFile"

      The "YourWavFile" is your MCI memory buffer and you can replace it with any other alias. You will write this buffer to disk later to create a WAV file.

    • 3

      Insert this line to set the time format to milliseconds:

      CommandString = "Set YourWavFile time format milliseconds"

      This action is not mandatory.

    • 4

      Write to the MCI buffer by using this line:

      CommandString = "Record YourWavFile"

    • 5

      Pause writing to the buffer with this line:

      CommandString = "Pause YourWavFile"

    • 6

      Resume writing to the buffer with this code:

      CommandString = "Resume YourWavFile"

    • 7

      Stop writing to the buffer by using this line:

      CommandString = "Stop YourWavFile"

      You must stop writing to the MCI buffer before you can write from the buffer to a WAV file.

    • 8

      Create the WAV file from the MCI buffer and close the WAV device by inserting these two lines:

      CommandString = "Save YourWavFile" & FileName
      CommandString = "Close YourWavFile"

Tips & Warnings

  • Use the "CommandString = "Record YourWavFile to 2000 wait" line if you want to record for a specified period of time, two seconds in this case.

  • You can use these commands inside your functions to customize the way you record and write the WAV file.

Related Searches:

References

Comments

Related Ads

Featured