Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine read, read_fid #529

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions auto_editor/render/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions auto_editor/wavfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down