-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
280 lines (232 loc) · 9.61 KB
/
main.py
File metadata and controls
280 lines (232 loc) · 9.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
import os
import tkinter as tk
from tkinter import filedialog, messagebox
from typing import Annotated, List, Optional
import typer
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Confirm, Prompt
from rich.table import Table
from combine import Audio_processing
class FolderSelector:
"""GUI folder selection utility."""
def __init__(self):
self.root = tk.Tk()
self.root.withdraw() # Hide the main window
def select_input_folder(self) -> Optional[str]:
"""Open a folder selection dialog for input directory."""
folder = filedialog.askdirectory(
title="Select Input Directory (containing WAV files)", mustexist=True
)
return folder if folder else None
def select_output_folder(self) -> Optional[str]:
"""Open a folder selection dialog for output directory."""
folder = filedialog.askdirectory(
title="Select Output Directory for consolidated files"
)
return folder if folder else None
def select_final_folder(self) -> Optional[str]:
"""Open a folder selection dialog for processed files"""
folder = filedialog.askdirectory(
title="Select output directory for processed files."
)
return folder if folder else None
def show_completion_message(self, output_dir: str):
"""Show completion message with output directory."""
messagebox.showinfo(
"Processing Complete",
f"Processing completed successfully!\n\nOutput files saved to:\n{output_dir}",
)
def show_error_message(self, message: str):
"""Show error message."""
messagebox.showerror("Error", message)
def select_noise_folder(self) -> Optional[str]:
"""Open a file selection dialog for multiple noise files."""
folder = filedialog.askdirectory(
title="Select input directory for the noise file"
)
return folder if folder else None
# Initialize Typer app
app = typer.Typer(
help="WAV File Consolidator and Filter Tool for Scientific Experiments",
rich_markup_mode="rich",
)
console = Console()
@app.command()
def process(
input_dir: Annotated[
Optional[str], typer.Argument(help="Input directory containing WAV files")
] = None,
output_dir: Annotated[
Optional[str], typer.Argument(help="Output directory for processed files")
] = None,
gui: Annotated[
bool, typer.Option("--gui", help="Use GUI folder selection")
] = False,
noise_profile: Annotated[
Optional[str], typer.Option(help="Path to noise profile file")
] = None,
):
"""
Process WAV files: consolidate and apply filters.
Available presets: scientific, noise_reduction, vocal_enhancement, adaptive_noise_reduction
"""
# Display welcome message
console.print(
Panel.fit(
"[bold blue]🎵 WAV File Consolidator & Filter Tool[/bold blue]\n"
"[dim]For Scientific Experiments[/dim]",
border_style="blue",
)
)
processor = Audio_processing(input_dir)
# Handle GUI mode or missing arguments
if gui or not input_dir or not output_dir:
folder_selector = FolderSelector()
if not input_dir:
console.print(
"\n[yellow]Please select the input directory containing WAV files...[/yellow]"
)
input_dir = folder_selector.select_input_folder()
if not input_dir:
console.print("[red]No input directory selected. Exiting.[/red]")
return
if not output_dir:
console.print(
"\n[yellow]Please select the output directory for processed files...[/yellow]"
)
output_dir = folder_selector.select_output_folder()
if not output_dir:
console.print("[red]No output directory selected. Exiting.[/red]")
return
# Handle noise profile selection
if gui and not noise_profile:
if Confirm.ask(
"\n[yellow]Do you have a noise profile for better noise reduction?[/yellow]",
default=False,
):
console.print(
"[yellow]Please select the noise profile file...[/yellow]"
)
noise_profile = folder_selector.select_noise_folder()
if noise_profile:
console.print(
f"[green]Selected noise profile: {os.path.basename(noise_profile)}[/green]"
)
else:
console.print(
"[yellow]No noise profile selected. Proceeding without noise profiling.[/yellow]"
)
# Display processing parameters
params_table = Table(title="Processing Parameters")
params_table.add_column("Parameter", style="cyan")
params_table.add_column("Value", style="green")
params_table.add_row("Input Directory", input_dir)
params_table.add_row("Output Directory", output_dir)
params_table.add_row("Noise Profile", noise_profile if noise_profile else "None")
console.print(params_table)
# Confirm processing
if not Confirm.ask("\n[bold]Proceed with processing?[/bold]", default=True):
console.print("[yellow]Processing cancelled.[/yellow]")
return
# Process the directory
if noise_profile:
success = processor.process_directory(input_dir, output_dir, noise_profile)
else:
success = processor.process_directory(input_dir, output_dir, "")
if success:
console.print("\n[green]✅ Processing completed successfully![/green]")
console.print(f"[blue]📁 Output files saved to: {output_dir}[/blue]")
# Show GUI completion message if GUI was used
if gui:
folder_selector = FolderSelector()
folder_selector.show_completion_message(output_dir)
else:
console.print("\n[red]❌ Processing failed. Check the logs for details.[/red]")
if gui:
folder_selector = FolderSelector()
folder_selector.show_error_message(
"Processing failed. Check the console for details."
)
@app.command()
def interactive():
"""
Run in interactive mode with prompts for all parameters.
"""
console.print(
Panel.fit(
"[bold green]🎛️ Interactive Mode[/bold green]\n"
"[dim]Step-by-step configuration[/dim]",
border_style="green",
)
)
# Initialize noise_profile variable
noise_profile = None
# Get input directory
use_gui = Confirm.ask("Use GUI for folder selection?", default=True)
if use_gui:
folder_selector = FolderSelector()
console.print("\n[yellow]Select input directory...[/yellow]")
input_dir = folder_selector.select_input_folder()
if not input_dir:
console.print("[red]No input directory selected. Exiting.[/red]")
return
console.print("\n[yellow]Select output directory...[/yellow]")
output_dir = folder_selector.select_output_folder()
if not output_dir:
console.print("[red]No output directory selected. Exiting.[/red]")
return
# Handle noise profile selection
if Confirm.ask(
"\n[yellow]Do you have a noise profile for better noise reduction?[/yellow]",
default=False,
):
console.print(
"[yellow]Please select the noise profile directory...[/yellow]"
)
noise_profile = folder_selector.select_noise_folder()
if noise_profile:
console.print(
f"[green]Selected noise profile: {os.path.basename(noise_profile)}[/green]"
)
else:
console.print(
"[yellow]No noise profile selected. Proceeding without noise profiling.[/yellow]"
)
else:
input_dir = Prompt.ask("Enter input directory path")
output_dir = Prompt.ask("Enter output directory path")
if Confirm.ask("Do you have a noise profile?", default=False):
noise_profile = Prompt.ask("Enter noise profile path")
# Display processing parameters
params_table = Table(title="Processing Parameters")
params_table.add_column("Parameter", style="cyan")
params_table.add_column("Value", style="green")
params_table.add_row("Input Directory", input_dir)
params_table.add_row("Output Directory", output_dir)
params_table.add_row("Noise Profile", noise_profile if noise_profile else "None")
console.print(params_table)
# Confirm processing
if not Confirm.ask("\n[bold]Proceed with processing?[/bold]", default=True):
console.print("[yellow]Processing cancelled.[/yellow]")
return
# Process
processor = Audio_processing(input_dir)
if noise_profile:
success = processor.process_directory(input_dir, output_dir, noise_profile)
else:
success = processor.process_directory(input_dir, output_dir, "")
if success:
console.print("\n[green]✅ Processing completed successfully![/green]")
console.print(f"[blue]📁 Output files saved to: {output_dir}[/blue]")
if use_gui:
folder_selector.show_completion_message(output_dir)
else:
console.print("\n[red]❌ Processing failed. Check the logs for details.[/red]")
if use_gui:
folder_selector = FolderSelector()
folder_selector.show_error_message(
"Processing failed. Check the console for details."
)
if __name__ == "__main__":
app()