Skip to content

Commit

Permalink
parametrize sample rate of file conversion methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alvesfelipe committed Mar 5, 2024
1 parent c387675 commit 429c1d2
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 262 deletions.
11 changes: 7 additions & 4 deletions maestro_worker_python/convert_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FileToConvert:
file_format: str
output_file_path: str = None
max_duration: int = 1200
sample_rate: int = 44100


def convert_files(convert_files: List[FileToConvert]):
Expand All @@ -43,6 +44,7 @@ def convert_files(convert_files: List[FileToConvert]):
convert_file.input_file_path,
convert_file.output_file_path,
convert_file.max_duration,
convert_file.sample_rate,
)
)

Expand Down Expand Up @@ -72,6 +74,7 @@ def convert_files_manager(*convert_files: FileToConvert) -> None | str | list[st
convert_file.input_file_path,
filename.name,
convert_file.max_duration,
convert_file.sample_rate,
)
)
list_objects.append(filename)
Expand All @@ -89,7 +92,7 @@ def convert_files_manager(*convert_files: FileToConvert) -> None | str | list[st
obj.close()


def _convert_to_wav(input_file_path, output_file_path, max_duration):
def _convert_to_wav(input_file_path, output_file_path, max_duration, sample_rate=44100):
_run_subprocess(
[
"ffmpeg",
Expand All @@ -102,13 +105,13 @@ def _convert_to_wav(input_file_path, output_file_path, max_duration):
"-i",
str(input_file_path),
"-ar",
"44100",
str(sample_rate),
str(output_file_path),
]
)


def _convert_to_m4a(input_file_path, output_file_path, max_duration):
def _convert_to_m4a(input_file_path, output_file_path, max_duration, sample_rate=44100):
_run_subprocess(
[
"ffmpeg",
Expand All @@ -125,7 +128,7 @@ def _convert_to_m4a(input_file_path, output_file_path, max_duration):
"-b:a",
"192k",
"-ar",
"44100",
str(sample_rate),
"-movflags",
"+faststart",
str(output_file_path),
Expand Down
Loading

0 comments on commit 429c1d2

Please sign in to comment.