-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert_audio.py
More file actions
30 lines (25 loc) · 943 Bytes
/
convert_audio.py
File metadata and controls
30 lines (25 loc) · 943 Bytes
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
import os
from pydub import AudioSegment
import sys
def convert_audio(input_path, output_path):
try:
# Load the audio file
audio = AudioSegment.from_file(input_path)
# Convert to WAV format with specific parameters
audio = audio.set_channels(2) # Stereo
audio = audio.set_frame_rate(44100) # 44.1kHz
audio = audio.set_sample_width(2) # 16-bit
# Export as WAV
audio.export(output_path, format="wav")
print(f"Successfully converted {input_path} to {output_path}")
return True
except Exception as e:
print(f"Error converting {input_path}: {str(e)}")
return False
if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python convert_audio.py <input_file> <output_file>")
sys.exit(1)
input_file = sys.argv[1]
output_file = sys.argv[2]
convert_audio(input_file, output_file)