MP3 Datei vom Mikrofon aufnehmen und abspeichern

Terminator2

Erfahrenes Mitglied
weiß jemand, wie ich mit VB ein Fenster erstellen kann, in dem ich mit ein paar Buttons kurze MP3 Dateien oder zur Not auch andere Formate aufnehmen kann?

Die Datei soll dann hinterher auf einen bestimmten Dateinamen umbenannt werden und in einen speziellen Ordner kopiert werden, und dort die vorhandene Datei überschreiben.

Danke im vorraus
 
Hi,

Also der Quellcode funktioniert an sich schon mal. Das mit der Qualität krieg ich sowieso nicht hin, weil die Kommentare ein bisschen zu kurz sind. Ich poste den Quellcode einfach mal und wenn einer weiß, wie das mit der Quali klappt, wäre es nett, wenn er mir den Code schreiben könnte.
Dazu kommt aber noch, dass 8 verschiedene Sound Dateien überschrieben werden sollen. Dafür habe ich 8 Option Felder erstellt. Aber ich bekomme dann immer so ne Fehlermeldung mit der man wie immer nix anfangen kann, wenn man nicht schon 10 Jahre mit VB programmiert.

Also hier der Code:

Code:
Option Explicit

Private Declare Function mciSendString Lib "winmm.dll" Alias _
        "mciSendStringA" (ByVal lpstrCommand As String, _
        ByVal lpstrReturnString As String, ByVal uReturnLength _
        As Long, ByVal hwndCallback As Long) As Long

Private Declare Function PlaySound Lib "winmm.dll" Alias _
        "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal _
        uFlags As Long) As Long

Dim RS$, CB&
'Ende Deklarationen Sound Aufnahme

'Start Bedienfeld Sound
Private Sub Command1_Click()

Dim Path As Integer

If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"

  If Dir$(Path, vbNormal) <> "" Then Kill Path
  RS = Space$(128)
      
  Call mciSendString("open new type waveaudio alias capture", _
                     RS, 128, CB)
  Call mciSendString("record capture", RS, 128, CB)
  
  Command1.Enabled = False
  Command2.Enabled = True
  Command3.Enabled = True
  Command4.Enabled = False
End Sub

Private Sub Command2_Click()
  If Command2.Caption = "Pause" Then
    Call mciSendString("pause capture", RS, 128, CB)
    Command2.Caption = "Weiter"
    
    Command1.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = False
  Else
    Call mciSendString("record capture", RS, 128, CB)
    Command2.Caption = "Pause"
    
    Command1.Enabled = False
    Command3.Enabled = True
    Command4.Enabled = False
  End If
End Sub

Private Sub Command3_Click()

Dim Path As Integer

If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"

  RS = Space$(128)
  Call mciSendString("stop capture", RS, 128, CB)
  Call mciSendString("save capture " & Path, RS, 128, CB)
  Call mciSendString("close capture", RS, 128, CB)
  
  Command1.Enabled = True
  Command2.Enabled = False
  Command3.Enabled = False
  Command4.Enabled = True
End Sub

Private Sub Command4_Click()

Dim Path As Integer

If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"

  Call PlaySound(Path, 0)
  
  Command1.Enabled = True
  Command2.Enabled = False
  Command3.Enabled = False
End Sub
 
Also ich würd erstmal vorschlagen, dass du die ganzen OptionX-Vars durch ein einziges Bool-Array ersetzt. Damit sparste viel Quellcode.... Und wenn du noch nicht mit Arrays umgehen kannst, dann lies dir ein Tutorial durch. Die sind wirklich praktisch;)

Natürlich wärs auch nützlich, wenn du mal die Fehlermeldung und den Ort wo sie auftritt posten würdest.
 
So,

Von Arrays habe ich in Java Script schon mal was gehört und auch "programmiert".
Ich arbeite mich mal durch ein Tutorial durch.
Wenn ich auf Rec drücke (Command1) erscheint:
Laufzeitfehler:'13'
Typen unverträglich

Und dann wars das, programm schließt sich und ich ärgere mich... ;-)

Schon mal danke, immerhin ein Anfang. (Ich nehme übrigens an, dass der Fehler wegen den Option Boxen kommt)
 
Hi,

hier mal Dein Code aufgearbeitet.
Pack mal auf Deine Form noch zusätzlich eine ComboBox:
Code:
Option Explicit

