### Install WebRtcVadSharp NuGet Package Source: https://github.com/ladenedge/webrtcvadsharp/blob/main/README.md Install the WebRtcVadSharp package using the NuGet Package Manager Console. This includes the .NET Standard adapter and the unmanaged WebRTC library. ```powershell Install-Package WebRtcVadSharp ``` -------------------------------- ### Pre-configure VAD and Process Audio File (C#) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/Home This example shows how to configure the VAD with specific operating mode, frame length, and sample rate before processing an entire audio file frame by frame. It calculates the frame size based on the configuration and reads audio data into a buffer for speech detection. ```csharp using var vad = new WebRtcVad() { OperatingMode = OperatingMode.Aggressive, FrameLength = FrameLength.Is30ms, SampleRate = SampleRate.Is16kHz, }; var frameSize = (int)vad.SampleRate / 1000 * 2 * (int)vad.FrameLength; var buffer = new byte[frameSize]; using var audio = OpenAudioFile(filename); for (int i = 0; i < audio.Length - frameSize; i += frameSize) { audio.Read(buffer, 0, buffer.Length); var hasSpeech = vad.HasSpeech(buffer); Console.WriteLine($"Frame {i}: {hasSpeech}"); } ``` -------------------------------- ### WebRtcVadSharp OperatingMode Property Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.OperatingMode Gets or sets the aggressiveness of the voice activity detection. Defaults to HighQuality. ```csharp public OperatingMode OperatingMode { get; set; } ``` -------------------------------- ### WebRtcVad SampleRate Property Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.SampleRate Gets or sets the sample rate when using the audio-only HasSpeech(byte[]) overload. Defaults to Is8kHz. ```csharp public SampleRate SampleRate { get; set; } ``` -------------------------------- ### WebRtcVad FrameLength Property Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.FrameLength Gets or sets the frame length when using the audio-only HasSpeech(byte[]) overload. Defaults to Is10ms. ```csharp public FrameLength FrameLength { get; set; } ``` -------------------------------- ### WebRtcVad() constructor Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad-Constructors Creates and initializes a WebRTC voice activity detector using the default P/Invoke implementation. ```APIDOC ## WebRtcVad() ### Description Creates and initializes a WebRTC voice activity detector. ### Method Constructor ### Parameters This constructor does not take any parameters. ### Request Example ```csharp var vad = new WebRtcVad(); ``` ### Response Initializes a new instance of the WebRtcVad class. ``` -------------------------------- ### WebRtcVad(IWebRtcDll) Constructor Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad-Constructors Creates and initializes a WebRTC voice activity detector by injecting a WebRTC library. This is useful for unit testing. ```csharp public WebRtcVad(IWebRtcDll library); ``` -------------------------------- ### WebRtcVad Constructors Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad Initializes a WebRTC voice activity detector. The constructor without parameters uses default settings, while the constructor with IWebRtcDll allows for custom DLL injection. ```APIDOC ## WebRtcVad() ### Description Creates and initializes a WebRTC voice activity detector with default settings. ### Method Constructor ### Parameters None ## WebRtcVad(IWebRtcDll) ### Description Creates and initializes a WebRTC voice activity detector, allowing for custom DLL injection. ### Method Constructor ### Parameters * **webRtcDll** (IWebRtcDll) - Required - An interface for the WebRTC DLL. ``` -------------------------------- ### WebRtcVad() Constructor Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad-Constructors Creates and initializes a WebRTC voice activity detector. Use this constructor for standard initialization. ```csharp public WebRtcVad(); ``` -------------------------------- ### WebRtcVad(IWebRtcDll) constructor Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad-Constructors Creates and initializes a WebRTC voice activity detector, injecting a WebRTC library for unit testing. ```APIDOC ## WebRtcVad(IWebRtcDll) ### Description Creates and initializes a WebRTC voice activity detector by injecting a WebRTC library, which is useful for unit testing. ### Method Constructor ### Parameters #### Path Parameters - **library** (IWebRtcDll) - Required - Interface for the underlying WebRTC library. ### Request Example ```csharp // Assuming 'mockWebRtcDll' is an implementation of IWebRtcDll var vad = new WebRtcVad(mockWebRtcDll); ``` ### Response Initializes a new instance of the WebRtcVad class with the specified WebRTC library. ``` -------------------------------- ### Basic Speech Detection with WebRtcVadSharp Source: https://github.com/ladenedge/webrtcvadsharp/blob/main/README.md Instantiate a WebRtcVad object and use the HasSpeech method to detect speech in a raw audio frame. Ensure to use a 'using' block as WebRtcVad implements IDisposable. ```csharp bool DoesFrameContainSpeech(byte[] audioFrame) { using var vad = new WebRtcVad(); return vad.HasSpeech(audioFrame, SampleRate.Is8kHz, FrameLength.Is10ms); } ``` -------------------------------- ### WebRtcVad Methods Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad Provides methods for disposing of resources and detecting speech in audio frames. ```APIDOC ## Dispose() ### Description Dispose the underlying WebRTC resources. ### Method Method ### Parameters None ## HasSpeech(byte[]) ### Description Test whether the supplied frame contains speech. ### Method Method ### Parameters * **frame** (byte[]) - Required - The audio frame to analyze. ## HasSpeech(byte[], SampleRate,FrameLength) ### Description Test whether the supplied frame contains speech with specified sample rate and frame length. ### Method Method ### Parameters * **frame** (byte[]) - Required - The audio frame to analyze. * **sampleRate** (SampleRate) - Required - The sample rate of the audio frame. * **FrameLength** (FrameLength) - Required - The frame length of the audio frame. ``` -------------------------------- ### Dispose() Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.Dispose() This is the method signature for disposing of WebRTC resources. Call this method when you are finished with the WebRtcVad instance to free up system resources. ```csharp public void Dispose(); ``` -------------------------------- ### C# HasSpeech(IntPtr, SampleRate, FrameLength) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This overload allows checking for speech in an audio frame represented by an IntPtr while explicitly providing the sample rate and frame length. This bypasses the VAD's default properties. ```csharp public bool HasSpeech(IntPtr audioFrame, SampleRate sampleRate, FrameLength frameLength); ``` -------------------------------- ### C# HasSpeech(short[], SampleRate, FrameLength) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This overload allows checking for speech in a short array audio frame while explicitly providing the sample rate and frame length. This bypasses the VAD's default properties. ```csharp public bool HasSpeech(short[] audioFrame, SampleRate sampleRate, FrameLength frameLength); ``` -------------------------------- ### C# HasSpeech(byte[], SampleRate, FrameLength) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This overload allows checking for speech in a byte array audio frame while explicitly providing the sample rate and frame length. This bypasses the VAD's default properties. ```csharp public bool HasSpeech(byte[] audioFrame, SampleRate sampleRate, FrameLength frameLength); ``` -------------------------------- ### WebRtcVad.HasSpeech(IntPtr, SampleRate, FrameLength) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Analyzes a single frame of audio to detect speech. This overload requires explicit passing of the audio frame, sample rate, and frame length. ```APIDOC ## WebRtcVad.HasSpeech(IntPtr, SampleRate, FrameLength) ### Description Determines if speech is detected in the provided audio frame. ### Parameters #### Path Parameters - **audioFrame** (System.IntPtr) - Required - A pointer to the audio data for a single frame. - **sampleRate** (SampleRate) - Required - The sample rate of the audio data. - **frameLength** (FrameLength) - Required - The length of the audio frame. ### Remarks This overload requires the `sampleRate` and `frameLength` to be passed with each call. For convenience, consider using the `HasSpeech(IntPtr)` overload if the sample rate and frame length are consistent and can be set on the `WebRtcVad` instance. ``` -------------------------------- ### HasSpeech(IntPtr, SampleRate, FrameLength) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied IntPtr frame contains speech, explicitly specifying the sample rate and frame length. ```APIDOC ## HasSpeech(IntPtr, SampleRate, FrameLength) `method` ### Description Tests whether the supplied IntPtr frame contains speech, explicitly specifying the sample rate and frame length for the audio data. ### Method `public bool HasSpeech(IntPtr audioFrame, SampleRate sampleRate, FrameLength frameLength);` ### Parameters #### Path Parameters - **audioFrame** (IntPtr) - Required - A single frame of audio data. - **sampleRate** (SampleRate) - Required - The sample rate used to encode `audioFrame`. - **frameLength** (FrameLength) - Required - The length of the frame in `audioFrame`. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ``` -------------------------------- ### HasSpeech(short[], SampleRate, FrameLength) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied short array frame contains speech, explicitly specifying the sample rate and frame length. ```APIDOC ## HasSpeech(short[], SampleRate, FrameLength) `method` ### Description Tests whether the supplied short array frame contains speech, explicitly specifying the sample rate and frame length for the audio data. ### Method `public bool HasSpeech(short[] audioFrame, SampleRate sampleRate, FrameLength frameLength);` ### Parameters #### Path Parameters - **audioFrame** (short[]) - Required - A single frame of audio data. - **sampleRate** (SampleRate) - Required - The sample rate used to encode `audioFrame`. - **frameLength** (FrameLength) - Required - The length of the frame in `audioFrame`. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ### Remarks This overload ignores the [SampleRate](WebRtcVad.SampleRate) and [FrameLength](WebRtcVad.FrameLength) properties. To avoid passing the rate and length on each call, use the `HasSpeech(short[])` overload instead. ``` -------------------------------- ### SampleRate Enum Definition Source: https://github.com/ladenedge/webrtcvadsharp/wiki/SampleRate-Enum Defines the supported audio sample rates for WebRTC. Use these constants to specify the sample rate when processing audio. ```csharp public enum SampleRate ``` -------------------------------- ### C# HasSpeech(short[]) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This is the method signature for checking speech in a short array audio frame. Ensure the frame is encoded according to the VAD's SampleRate and FrameLength properties. ```csharp public bool HasSpeech(short[] audioFrame); ``` -------------------------------- ### WebRtcVad Properties Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad Configures the behavior of the voice activity detector, including frame length, operating mode (aggressiveness), and sample rate. ```APIDOC ## FrameLength ### Description Gets or sets the frame length when using the audio-only `HasSpeech(byte[])` overload. Defaults to `Is10ms`. ### Property Type FrameLength ## OperatingMode ### Description Gets or sets the aggressiveness of the detection. Defaults to `HighQuality`. ### Property Type OperatingMode ## SampleRate ### Description Gets or sets the sample rate when using the audio-only `HasSpeech(byte[])` overload. Defaults to `Is8kHz`. ### Property Type SampleRate ``` -------------------------------- ### C# HasSpeech(byte[]) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This is the method signature for checking speech in a byte array audio frame. Ensure the frame is encoded according to the VAD's SampleRate and FrameLength properties. ```csharp public bool HasSpeech(byte[] audioFrame); ``` -------------------------------- ### C# HasSpeech(IntPtr) Method Signature Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() This is the method signature for checking speech in an audio frame represented by an IntPtr. Ensure the frame is encoded according to the VAD's SampleRate and FrameLength properties. ```csharp public bool HasSpeech(IntPtr audioFrame); ``` -------------------------------- ### HasSpeech(byte[], SampleRate, FrameLength) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied byte array frame contains speech, explicitly specifying the sample rate and frame length. ```APIDOC ## HasSpeech(byte[], SampleRate, FrameLength) `method` ### Description Tests whether the supplied byte array frame contains speech, explicitly specifying the sample rate and frame length for the audio data. ### Method `public bool HasSpeech(byte[] audioFrame, SampleRate sampleRate, FrameLength frameLength);` ### Parameters #### Path Parameters - **audioFrame** (byte[]) - Required - A single frame of audio data. - **sampleRate** (SampleRate) - Required - The sample rate used to encode `audioFrame`. - **frameLength** (FrameLength) - Required - The length of the frame in `audioFrame`. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ### Remarks This overload ignores the [SampleRate](WebRtcVad.SampleRate) and [FrameLength](WebRtcVad.FrameLength) properties. To avoid passing the rate and length on each call, use the `HasSpeech(byte[])` overload instead. ``` -------------------------------- ### FrameLength Enum Definition Source: https://github.com/ladenedge/webrtcvadsharp/wiki/FrameLength-Enum Defines the possible frame lengths in milliseconds supported by WebRTC. Use these constants to specify the audio frame size. ```csharp public enum FrameLength ``` -------------------------------- ### HasSpeech(short[]) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied short array frame contains speech using default sample rate and frame length properties. ```APIDOC ## HasSpeech(short[]) `method` ### Description Tests whether the supplied short array frame contains speech using the default sample rate and frame length properties configured for the WebRTcVAD instance. ### Method `public bool HasSpeech(short[] audioFrame);` ### Parameters #### Path Parameters - **audioFrame** (short[]) - Required - A single frame of audio data. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ### Remarks The supplied frame must be encoded according to [SampleRate](WebRtcVad.SampleRate) and [FrameLength](WebRtcVad.FrameLength). To test a frame at other rates or length, either re-set the appropriate properties, or use the standalone overload `HasSpeech(short[], SampleRate, FrameLength)`. ``` -------------------------------- ### Dispose() Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.Dispose() Disposes of the underlying WebRTC resources managed by the WebRtcVad instance. This method should be called when the WebRtcVad object is no longer needed to prevent resource leaks. ```APIDOC ## Dispose() ### Description Disposes of the underlying WebRTC resources. ### Method ```csharp public void Dispose(); ``` ### Summary Dispose the underlying WebRTC resources. ``` -------------------------------- ### HasSpeech(IntPtr) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied IntPtr frame contains speech using default sample rate and frame length properties. ```APIDOC ## HasSpeech(IntPtr) `method` ### Description Tests whether the supplied IntPtr frame contains speech using the default sample rate and frame length properties configured for the WebRTcVAD instance. ### Method `public bool HasSpeech(IntPtr audioFrame);` ### Parameters #### Path Parameters - **audioFrame** (IntPtr) - Required - A single frame of audio data. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ### Remarks The supplied frame must be encoded according to [SampleRate](WebRtcVad.SampleRate) and [FrameLength](WebRtcVad.FrameLength). To test a frame at other rates or length, either re-set the appropriate properties, or use the standalone overload `HasSpeech(IntPtr, SampleRate, FrameLength)`. ``` -------------------------------- ### HasSpeech(byte[]) Source: https://github.com/ladenedge/webrtcvadsharp/wiki/WebRtcVad.HasSpeech() Tests whether the supplied byte array frame contains speech using default sample rate and frame length properties. ```APIDOC ## HasSpeech(byte[]) `method` ### Description Tests whether the supplied byte array frame contains speech using the default sample rate and frame length properties configured for the WebRTcVAD instance. ### Method `public bool HasSpeech(byte[] audioFrame);` ### Parameters #### Path Parameters - **audioFrame** (byte[]) - Required - A single frame of audio data. ### Returns - **bool** - `true` if the provided frame contains speech, otherwise `false`. ### Remarks The supplied frame must be encoded according to [SampleRate](WebRtcVad.SampleRate) and [FrameLength](WebRtcVad.FrameLength). To test a frame at other rates or length, either re-set the appropriate properties, or use the standalone overload `HasSpeech(byte[], SampleRate, FrameLength)`. ``` -------------------------------- ### Define OperatingMode Enum Source: https://github.com/ladenedge/webrtcvadsharp/wiki/OperatingMode-Enum Defines the VAD operating mode. The default is HighQuality. Higher modes are more aggressive in detecting speech but increase the missed detection rate. ```csharp public enum OperatingMode ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.