You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Replace Ko-fi with AirTM for donations (since PayPal is unavailable in my region).
- Simplify Recorder and VAD components
- Remove VAD integration from Recorder component.
- Simplify VoiceActivityDetector for basic energy detection.
- Add modifier/analyzer management to Recorder.
feat(experimental): Introduce advanced VAD
- Add experimental VoiceActivityDetector with noise gate to Experimental namespace.
- Implement combined detection mode in advanced VAD.
- Add configuration options for advanced VAD.
- Move configurePlayer invocation after adding component
to mixer to avoid potential issues.
- Move NoiseReductionModifier to Experimental namespace.
- Indicate it's under development and not stable.
- Introduce MathHelper.IsPowerOfTwo for power of two check.
- Add MathHelper.Lerp for linear interpolation.
- Optimize FFT algorithm by adding scalar implementation for
smaller sizes.
- Improve complex multiplication using AVX for
performance.
Welcome to SoundFlow repository! We appreciate you taking the time to contribute.
16
+
17
+
We're excited to review your pull request and look forward to collaborating with you. Please let us know if you have any questions or need any assistance.
Copy file name to clipboardExpand all lines: README.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,9 +147,10 @@ Beyond equipment, your contributions, no matter the size, help to:
147
147
148
148
You can directly support SoundFlow and help me get essential headphones through:
149
149
150
-
***Ko-fi:** For simple one-time donations or flexible recurring support.
150
+
***AirTM:** For simple one-time donations with various payment options like Direct Bank Transfer (ACH), Debit / Credit Card via Moonpay, Stablecoins, and more than 500 banks and e-wallets.
Copy file name to clipboardExpand all lines: Src/Components/Recorder.cs
+72-24Lines changed: 72 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,13 @@
2
2
usingSoundFlow.Enums;
3
3
usingSoundFlow.Interfaces;
4
4
usingSoundFlow.Exceptions;
5
+
usingSystem.Collections.ObjectModel;
5
6
6
7
namespaceSoundFlow.Components;
7
8
8
9
/// <summary>
9
10
/// Component for recording audio data, either to a file or via a callback.
10
-
/// Supports various sample and encoding formats and can integrate with a Voice Activity Detector (VAD).
11
+
/// Supports various sample and encoding formats and can integrate with <see cref="SoundModifier"/> and <see cref="AudioAnalyzer"/> components for real-time processing and analysis during recording.
11
12
/// Implements the <see cref="IDisposable"/> interface to ensure resources are released properly.
12
13
/// </summary>
13
14
publicclassRecorder:IDisposable
@@ -50,7 +51,8 @@ public class Recorder : IDisposable
50
51
publicAudioProcessCallback?ProcessCallback;
51
52
52
53
privateISoundEncoder?_encoder;
53
-
privatereadonlyVoiceActivityDetector?_vad;
54
+
privatereadonlyList<SoundModifier>_modifiers=[];
55
+
privatereadonlyList<AudioAnalyzer>_analyzers=[];
54
56
55
57
/// <summary>
56
58
/// Initializes a new instance of the <see cref="Recorder"/> class to record audio to a file.
@@ -60,15 +62,12 @@ public class Recorder : IDisposable
60
62
/// <param name="encodingFormat">The desired encoding format for the recorded audio file. Defaults to <see cref="EncodingFormat.Wav"/>.</param>
61
63
/// <param name="sampleRate">The desired sample rate for recording, in samples per second. Defaults to 44100 Hz.</param>
62
64
/// <param name="channels">The number of channels to record. Defaults to 2 (stereo).</param>
63
-
/// <param name="vad">An optional <see cref="VoiceActivityDetector"/> to use for voice activity detection during recording. Defaults to null.</param>
64
65
publicRecorder(stringfilePath,
65
66
SampleFormatsampleFormat=SampleFormat.F32,
66
67
EncodingFormatencodingFormat=EncodingFormat.Wav,
67
68
intsampleRate=44100,
68
-
intchannels=2,
69
-
VoiceActivityDetector?vad=null)
69
+
intchannels=2)
70
70
{
71
-
_vad=vad;
72
71
SampleFormat=sampleFormat;
73
72
EncodingFormat=encodingFormat;
74
73
FilePath=filePath;
@@ -84,25 +83,32 @@ public Recorder(string filePath,
84
83
/// <param name="encodingFormat">The encoding format (primarily for internal use or if an encoder is manually managed). Defaults to <see cref="EncodingFormat.Wav"/>.</param>
85
84
/// <param name="sampleRate">The desired sample rate for recording, in samples per second. Defaults to 44100 Hz.</param>
86
85
/// <param name="channels">The number of channels to record. Defaults to 2 (stereo).</param>
87
-
/// <param name="vad">An optional <see cref="VoiceActivityDetector"/> to use for voice activity detection during recording. Defaults to null.</param>
88
86
publicRecorder(AudioProcessCallbackcallback,
89
87
SampleFormatsampleFormat=SampleFormat.F32,
90
88
EncodingFormatencodingFormat=EncodingFormat.Wav,
91
89
intsampleRate=44100,
92
-
intchannels=2,
93
-
VoiceActivityDetector?vad=null)
90
+
intchannels=2)
94
91
{
95
92
ProcessCallback=callback;
96
-
_vad=vad;
97
93
SampleFormat=sampleFormat;
98
94
EncodingFormat=encodingFormat;
99
95
SampleRate=sampleRate;
100
96
Channels=channels;
101
97
}
102
98
99
+
/// <summary>
100
+
/// Gets a read-only list of <see cref="SoundModifier"/> components applied to the recorder.
/// If recording to a file, it initializes the audio encoder. If using a VAD, it starts monitoring for voice activity.
111
+
/// If recording to a file, it initializes the audio encoder.
106
112
/// </summary>
107
113
/// <exception cref="ArgumentException">Thrown if both <see cref="FilePath"/> and <see cref="ProcessCallback"/> are invalid (e.g., <see cref="FilePath"/> is null or empty and <see cref="ProcessCallback"/> is null).</exception>
108
114
/// <exception cref="BackendException">Thrown if creating the audio encoder fails when recording to a file.</exception>
@@ -124,17 +130,6 @@ public void StartRecording()
124
130
125
131
AudioEngine.OnAudioProcessed+=OnOnAudioProcessed;
126
132
State=PlaybackState.Playing;
127
-
128
-
if(_vad!=null)
129
-
{
130
-
_vad.SpeechDetected+= isDetected =>
131
-
{
132
-
if(isDetected)
133
-
ResumeRecording();
134
-
else
135
-
PauseRecording();
136
-
};
137
-
}
138
133
}
139
134
140
135
/// <summary>
@@ -179,19 +174,70 @@ public void StopRecording()
179
174
State=PlaybackState.Stopped;
180
175
}
181
176
177
+
/// <summary>
178
+
/// Adds a <see cref="SoundModifier"/> to the recording pipeline.
179
+
/// Modifiers are applied to the audio data before encoding or processing via callback.
180
+
/// </summary>
181
+
/// <param name="modifier">The modifier to add.</param>
182
+
publicvoidAddModifier(SoundModifiermodifier)
183
+
{
184
+
_modifiers.Add(modifier);
185
+
}
186
+
187
+
/// <summary>
188
+
/// Removes a <see cref="SoundModifier"/> from the recording pipeline.
189
+
/// </summary>
190
+
/// <param name="modifier">The modifier to remove.</param>
191
+
publicvoidRemoveModifier(SoundModifiermodifier)
192
+
{
193
+
_modifiers.Remove(modifier);
194
+
}
195
+
196
+
/// <summary>
197
+
/// Adds an <see cref="AudioAnalyzer"/> to the recording pipeline.
198
+
/// Analyzers can be used to process and extract data from the audio during recording.
199
+
/// </summary>
200
+
/// <param name="analyzer">The analyzer to add.</param>
201
+
publicvoidAddAnalyzer(AudioAnalyzeranalyzer)
202
+
{
203
+
_analyzers.Add(analyzer);
204
+
}
205
+
206
+
/// <summary>
207
+
/// Removes an <see cref="AudioAnalyzer"/> from the recording pipeline.
208
+
/// </summary>
209
+
/// <param name="analyzer">The analyzer to remove.</param>
210
+
publicvoidRemoveAnalyzer(AudioAnalyzeranalyzer)
211
+
{
212
+
_analyzers.Remove(analyzer);
213
+
}
214
+
182
215
/// <summary>
183
216
/// Handles the audio processed event from the audio engine.
184
217
/// This method is invoked by the audio engine when new audio samples are available.
185
-
/// It processes the samples through the VAD (if enabled), checks the current state, invokes the <see cref="ProcessCallback"/> (if set), and encodes the samples using the <see cref="_encoder"/> (if recording to a file).
218
+
/// It processes the samples through the added <see cref="SoundModifier"/> and <see cref="AudioAnalyzer"/> components, checks the current state, invokes the <see cref="ProcessCallback"/> (if set), and encodes the samples using the <see cref="_encoder"/> (if recording to a file).
186
219
/// </summary>
187
220
/// <param name="samples">A span containing the audio samples to process.</param>
188
221
/// <param name="capability">The audio capability associated with the processed samples (e.g., input or output).</param>
0 commit comments