示例#1
0
 public void Reset()
 {
     //Init a new VAD state in the existing space
     if (WebRtcVadNativeMethods.Dissonance_WebRtcVad_Init(_handle) != 0)
     {
         throw new WebRtcVadException(Log.PossibleBugMessage("Failed to re-initialize WebRTC VAD", "4A2E754F-5031-476C-A6FA-C0F883832806"));
     }
 }
示例#2
0
            public void Dispose()
            {
                if (_disposed)
                {
                    return;
                }

                GC.SuppressFinalize(this);

                if (_handle != IntPtr.Zero)
                {
                    WebRtcVadNativeMethods.Dissonance_WebRtcVad_Free(_handle);
                    _handle = IntPtr.Zero;
                }

                _disposed = true;
            }
示例#3
0
            public bool Process(ArraySegment <short> frame)
            {
                if (frame.Count != _frameSize)
                {
                    throw Log.CreatePossibleBugException(string.Format("Frame is incorrect size (expected {0} for {1})", _frameSize, frame.Count), "716C8CBD-8014-4C57-889C-0450ECF96A0F");
                }

                using (var pin = frame.Pin())
                {
                    var result = WebRtcVadNativeMethods.Dissonance_WebRtcVad_Process(_handle, _sampleRate, pin.Ptr, new UIntPtr((uint)frame.Count));

                    if (result == -1)
                    {
                        throw Log.CreatePossibleBugException("Unknown error processing audio", "9BBD8BB1-B08D-4F34-AFF2-AAF32F69C309");
                    }
                    return(result == 1);
                }
            }
示例#4
0
            public VAD(uint frameSize, int sampleRate, Aggressiveness mode = Aggressiveness.Normal)
            {
                _frameSize  = frameSize;
                _sampleRate = sampleRate;

                if (!IsValidUsage(sampleRate, frameSize))
                {
                    throw new WebRtcVadException(Log.PossibleBugMessage("Failed to initialize WebRTC VAD (incorrect frame size or sample rate)", "E74CF7D3-51C0-4240-B552-02EB58EAE34D"));
                }

                //Create handle
                _handle = WebRtcVadNativeMethods.Dissonance_WebRtcVad_Create();
                if (WebRtcVadNativeMethods.Dissonance_WebRtcVad_Init(_handle) != 0)
                {
                    throw new WebRtcVadException(Log.PossibleBugMessage("Failed to initialize WebRTC VAD", "87596AD8-9096-4FEB-867D-B23A1A7F7F91"));
                }

                //Initialize defaults
                Mode = mode;
            }
示例#5
0
 private static bool IsValidUsage(int sampleRate, uint frameLength)
 {
     return(WebRtcVadNativeMethods.Dissonance_WebRtcVad_ValidRateAndFrameLength(sampleRate, new UIntPtr(frameLength)) == 0);
 }