Mikrofon Aufzeichnen (recorden) Und Speichern

    • VB.NET

    Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von thefiloe.

      Mikrofon Aufzeichnen (recorden) Und Speichern

      Hallo ich wollte gerade mal ein Tutorial wir ihr eine Sprachaufzeichnung macht.
      Das ganz ist eigentlich recht Simpel!

      Ihr braucht:
      -Visual Basic min.2008
      -Form
      -2 Textboxen
      -3 Buttons
      -Folderbrowserdialog
      Das wars!

      In der Textbox1 soll der Dateispeicherort rein kommen
      eiso den Button darunter damit ihr den Folderbrowserdialog öffnen könnt und somit
      dann den Speicherort als Text in die Textbox1 bringt.
      In der Textbox2 soll der Name der Datei reingeschrieben werden
      Button 2 ist um die Aufnahme zu beginnen.
      Button 3 um die Aufnahme zu beenden.
      Ihr könnt ja Start und Stop reinschreiben oder so ;)

      Jetzt zum Programmieren:


      Am Anfang macht ihr noch eine Funktion und Dim´s geregt unter Public Class Form1

      VB.NET-Quellcode

      1. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal Command As String, ByVal Returnstring As String, ByVal returnlength As Integer, ByVal callback As Integer) As Integer
      2. Dim returnstring As String
      3. Dim callback As Integer


      Als erstes Programmieren wir den Öffnen des Folderbrowserdialog Buttons:

      VB.NET-Quellcode

      1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      2. FolderBrowserDialog1.ShowDialog()
      3. TextBox1.Text = (FolderBrowserDialog1.SelectedPath)
      4. End Sub

      Dann den Aufnahme Start Button:

      VB.NET-Quellcode

      1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      2. returnstring = New String(" ", 128)
      3. Call mciSendString("Open New Type waveaudio Alias capture", returnstring, 128, callback)
      4. Call mciSendString("record capture", returnstring, 128, callback)
      5. End Sub

      Dannach den Stop Button:

      VB.NET-Quellcode

      1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      2. Dim aufnahmepfad As String = TextBox1.Text + "\" + TextBox2.Text + ".wav"
      3. Call mciSendString("Stop capture", returnstring, 128, callback)
      4. Call mciSendString("save capture " & aufnahmepfad, returnstring, 128, callback)
      5. Call mciSendString("Close capture", returnstring, 128, callback)
      6. End Sub


      Falls jemand Faul ist kann er auch den Code hier Komplett haben:
      Spoiler anzeigen

      VB.NET-Quellcode

      1. Public Class Form1
      2. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal Command As String, ByVal Returnstring As String, ByVal returnlength As Integer, ByVal callback As Integer) As Integer
      3. Dim returnstring As String
      4. Dim callback As Integer
      5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      6. FolderBrowserDialog1.ShowDialog()
      7. TextBox1.Text = (FolderBrowserDialog1.SelectedPath)
      8. End Sub
      9. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      10. returnstring = New String(" ", 128)
      11. Call mciSendString("Open New Type waveaudio Alias capture", returnstring, 128, callback)
      12. Call mciSendString("record capture", returnstring, 128, callback)
      13. End Sub
      14. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      15. Dim aufnahmepfad As String = TextBox1.Text + "\" + TextBox2.Text + ".wav"
      16. Call mciSendString("Stop capture", returnstring, 128, callback)
      17. Call mciSendString("save capture " & aufnahmepfad, returnstring, 128, callback)
      18. Call mciSendString("Close capture", returnstring, 128, callback)
      19. End Sub
      20. End Class



      Das war der Teil mit dem Programmieren!
      Das War das Tutorial ich hoffe es gefällt euch und ihr könnt was damit anfangen.
      Über Feedback usw. Freue ich mich wie immer! 8o :thumbsup:

      Mfg GMT
      Hallo
      Habe dies hier im Forum gefunden,ist auch nur Kopiert und etwas umgeschrieben.
      Den Link habe ich absichtlich vergessen. :D

      VB.NET-Quellcode

      1. Public Class Form1
      2. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal Command As String, _
      3. ByVal ReturnString As String, ByVal ReturnLength As Integer, ByVal Callback As Integer) As Integer
      4. Dim Path As String = "Test.wav"
      5. Dim rs As String
      6. Dim cb As Integer
      7. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      8. ' If Button1.Text = "Record" Then
      9. 'Button1.Text = "Stop"
      10. Button2.Enabled = False
      11. Button4.Enabled = True
      12. rs = New String(" ", 128)
      13. Call mciSendString("Open New Type waveaudio Alias capture", rs, 128, cb)
      14. Call mciSendString("record capture", rs, 128, cb)
      15. ' Else
      16. ' Button1.Text = "Record"
      17. ' Button2.Enabled = True
      18. ' Call mciSendString("Stop capture", rs, 128, cb)
      19. ' Call mciSendString("save capture " & Path, rs, 128, cb)
      20. 'Call mciSendString("Close capture", rs, 128, cb)
      21. ' End If
      22. End Sub
      23. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      24. Button1.Text = "Record"
      25. Button3.Text = "Play Halt"
      26. Button3.Enabled = False
      27. Button2.Text = "Play"
      28. Button4.Text = "Record Halt"
      29. Button4.Enabled = False
      30. Button2.Enabled = True
      31. End Sub
      32. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      33. My.Computer.Audio.Play(Path, AudioPlayMode.Background)
      34. ' Button1.Enabled = True
      35. Button3.Enabled = True
      36. Button2.Enabled = False
      37. Button4.Enabled = False
      38. Button1.Enabled = False
      39. End Sub
      40. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      41. 'play halt
      42. 'Button1.Text = "Record"
      43. ' Button1.Enabled = False
      44. Button2.Enabled = True
      45. Button1.Enabled = True
      46. Button3.Enabled = False
      47. End Sub
      48. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
      49. 'Record Halt
      50. Call mciSendString("Stop capture", rs, 128, cb)
      51. Call mciSendString("save capture " & Path, rs, 128, cb)
      52. Call mciSendString("Close capture", rs, 128, cb)
      53. Button3.Enabled = False
      54. Button2.Enabled = True
      55. Button4.Enabled = False
      56. End Sub
      57. End Class




      Das War das Tutorial ich hoffe


      Das immer die Quellen angegeben werde,es ist doch nicht dabei.
      Nicht die von "Oben" sondern das Original.
      ;)

      Grüße

      GMT schrieb:

      Ihr braucht:
      -Visual Basic min.2008

      Wenn du schon auf VB2008 bestehst, dann solltest du auch die .NET-Deklarationen für die API-Funktion benutzen.

      VB.NET-Quellcode

      1. <DllImport("winmm.dll")> _
      2. Private Shared Function mciSendString(ByVal command As String, ByVal buffer As StringBuilder, ByVal bufferSize As Integer, ByVal hwndCallback As IntPtr) As Integer
      3. End Function

      pinvoke.net/default.aspx/winmm/mciSendString.html
      Von meinem iPhone gesendet
      Kann ich diese Lib wimm.dll und die API auch so verwenden, dass ich einmal mit My.Computer.Audio.Play(...) eine Datei abspiele und mit dann den Prozess "aufnehme"? Also so wie man(/ich) das fürher mit Kassetten gemacht habe? Also ob man die Aufnahmefunktion auf einen Prozess/eine Ausgabe-Einheit oder so was lenken kann.
      Mfg und danke schon ma im Vorraus!
      In general (across programming languages), a pointer is a number that represents a physical location in memory. A nullpointer is (almost always) one that points to 0, and is widely recognized as "not pointing to anything". Since systems have different amounts of supported memory, it doesn't always take the same number of bytes to hold that number, so we call a "native size integer" one that can hold a pointer on any particular system. - Sam Harwell
      Da Windows intern alle Prozesse zusammenmixt ist es nicht möglich einen einzelnen Prozess aufzunehmen. Einziges was du kannst ist, das Zusammengemixte aufnehmen (jedoch wohl kaum mit dem "pseudo-aufnahme code"). Bei einer solchen Aufnahme sind dann aber halt ALLE Prozesse mit hörbar.


      Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.