1
我正在使用NAudio和Visual Basic的簡單錄音機。我正在使用.NET 4.0和Visual Studio 2013社區。 是否可以暫停音頻記錄,然後恢復錄製?使用NAudio暫停錄音
這是我的代碼進行錄音:
Dim micWaveIn As IWaveIn
Dim micFileWriter As WaveFileWriter
Dim tempFolderPath As String = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "recordings")
Private Sub cmdStartRecord_Click(sender As Object, e As EventArgs) Handles cmdStartRecord.Click
Dim micDevice = DirectCast(cboInputDevice.SelectedItem, MMDevice)
micDevice.AudioEndpointVolume.Mute = False
micWaveIn = New WasapiCapture(micDevice)
AddHandler micWaveIn.DataAvailable, AddressOf MIC_AudioDataAvailable
AddHandler micWaveIn.RecordingStopped, AddressOf MIC_AudioStopRecording
Dim filePath As String = IO.Path.Combine(tempFolderPath, "mic_record.wav")
micFileWriter = New WaveFileWriter(filePath, micWaveIn.WaveFormat)
micWaveIn.StartRecording()
End Sub
Private Sub cmdStopRecord_Click(sender As Object, e As EventArgs) Handles cmdStopRecord.Click
If micWaveIn IsNot Nothing Then
micWaveIn.StopRecording()
RemoveHandler micWaveIn.DataAvailable, AddressOf MIC_AudioDataAvailable
RemoveHandler micWaveIn.RecordingStopped, AddressOf MIC_AudioStopRecording
micWaveIn.Dispose()
micWaveIn = Nothing
End If
If micFileWriter IsNot Nothing Then
micFileWriter.Dispose()
micFileWriter = Nothing
End If
End Sub
Private Sub MIC_AudioDataAvailable(sender As Object, e As WaveInEventArgs)
If micFileWriter IsNot Nothing Then
micFileWriter.Write(e.Buffer, 0, e.BytesRecorded)
End If
End Sub
Private Sub MIC_AudioStopRecording(sender As Object, e As StoppedEventArgs)
If e.Exception IsNot Nothing Then
MsgBox("Error while recording.", vbExclamation, "Error.")
End If
End Sub
我目前在思考這個代碼:
Private Sub MIC_AudioDataAvailable(sender As Object, e As WaveInEventArgs)
If micFileWriter IsNot Nothing Then
If isRecording Then
micFileWriter.Write(e.Buffer, 0, e.BytesRecorded)
End If
End If
End Sub
但輸出音頻不能在我的電腦中播放。任何建議?