Wav dateien erstellen

  • VB.NET

Es gibt 26 Antworten in diesem Thema. Der letzte Beitrag () ist von XProg.

    Wav dateien erstellen

    Hallo,
    ich möchte ein Programm schreiben mit dem man Wav dateien
    aufnehmen kann, habe aber keine Ahnung wie man das Mikrofon anspricht.
    Wäre echt dankbar für Hilfe.
    Vincent

    *Topic verschoben*

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Marcus Gräfe“ ()

    Ich will mal nicht so sein:
    Hier ein CuP Code

    VB.NET-Quellcode

    1. Private Declare Auto Function mciSendString Lib "winmm.dll" ( _
    2. ByVal lpstrCommand As String, _
    3. ByVal lpstrRetrunString As String, _
    4. ByVal dwReturnlength As Int16, _
    5. ByVal hCallback As Int16) As Integer
    6. ' Aufnahmeformate
    7. Private Enum BitsPerSec
    8. Bits16 = 16
    9. Bits8 = 8
    10. End Enum
    11. Private Enum SampelsPerSec
    12. Sampels8000 = 8000
    13. Sampels11025 = 11025
    14. Sampels12000 = 12000
    15. Sampels16000 = 16000
    16. Sampels22050 = 22050
    17. Sampels24000 = 24000
    18. Sampels32000 = 32000
    19. Sampels44100 = 44100
    20. Sampels48000 = 48000
    21. End Enum
    22. Private Enum Channels
    23. Mono = 1
    24. Stereo = 2
    25. End Enum
    26. ''' <summary>
    27. ''' Startet die WAVE-Aufnahme
    28. ''' </summary>
    29. ''' <param name="BitRate">Bits pro Sekunde</param>
    30. ''' <param name="SampleRate">Samples pro Sekunde</param>
    31. ''' <param name="Mode">Stereo oder Mono-Aufnahme</param>
    32. Private Function WAVE_RecordStart(Optional ByVal BitRate As BitsPerSec = BitsPerSec.Bits16, _
    33. Optional ByVal SampleRate As SampelsPerSec = SampelsPerSec.Sampels11025, _
    34. Optional ByVal Mode As Channels = Channels.Stereo) As Boolean
    35. Dim sReturn As String = Strings.Space(256)
    36. Dim cmd As String
    37. cmd = "open new type waveaudio alias recwave"
    38. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    39. MsgBox("Fehler beim Anlegen der neuen Aufnahmedatei!", MsgBoxStyle.Exclamation)
    40. Return (False)
    41. End If
    42. ' Aufnahmeformat
    43. Dim ByteRate As Integer = (Mode * BitRate * SampleRate) / 8
    44. mciSendString("set recwave time format milliseconds" & _
    45. " bitspersample " & CStr(BitRate) & _
    46. " samplespersec " & CStr(SampleRate) & _
    47. " channels " & CStr(Mode) & _
    48. " bytespersec " & CStr(ByteRate) & _
    49. " alignment 4", sReturn, 256, 0)
    50. cmd = "record recwave"
    51. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    52. MsgBox("Fehler bei der Aufnahme!", MsgBoxStyle.Exclamation)
    53. Return (False)
    54. End If
    55. Return (True)
    56. End Function
    57. ''' <summary>
    58. ''' Beendet die WAVE-Aufnahme
    59. ''' </summary>
    60. ''' <param name="Filename">Datei, unter der die Aufnahme gespeichert werden soll.</param>
    61. Private Function WAVE_RecordStop(ByVal Filename As String) As Boolean
    62. Dim sReturn As String = Strings.Space(256)
    63. Dim cmd As String
    64. Dim Result As Boolean = True
    65. cmd = "stop recwave"
    66. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    67. MsgBox("Fehler beim Beenden der Aufnahme!", MsgBoxStyle.Exclamation)
    68. Return (False)
    69. End If
    70. If Filename.Length > 0 Then
    71. ' Aufnhame in Datei speichern
    72. cmd = "save recwave " & Filename
    73. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    74. MsgBox("Fehler beim Speichern der Aufnahme.", MsgBoxStyle.Exclamation)
    75. Result = False
    76. End If
    77. End If
    78. cmd = "close recwave"
    79. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    80. MsgBox("Fehler beim Schließen der Aufnahme...", MsgBoxStyle.Exclamation)
    81. End If


    Jetzt fügst du 2 Buttons auf die Form:
    Also aus der Toolbox auf die Form ziehen :D
    Du doppelklickst auf den einen und schreibst in die Click prozedur:

    VB.NET-Quellcode

    1. WAVE_RecordStart()


    Das ist der zum Starten der aufnaheme!

    Im anderen Button einfach

    VB.NET-Quellcode

    1. WAVE_RecordStop


    Ok? Viel Spaß!
    Ja ich habe es mir angeschaut! :cursing:

    und auserdem kann ich mehr als nur vb 2008:

    GW-Basic; Quickbasic;vb 6.0; C-Control Pro :cursing:

    Vincent :cursing: :cursing: :cursing: :cursing: :cursing: :cursing: :cursing:

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „Vincent fischer“ ()

    Funkt mein Code nicht? ;( ;( ;( ;( ;( ;( ;( ;( ;( ;(

    Du könntest auch:

    VB.NET-Quellcode

    1. Private Declare Auto Function mciSendString Lib "winmm.dll" ( _
    2. ByVal lpstrCommand As String, _
    3. ByVal lpstrRetrunString As String, _
    4. ByVal dwReturnlength As Int16, _
    5. ByVal hCallback As Int16) As Integer
    6. ' Aufnahmeformate
    7. Private Enum BitsPerSec
    8. Bits16 = 16
    9. Bits8 = 8
    10. End Enum
    11. Private Enum SampelsPerSec
    12. Sampels8000 = 8000
    13. Sampels11025 = 11025
    14. Sampels12000 = 12000
    15. Sampels16000 = 16000
    16. Sampels22050 = 22050
    17. Sampels24000 = 24000
    18. Sampels32000 = 32000
    19. Sampels44100 = 44100
    20. Sampels48000 = 48000
    21. End Enum
    22. Private Enum Channels
    23. Mono = 1
    24. Stereo = 2
    25. End Enum

    Das in deinen Code einfügen und in die jeweiligen Button Handlers dass:

    VB.NET-Quellcode

    1. Dim sReturn As String = Strings.Space(256)
    2. Dim cmd As String
    3. cmd = "open new type waveaudio alias recwave"
    4. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    5. MsgBox("Fehler beim Anlegen der neuen Aufnahmedatei!", MsgBoxStyle.Exclamation)
    6. Return (False)
    7. End If
    8. ' Aufnahmeformat
    9. Dim ByteRate As Integer = (Mode * BitRate * SampleRate) / 8
    10. mciSendString("set recwave time format milliseconds" & _
    11. " bitspersample " & CStr(BitRate) & _
    12. " samplespersec " & CStr(SampleRate) & _
    13. " channels " & CStr(Mode) & _
    14. " bytespersec " & CStr(ByteRate) & _
    15. " alignment 4", sReturn, 256, 0)
    16. cmd = "record recwave"
    17. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    18. MsgBox("Fehler bei der Aufnahme!", MsgBoxStyle.Exclamation)
    19. Return (False)


    bzw. das:

    VB.NET-Quellcode

    1. Dim sReturn As String = Strings.Space(256)
    2. Dim cmd As String
    3. Dim Result As Boolean = True
    4. cmd = "stop recwave"
    5. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    6. MsgBox("Fehler beim Beenden der Aufnahme!", MsgBoxStyle.Exclamation)
    7. Return (False)
    8. End If
    9. If Filename.Length > 0 Then
    10. ' Aufnhame in Datei speichern
    11. cmd = "save recwave " & Filename ' Speicherort!
    12. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    13. MsgBox("Fehler beim Speichern der Aufnahme.", MsgBoxStyle.Exclamation)
    14. Result = False
    15. End If
    16. End If
    17. cmd = "close recwave"
    18. If mciSendString(cmd, sReturn, 256, 0) <> 0 Then
    19. MsgBox("Fehler beim Schließen der Aufnahme...", MsgBoxStyle.Exclamation)
    20. End If
    21. Return (Result)


    Falseds immer noch nicht funkt Hau die "Return/Results) raus

    Viel Glück! :)
    Danke xyz, aber wie ereiche ich es

    dass beim speichern kein Fehler auf tritt(Erstes beispiel)?

    Vincent ^^

    Ps. bzw. Zweites Beispiel
    Dateien
    • Form1.vb

      (6,28 kB, 272 mal heruntergeladen, zuletzt: )

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Vincent fischer“ ()

    @xyz: Ich glaube du musst ihm den ganzen Projektordner in einer zip-Datei hochladen, sonst rafft er das nicht. Er kann nur Klicken. Copy&Paste kann er schon nicht mehr.
    PS: Benutze bloß keine RAR-Datei, denn die kann Windows ja nicht von alleine öffnen (und Vincent wird WinRAR wahrscheinlich nicht finden, weil er nicht G00geln kann).

    EPIC FAIL :thumbdown:
    Gruß
    hal2000
    Mach vincent doch aml nicht so fertig! Ich glaub ich ahb dein Problem:

    VB.NET-Quellcode

    1. My.Computer.Audio.Play(pfad.Text, AudioPlayMode.Background)


    Vileicht pfad.text+".wav"

    Wenn das nicht geht hat der Code nen kleinen Bug es muss gluab ich .wave heisen!

    Sory ich find das Projekt nicht mehr ich hab den code nur in ner .txt :pinch:

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „xyz“ ()

    Hier ist der teil im code der speichern soll

    VB.NET-Quellcode

    1. Private Function WAVE_RecordStop(ByVal Filename As String) As BooleanDim sReturn As String = Strings.Space(256)
    2. Dim cmd As String
    3. Dim Result As Boolean = True
    4. cmd = "stop recwave"
    5. If mciSendString(cmd, sReturn, 256, 0) <> 0 ThenMsgBox("Fehler beim Beenden der Aufnahme!", MsgBoxStyle.Exclamation)
    6. Return (False)
    7. End If
    8. If Filename.Length > 0 Then
    9. ' Aufnhame in Datei speicherncmd = "save recwave " & Filename
    10. If mciSendString(cmd, sReturn, 256, 0) <> 0 ThenMsgBox("Fehler beim Speichern der Aufnahme.", MsgBoxStyle.Exclamation)
    11. Result = False
    12. End If
    13. End If
    14. cmd = "close recwave"
    15. If mciSendString(cmd, sReturn, 256, 0) <> 0 ThenMsgBox("Fehler beim Schlieáen der Aufnahme...", MsgBoxStyle.Exclamation)
    16. End If
    17. End Function


    Vincent 8-)

    ps. Es ist .wav, habs grad ausprobiert

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Vincent fischer“ ()