@@ -7,6 +7,7 @@ use audiopus::{
77 coder:: { Decoder as OpusDecoder , Encoder as OpusEncoder } ,
88 packet:: Packet ,
99} ;
10+ #[ cfg( target_os = "linux" ) ]
1011use nnnoiseless:: DenoiseState ;
1112use std:: collections:: VecDeque ;
1213use thiserror:: Error ;
@@ -140,8 +141,10 @@ impl Default for AudioConfig {
140141pub struct VoiceEncoder {
141142 encoder : OpusEncoder ,
142143 config : AudioConfig ,
144+ #[ cfg( target_os = "linux" ) ]
143145 denoise : Option < Box < DenoiseState < ' static > > > ,
144146 /// Buffer for resampling (for noise suppression at 48kHz)
147+ #[ cfg( target_os = "linux" ) ]
145148 resample_buffer : Vec < f32 > ,
146149}
147150
@@ -174,20 +177,24 @@ impl VoiceEncoder {
174177 . set_dtx ( true )
175178 . map_err ( |e| AudioError :: EncoderError ( format ! ( "Failed to enable DTX: {:?}" , e) ) ) ?;
176179
177- // Initialize noise suppression if enabled
180+ // Initialize noise suppression if enabled (Linux only - uses nnnoiseless/RNNoise)
181+ #[ cfg( target_os = "linux" ) ]
178182 let denoise = if config. enable_noise_suppression {
179183 Some ( DenoiseState :: new ( ) )
180184 } else {
181185 None
182186 } ;
183187
184188 // RNNoise requires 480 samples at 48kHz (10ms frames)
189+ #[ cfg( target_os = "linux" ) ]
185190 let resample_buffer = vec ! [ 0.0f32 ; 480 ] ;
186191
187192 Ok ( Self {
188193 encoder,
189194 config,
195+ #[ cfg( target_os = "linux" ) ]
190196 denoise,
197+ #[ cfg( target_os = "linux" ) ]
191198 resample_buffer,
192199 } )
193200 }
@@ -201,7 +208,8 @@ impl VoiceEncoder {
201208 /// # Returns
202209 /// Number of bytes written to output, or 0 if VAD detected silence
203210 pub fn encode ( & mut self , pcm : & [ i16 ] , output : & mut [ u8 ] ) -> Result < usize , AudioError > {
204- // Apply noise suppression if enabled
211+ // Apply noise suppression if enabled (Linux only - uses nnnoiseless/RNNoise)
212+ #[ cfg( target_os = "linux" ) ]
205213 let processed_pcm: Vec < i16 > = if self . denoise . is_some ( ) {
206214 // We need to take denoise out temporarily to avoid borrow issues
207215 let mut denoise = self . denoise . take ( ) . unwrap ( ) ;
@@ -212,6 +220,10 @@ impl VoiceEncoder {
212220 pcm. to_vec ( )
213221 } ;
214222
223+ // On non-Linux platforms, noise suppression is not available
224+ #[ cfg( not( target_os = "linux" ) ) ]
225+ let processed_pcm: Vec < i16 > = pcm. to_vec ( ) ;
226+
215227 let pcm_to_encode = & processed_pcm;
216228
217229 // Simple VAD: check if audio is mostly silent
@@ -233,7 +245,8 @@ impl VoiceEncoder {
233245 Ok ( len)
234246 }
235247
236- /// Apply RNNoise noise suppression to PCM samples
248+ /// Apply RNNoise noise suppression to PCM samples (Linux only)
249+ #[ cfg( target_os = "linux" ) ]
237250 fn apply_noise_suppression ( & mut self , pcm : & [ i16 ] , denoise : & mut DenoiseState ) -> Vec < i16 > {
238251 let mut output = Vec :: with_capacity ( pcm. len ( ) ) ;
239252
0 commit comments