Private Declare Function mciSendString Lib "winmm.dll" Alias _
        "mciSendStringA" (ByVal lpstrCommand As String, _
        ByVal lpstrReturnString As String, ByVal uReturnLength _
        As Long, ByVal hwndCallback As Long) As Long

Private Declare Function PlaySound Lib "winmm.dll" Alias _
        "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal _
        uFlags As Long) As Long

Dim sRetString  As String
Dim lCallBack   As Long


'Start Bedienfeld Sound
Private Sub Command1_Click()

    
    'Dim Path As Integer
    'If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
    'If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
    'If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
    'If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
    'If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
    'If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
    'If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
    'If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"
    
    Dim sPath   As String
    sPath = cboFileSelect.List(cboFileSelect.ListIndex)
    If (Dir$(sPath, vbNormal) <> vbNullString) Then
        Call Kill(sPath)
    End If
    
    sRetString = Space$(128)
        
    Call mciSendString("open new type waveaudio alias capture", _
                       sRetString, 128, lCallBack)
    Call mciSendString("record capture", sRetString, 128, lCallBack)
  
    Command1.Enabled = False
    Command2.Enabled = True
    Command3.Enabled = True
    Command4.Enabled = False
End Sub

Private Sub Command2_Click()
  
    If (Command2.Caption = "Pause") Then
        Call mciSendString("pause capture", sRetString, 128, lCallBack)
        Command2.Caption = "Weiter"
        
        Command1.Enabled = False
        Command3.Enabled = False
        Command4.Enabled = False
    Else
        Call mciSendString("record capture", sRetString, 128, lCallBack)
        
        Command2.Caption = "Pause"
        Command1.Enabled = False
        Command3.Enabled = True
        Command4.Enabled = False
  End If
End Sub

Private Sub Command3_Click()

'    Dim Path As Integer
'    If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
'    If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
'    If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
'    If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
'    If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
'    If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
'    If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
'    If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"

    sRetString = Space$(128)
        
    Dim sPath   As String
    sPath = cboFileSelect.List(cboFileSelect.ListIndex)
    
    Call mciSendString("stop capture", sRetString, 128, lCallBack)
    Call mciSendString("save capture " & sPath, sRetString, 128, lCallBack)
    Call mciSendString("close capture", sRetString, 128, lCallBack)
  
    Command1.Enabled = True
    Command2.Enabled = False
    Command3.Enabled = False
    Command4.Enabled = True
End Sub

Private Sub Command4_Click()
    
    ' wie kommst Du darauf, einen String
    ' in einem Integer zuzuordnen?
    
    'Dim Path As Integer
    'If Option1 = True Then Path = "C:\Sound\Play1\Play1_2.wav"
    'If Option2 = True Then Path = "C:\Sound\Play2\Play2_2.wav"
    'If Option3 = True Then Path = "C:\Sound\Play3\Play3_2.wav"
    'If Option4 = True Then Path = "C:\Sound\Play4\Play4_2.wav"
    'If Option5 = True Then Path = "C:\Sound\Play5\Play5_2.wav"
    'If Option6 = True Then Path = "C:\Sound\Play6\Play6_2.wav"
    'If Option7 = True Then Path = "C:\Sound\Play7\Play7_2.wav"
    'If Option8 = True Then Path = "C:\Sound\Play8\Play8_2.wav"

    Dim sPath   As String
    sPath = cboFileSelect.List(cboFileSelect.ListIndex)
    
    Call PlaySound(sPath, 0)
  
    Command3.Enabled = True
    Command2.Enabled = False
    Command3.Enabled = False
End Sub

Private Sub Form_Load()
    
    ' hier eventuell noch die Pfadauswahl einbauen,
    ' dann allerdings nicht im Form_Load
    Const FILENAME As String = "C:\Sound\Play*\Play*_2.wav"
    
    Dim i As Long
    Dim s As String
    
    For i = 1 To 8
        ' dateinamen zusammenbauen
        ' replace esRetStringtetzt * durch i
        s = Replace$(FILENAME, "*", CStr(i))
        ' item eintragen
        Call cboFileSelect.AddItem(s)
    Next i
End Sub

Wie Du im Code schon siehst, kommt der Fehler nicht wegen den Optionbuttons!
Du hast eine Variable (Path) vom Typ Integer deklariert und weißt der einen String zu !

Code ungetestet (da kein Micro und Zeit), lässt sich aber kompilieren.
 
Zurück