Skip to main content

voirs_conversion/style_transfer/
config.rs

1//! Configuration types for style transfer system
2
3use serde::{Deserialize, Serialize};
4
5/// Configuration for style transfer system
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct StyleTransferConfig {
8    /// Enable style transfer
9    pub enabled: bool,
10
11    /// Content preservation weight (0.0 to 1.0)
12    pub content_preservation_weight: f32,
13
14    /// Style transfer strength (0.0 to 1.0)
15    pub style_transfer_strength: f32,
16
17    /// Quality threshold for transfer
18    pub quality_threshold: f32,
19
20    /// Transfer method selection
21    pub transfer_method: StyleTransferMethod,
22
23    /// Adaptation settings
24    pub adaptation_settings: StyleAdaptationSettings,
25
26    /// Feature extraction settings
27    pub feature_extraction: FeatureExtractionSettings,
28
29    /// Synthesis settings
30    pub synthesis_settings: SynthesisSettings,
31
32    /// Real-time processing settings
33    pub realtime_settings: RealtimeProcessingSettings,
34}
35
36/// Style transfer method
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
38pub enum StyleTransferMethod {
39    /// Content-style decomposition
40    ContentStyleDecomposition,
41
42    /// Adversarial style transfer
43    AdversarialTransfer,
44
45    /// Cycle-consistent style transfer
46    CycleConsistentTransfer,
47
48    /// Neural style transfer
49    NeuralStyleTransfer,
50
51    /// Semantic style transfer
52    SemanticStyleTransfer,
53
54    /// Hierarchical style transfer
55    HierarchicalTransfer,
56}
57
58/// Style adaptation settings
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct StyleAdaptationSettings {
61    /// Adaptation learning rate
62    pub learning_rate: f32,
63
64    /// Number of adaptation iterations
65    pub adaptation_iterations: usize,
66
67    /// Regularization strength
68    pub regularization_strength: f32,
69
70    /// Content consistency weight
71    pub content_consistency_weight: f32,
72
73    /// Style consistency weight
74    pub style_consistency_weight: f32,
75
76    /// Perceptual loss weight
77    pub perceptual_loss_weight: f32,
78
79    /// Adversarial loss weight
80    pub adversarial_loss_weight: f32,
81}
82
83/// Feature extraction settings
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct FeatureExtractionSettings {
86    /// Enable prosodic feature extraction
87    pub enable_prosodic: bool,
88
89    /// Enable spectral feature extraction
90    pub enable_spectral: bool,
91
92    /// Enable temporal feature extraction
93    pub enable_temporal: bool,
94
95    /// Enable semantic feature extraction
96    pub enable_semantic: bool,
97
98    /// Feature dimension
99    pub feature_dimension: usize,
100
101    /// Window size for analysis (ms)
102    pub window_size: f32,
103
104    /// Hop size for analysis (ms)
105    pub hop_size: f32,
106
107    /// Feature normalization method
108    pub normalization_method: NormalizationMethod,
109}
110
111/// Normalization method for features
112#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
113pub enum NormalizationMethod {
114    /// Z-score normalization
115    ZScore,
116
117    /// Min-max normalization
118    MinMax,
119
120    /// Unit normalization
121    Unit,
122
123    /// Quantile normalization
124    Quantile,
125
126    /// No normalization
127    None,
128}
129
130/// Synthesis settings
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct SynthesisSettings {
133    /// Synthesis method
134    pub synthesis_method: SynthesisMethod,
135
136    /// Vocoder configuration
137    pub vocoder_config: VocoderConfig,
138
139    /// Post-processing settings
140    pub post_processing: PostProcessingSettings,
141
142    /// Quality enhancement settings
143    pub quality_enhancement: QualityEnhancementSettings,
144}
145
146/// Synthesis method
147#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
148pub enum SynthesisMethod {
149    /// Neural vocoder synthesis
150    NeuralVocoder,
151
152    /// Parametric synthesis
153    Parametric,
154
155    /// Hybrid synthesis
156    Hybrid,
157
158    /// Direct waveform synthesis
159    DirectWaveform,
160}
161
162/// Vocoder configuration
163#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct VocoderConfig {
165    /// Vocoder type
166    pub vocoder_type: VocoderType,
167
168    /// Hop length
169    pub hop_length: usize,
170
171    /// Filter length
172    pub filter_length: usize,
173
174    /// Window function
175    pub window_function: String,
176
177    /// Mel bins
178    pub mel_bins: usize,
179
180    /// Sample rate
181    pub sample_rate: u32,
182}
183
184/// Vocoder type
185#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
186pub enum VocoderType {
187    /// HiFi-GAN vocoder
188    HiFiGAN,
189
190    /// WaveGlow vocoder
191    WaveGlow,
192
193    /// Parallel WaveGAN
194    ParallelWaveGAN,
195
196    /// MelGAN vocoder
197    MelGAN,
198
199    /// Universal vocoder
200    Universal,
201}
202
203/// Post-processing settings
204#[derive(Debug, Clone, Serialize, Deserialize)]
205pub struct PostProcessingSettings {
206    /// Enable noise reduction
207    pub noise_reduction: bool,
208
209    /// Enable dynamic range compression
210    pub dynamic_range_compression: bool,
211
212    /// Enable spectral enhancement
213    pub spectral_enhancement: bool,
214
215    /// Enable artifacts removal
216    pub artifacts_removal: bool,
217
218    /// Enhancement strength (0.0 to 1.0)
219    pub enhancement_strength: f32,
220}
221
222/// Quality enhancement settings
223#[derive(Debug, Clone, Serialize, Deserialize)]
224pub struct QualityEnhancementSettings {
225    /// Enable super-resolution
226    pub super_resolution: bool,
227
228    /// Enable bandwidth extension
229    pub bandwidth_extension: bool,
230
231    /// Enable prosody enhancement
232    pub prosody_enhancement: bool,
233
234    /// Enhancement target quality
235    pub target_quality: f32,
236
237    /// Quality vs speed tradeoff
238    pub quality_speed_tradeoff: f32,
239}
240
241/// Real-time processing settings
242#[derive(Debug, Clone, Serialize, Deserialize)]
243pub struct RealtimeProcessingSettings {
244    /// Enable real-time processing
245    pub enabled: bool,
246
247    /// Processing chunk size (samples)
248    pub chunk_size: usize,
249
250    /// Lookahead buffer size (samples)
251    pub lookahead_size: usize,
252
253    /// Maximum processing latency (ms)
254    pub max_latency: f32,
255
256    /// Enable GPU acceleration
257    pub gpu_acceleration: bool,
258
259    /// Thread pool size
260    pub thread_pool_size: usize,
261}
262
263impl Default for StyleTransferConfig {
264    fn default() -> Self {
265        Self {
266            enabled: true,
267            content_preservation_weight: 0.7,
268            style_transfer_strength: 0.8,
269            quality_threshold: 0.75,
270            transfer_method: StyleTransferMethod::ContentStyleDecomposition,
271            adaptation_settings: StyleAdaptationSettings {
272                learning_rate: 0.001,
273                adaptation_iterations: 50,
274                regularization_strength: 0.01,
275                content_consistency_weight: 1.0,
276                style_consistency_weight: 1.0,
277                perceptual_loss_weight: 0.5,
278                adversarial_loss_weight: 0.1,
279            },
280            feature_extraction: FeatureExtractionSettings {
281                enable_prosodic: true,
282                enable_spectral: true,
283                enable_temporal: true,
284                enable_semantic: true,
285                feature_dimension: 512,
286                window_size: 25.0,
287                hop_size: 10.0,
288                normalization_method: NormalizationMethod::ZScore,
289            },
290            synthesis_settings: SynthesisSettings {
291                synthesis_method: SynthesisMethod::NeuralVocoder,
292                vocoder_config: VocoderConfig {
293                    vocoder_type: VocoderType::HiFiGAN,
294                    hop_length: 256,
295                    filter_length: 1024,
296                    window_function: "hann".to_string(),
297                    mel_bins: 80,
298                    sample_rate: 22050,
299                },
300                post_processing: PostProcessingSettings {
301                    noise_reduction: true,
302                    dynamic_range_compression: true,
303                    spectral_enhancement: true,
304                    artifacts_removal: true,
305                    enhancement_strength: 0.5,
306                },
307                quality_enhancement: QualityEnhancementSettings {
308                    super_resolution: true,
309                    bandwidth_extension: true,
310                    prosody_enhancement: true,
311                    target_quality: 0.9,
312                    quality_speed_tradeoff: 0.7,
313                },
314            },
315            realtime_settings: RealtimeProcessingSettings {
316                enabled: false,
317                chunk_size: 1024,
318                lookahead_size: 256,
319                max_latency: 100.0,
320                gpu_acceleration: true,
321                thread_pool_size: 4,
322            },
323        }
324    }
325}