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

Fixing recording move to memory #1306

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 12 additions & 9 deletions lhotse/audio/recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Pathlike,
Seconds,
SetContainingAnything,
SmartOpen,
asdict_nonull,
compute_num_samples,
fastcopy,
Expand Down Expand Up @@ -294,19 +295,21 @@ def _aslist(x):
return x

# Case #1: no opts specified, read audio without decoding and move it in memory.
if all(opt is None for opt in (channels, offset, duration)) or (
if format is None and (all(opt is None for opt in (channels, offset, duration)) or (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if all(opt is None for opt in (channels, offset, duration, format)) would be clearer

(channels is None or _aslist(channels) == self.channel_ids)
and (offset is None or isclose(offset, 0.0))
and (duration is None or isclose(duration, self.duration))
and (duration is None or isclose(duration, self.duration)))
):
memory_sources = [
AudioSource(
type="memory",
channels=old_source.channels,
source=open(old_source.source, "rb").read(),
memory_sources = []
for old_source in self.sources:
with SmartOpen.open(old_source.source, "rb") as f:
source = f.read()
memory_sources.append(AudioSource(
type="memory",
channels=old_source.channels,
source=source,
)
)
for old_source in self.sources
]
return fastcopy(self, sources=memory_sources)

# Case #2: user specified some subset of the recording, decode audio,
Expand Down
Loading