Advertisement
Robomatics

Recording from a Microphone

Apr 25th, 2013
3,629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.28 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class Form1
  4.  
  5.     Dim recording As Boolean = False
  6.     Dim Filez As String = "C:\\Test.wav"
  7.  
  8.     <DllImport("winmm.dll")> _
  9.     Private Shared Function mciSendString(ByVal command As String, ByVal buffer As String, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
  10.     End Function
  11.  
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.  
  14.         If recording = False Then
  15.             mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
  16.             mciSendString("record recsound", "", 0, 0)
  17.             recording = True
  18.             Button1.Text = "Stop"
  19.         Else
  20.             mciSendString("save recsound " & Filez, "", 0, 0)
  21.             mciSendString("close recsound ", "", 0, 0)
  22.             Button2.Enabled = True
  23.             recording = False
  24.             Button1.Text = "Record"
  25.         End If
  26.  
  27.     End Sub
  28.  
  29.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  30.         My.Computer.Audio.Play(Filez)
  31.     End Sub
  32.  
  33.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  34.         Button2.Enabled = False
  35.     End Sub
  36. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement