Skip to content

Commit 429c1d2

Browse files
committed
parametrize sample rate of file conversion methods
1 parent c387675 commit 429c1d2

File tree

4 files changed

+187
-262
lines changed

4 files changed

+187
-262
lines changed

maestro_worker_python/convert_files.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class FileToConvert:
2424
file_format: str
2525
output_file_path: str = None
2626
max_duration: int = 1200
27+
sample_rate: int = 44100
2728

2829

2930
def convert_files(convert_files: List[FileToConvert]):
@@ -43,6 +44,7 @@ def convert_files(convert_files: List[FileToConvert]):
4344
convert_file.input_file_path,
4445
convert_file.output_file_path,
4546
convert_file.max_duration,
47+
convert_file.sample_rate,
4648
)
4749
)
4850

@@ -72,6 +74,7 @@ def convert_files_manager(*convert_files: FileToConvert) -> None | str | list[st
7274
convert_file.input_file_path,
7375
filename.name,
7476
convert_file.max_duration,
77+
convert_file.sample_rate,
7578
)
7679
)
7780
list_objects.append(filename)
@@ -89,7 +92,7 @@ def convert_files_manager(*convert_files: FileToConvert) -> None | str | list[st
8992
obj.close()
9093

9194

92-
def _convert_to_wav(input_file_path, output_file_path, max_duration):
95+
def _convert_to_wav(input_file_path, output_file_path, max_duration, sample_rate=44100):
9396
_run_subprocess(
9497
[
9598
"ffmpeg",
@@ -102,13 +105,13 @@ def _convert_to_wav(input_file_path, output_file_path, max_duration):
102105
"-i",
103106
str(input_file_path),
104107
"-ar",
105-
"44100",
108+
str(sample_rate),
106109
str(output_file_path),
107110
]
108111
)
109112

110113

111-
def _convert_to_m4a(input_file_path, output_file_path, max_duration):
114+
def _convert_to_m4a(input_file_path, output_file_path, max_duration, sample_rate=44100):
112115
_run_subprocess(
113116
[
114117
"ffmpeg",
@@ -125,7 +128,7 @@ def _convert_to_m4a(input_file_path, output_file_path, max_duration):
125128
"-b:a",
126129
"192k",
127130
"-ar",
128-
"44100",
131+
str(sample_rate),
129132
"-movflags",
130133
"+faststart",
131134
str(output_file_path),

0 commit comments

Comments
 (0)