-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudacity_automation.py
More file actions
196 lines (155 loc) · 5.5 KB
/
audacity_automation.py
File metadata and controls
196 lines (155 loc) · 5.5 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
#!/usr/bin/env python3
"""
Audacity Automation Script
Uses Audacity's built-in Python scripting to automate effects and export.
"""
import os
import sys
from pathlib import Path
def create_audacity_script(input_file, output_file, effects=None):
"""
Create a Python script that can be run within Audacity.
Args:
input_file (str): Path to input bitmap file
output_file (str): Path for output raw file
effects (list): List of effects to apply with their parameters
"""
if effects is None:
effects = [
{"name": "Echo", "delay": 0.3, "decay": 0.1},
{"name": "Reverb", "room_size": 0.5, "damping": 0.5},
]
script_content = f'''# Audacity Python Script
# This script can be run from within Audacity: Tools > Scriptables > Run Script...
import os
import audacity
def apply_effects():
"""Apply effects to the current audio track"""
# Get the current project
project = audacity.GetProject()
# Select all audio
audacity.SelectAll()
# Apply effects
for effect in {effects}:
effect_name = effect["name"]
print(f"Applying {{effect_name}}...")
if effect_name == "Echo":
audacity.ApplyEffect("Echo",
delay=effect.get("delay", 0.3),
decay=effect.get("decay", 0.1))
elif effect_name == "Reverb":
audacity.ApplyEffect("Reverb",
room_size=effect.get("room_size", 0.5),
damping=effect.get("damping", 0.5))
elif effect_name == "Distortion":
audacity.ApplyEffect("Distortion",
distortion_type=effect.get("type", "Soft Clip"),
level=effect.get("level", 0.5))
elif effect_name == "Phaser":
audacity.ApplyEffect("Phaser",
stages=effect.get("stages", 2),
dry_wet=effect.get("dry_wet", 0.5),
frequency=effect.get("frequency", 0.5))
else:
print(f"Unknown effect: {{effect_name}}")
print("Effects applied successfully!")
def export_raw():
"""Export as raw audio"""
output_path = "{output_file}"
# Export as raw (header-less)
audacity.Export2(
filename=output_path,
format="RAW",
encoding="ULAW",
channels=1
)
print(f"Exported to: {{output_path}}")
if __name__ == "__main__":
apply_effects()
export_raw()
'''
script_file = "audacity_script.py"
with open(script_file, 'w') as f:
f.write(script_content)
print(f"Created Audacity script: {script_file}")
print("To use this script:")
print("1. Open Audacity")
print("2. Import your bitmap as raw data")
print("3. Go to Tools > Scriptables > Run Script...")
print("4. Select the generated script file")
print("5. The script will apply effects and export automatically")
return script_file
def create_batch_script(input_dir="input-bitmap", output_dir="output-raw", effects=None):
"""
Create a batch processing script for multiple files.
"""
input_path = Path(input_dir)
output_path = Path(output_dir)
output_path.mkdir(exist_ok=True)
bitmap_files = list(input_path.glob("*.bmp"))
if not bitmap_files:
print(f"No bitmap files found in {input_dir}")
return
batch_script = '''# Audacity Batch Processing Script
# This script processes multiple bitmap files
import os
import audacity
from pathlib import Path
def process_file(input_file, output_file, effects):
"""Process a single file"""
# Import the bitmap as raw data
audacity.ImportRaw(
filename=input_file,
encoding="ULAW",
channels=1
)
# Apply effects
apply_effects(effects)
# Export
audacity.Export2(
filename=output_file,
format="RAW",
encoding="ULAW",
channels=1
)
# Close the project to prepare for next file
audacity.CloseProject()
def apply_effects(effects):
"""Apply effects to current track"""
audacity.SelectAll()
for effect in effects:
effect_name = effect["name"]
print(f"Applying {effect_name}...")
if effect_name == "Echo":
audacity.ApplyEffect("Echo",
delay=effect.get("delay", 0.3),
decay=effect.get("decay", 0.1))
elif effect_name == "Reverb":
audacity.ApplyEffect("Reverb",
room_size=effect.get("room_size", 0.5),
damping=effect.get("damping", 0.5))
# Add more effects as needed
# Main processing loop
input_dir = "{input_dir}"
output_dir = "{output_dir}"
effects = {effects}
input_path = Path(input_dir)
output_path = Path(output_dir)
for bitmap_file in input_path.glob("*.bmp"):
output_file = output_path / f"{{bitmap_file.stem}}.raw"
print(f"Processing {{bitmap_file.name}}...")
process_file(str(bitmap_file), str(output_file), effects)
print(f"Exported to {{output_file}}")
print("Batch processing complete!")
'''
with open("audacity_batch.py", 'w') as f:
f.write(batch_script)
print("Created batch processing script: audacity_batch.py")
if __name__ == "__main__":
# Example usage
effects = [
{"name": "Echo", "delay": 0.3, "decay": 0.1},
{"name": "Reverb", "room_size": 0.5, "damping": 0.5},
]
create_audacity_script("input-bitmap/test.bmp", "output-raw/test.raw", effects)
create_batch_script("input-bitmap", "output-raw", effects)