This project has moved and is read-only. For the latest updates, please go here.

"StarRecording"

Mar 12, 2015 at 7:45 PM
I developed around DLL NAudio a professional application and randomly, for some reason, when I run the command 'StartRecording', there is no data that arrives in a routine 'DataAvailable'! Someone would have an idea?

Thank you in advance
Mar 12, 2015 at 10:13 PM
what class are you using to record? WaveIn? WasapiIn?
Mar 15, 2015 at 12:15 PM
I used WaveIn Without explore WasapiIn because WaveIn fits perfectly with what I do.

Here is my code :

Imports NAudio.Wave
Imports System.Runtime.InteropServices
Friend Class NaudioMicro
...

Region "Déclarations"

'Autorisation d'exporter le flux Audio
Private Transmit As Integer = 0
'Indique que le recorder est en mode capture
Private IsCapturing As Integer = 0
'Recorder Naudio
Private WithEvents _WaveInDevice As NAudio.Wave.WaveIn

End Region

Region "Constructor"

Public Sub New()
    Dim DeviceInfoI As WaveInCapabilities
    Try
        '1. Détection automatique du Micro Peiker
        Dim DeviceNumber As Integer = -1
        For I As Integer = 0 To WaveIn.DeviceCount - 1
            DeviceInfoI = WaveIn.GetCapabilities(I)
            If Val("&H" & Strings.Left(DeviceInfoI.ProductGuid.ToString, 2)) > 0 Then
                If InStr(DeviceInfoI.ProductName, "PTC USB", CompareMethod.Text) > 0 Then
                    DeviceNumber = I
                    Exit For
                End If
            End If
        Next
'2. Configuration du Recorder avec Micro Peiker
        If DeviceNumber >= 0 Then
            _WaveInDevice = New WaveIn()
            _WaveInDevice.DeviceNumber = DeviceNumber
            _WaveInDevice.WaveFormat = New WaveFormat(8000, 16, 1)
            _WaveInDevice.NumberOfBuffers = 2
            _WaveInDevice.BufferMilliseconds = 60
        End If
    Catch Ex As Exception
    End Try
End Sub

End Region

Region "Event"

Friend Event OnError(ByVal Source As String, ByVal Message As String)
Friend Event OnDeliverySpeechData(ByVal SpeechData() As Byte)

End Region

Region "Commandes"

   Private Sub CaptureStart()
    Try
        If _WaveInDevice Is Nothing Then
            Return
        End If
        If IsCapturing = 0 Then
            IsCapturing = 1
            _WaveInDevice.StartRecording()
        End If
    Catch Ex As Exception
        RaiseEvent OnError("CaptureStart", Ex.Message)
    End Try
End Sub
 Private Sub CaptureStop()
    If _WaveInDevice Is Nothing Then
        Return
    End If
    If IsCapturing = 1 Then
        IsCapturing = 0
        _WaveInDevice.StopRecording()
        Transmit = 0
    End If
End Sub
Friend Sub StartCapture()
    Transmit = 1
    CaptureStart()
End Sub
Friend Sub StopCapture()
    Transmit = 0
    CaptureStop()
End Sub

End Region

Region "Processus_internes"

Private Sub DataAvailable(ByVal sender As Object, ByVal e As NAudio.Wave.WaveInEventArgs) Handles _WaveInDevice.DataAvailable
    Try
        If My.Settings.SendSpeechDirect = 1 Then
            Dim AIOPCMFrame As New _D25AIOPCMFRAME
            AIOPCMFrame.sz = e.Buffer.Length
            AIOPCMFrame.m_aFrame = Marshal.AllocHGlobal(e.Buffer.Length)
            Marshal.Copy(e.Buffer, 0, AIOPCMFrame.m_aFrame, e.Buffer.Length)
            Call IHM.Appels.DiffusionMicro(AIOPCMFrame)
            If IHM.LoopBack = 1 Then
                If IHM.PlayBackJingleInProgress = 0 Then
                    If My.Settings.AudioEmbeded = 0 Then
                        IHM.Players.Player(0).PlayPacket(e.Buffer)
                    Else
                        IHM.LocalPlayer.PlayPacket(e.Buffer)
                    End If
                End If
            End If
        Else
            RaiseEvent OnDeliverySpeechData(e.Buffer)
        End If
    Catch Ex As Exception
    End Try
End Sub

End Region

...
End Class
Mar 16, 2015 at 6:32 PM
What sort of app are you using? WaveIn can be used with WinForms or WPF, but if it is a console app you'll need to go with WaveInEvent