From a31f86bf1a38ea839db48ad4d594fe3c49d5b7cf Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Wed, 18 Sep 2024 01:32:31 -0400 Subject: [PATCH] Combine read, read_fid --- auto_editor/render/audio.py | 7 ++++--- auto_editor/wavfile.py | 10 +++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/auto_editor/render/audio.py b/auto_editor/render/audio.py index 758880ce6..f7ad84c39 100644 --- a/auto_editor/render/audio.py +++ b/auto_editor/render/audio.py @@ -19,7 +19,7 @@ from auto_editor.utils.cmdkw import ParserError, parse_with_palet, pAttr, pAttrs from auto_editor.utils.log import Log from auto_editor.utils.types import Args -from auto_editor.wavfile import AudioData, read, read_fid, write +from auto_editor.wavfile import AudioData, read, write norm_types = { "ebu": pAttrs( @@ -226,7 +226,7 @@ def process_audio_clip( output_file.close() output_bytes.seek(0) - return read_fid(output_bytes)[1] + return read(output_bytes)[1] def make_new_audio( @@ -254,7 +254,8 @@ def make_new_audio( for c, clip in enumerate(layer): if (clip.src, clip.stream) not in samples: audio_path = ensure.audio(clip.src, clip.stream) - samples[(clip.src, clip.stream)] = read(audio_path)[1] + with open(audio_path, "rb") as file: + samples[(clip.src, clip.stream)] = read(file)[1] if arr is None: leng = max(round((layer[-1].start + layer[-1].dur) * sr / tb), sr // tb) diff --git a/auto_editor/wavfile.py b/auto_editor/wavfile.py index cfe09a32f..f1952a108 100644 --- a/auto_editor/wavfile.py +++ b/auto_editor/wavfile.py @@ -199,12 +199,7 @@ def _handle_pad_byte(fid: Reader, size: int) -> None: fid.seek(1, 1) -def read(filename: str) -> tuple[int, AudioData]: - fid = open(filename, "rb") - return read_fid(fid) - - -def read_fid(fid: Reader) -> tuple[int, AudioData]: +def read(fid: Reader) -> tuple[int, AudioData]: file_sig = fid.read(4) if file_sig in (b"RIFF", b"RIFX"): data_size, file_size, en = _read_riff_chunk(file_sig, fid) @@ -303,7 +298,8 @@ def main() -> None: with open("test.wav", "wb") as file: write(file, 48_000, data) - read_sr, read_data = read("test.wav") + with open("test.wav", "rb") as file: + read_sr, read_data = read(file) assert read_sr == 48_000 assert np.array_equal(data, read_data)