Skip to content

Add Docs for AudioEncoder #717

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

NicolasHug
Copy link
Member

This PR adds docstrings and a tutorial for the AudioEncoder, plus some minor changes listed in the comments below

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 9, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in this file, as well as the files renaming, are meant to separate our "tutorials" page into 2 separate sections: one for decoding, one for encoding.

@@ -16,8 +26,11 @@ def __init__(self, samples: Tensor, *, sample_rate: int):
raise ValueError(
f"Expected samples to be a Tensor, got {type(samples) = }."
)
if samples.ndim == 1:
# make it 2D and assume 1 channel
samples = samples[None, :]
Copy link
Member Author

Choose a reason for hiding this comment

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

Drive-by, I think this makes sense, i.e. if the input tensor is 1D we assume it's 1 channel instead of raising an error

Copy link
Contributor

Choose a reason for hiding this comment

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

Is that the most idomatic way to do that? There's also unsqueeze, view or reshape. Minor, but I'm surprised at how this works.

uses the version of FFmpeg you already have installed. FFmpeg is a mature
library with broad coverage available on most systems. It is, however, not
easy to use. TorchCodec abstracts FFmpeg's complexity to ensure it is used
* Relying on [FFmpeg](https://www.ffmpeg.org/) to do the decoding / encoding.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I prefer "x and y" as opposed to "x / y" in prose.

order = [
"audio_encoding.py",
]

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment explaining that we have two top-level galleries, and for that reason, we need to figure out which gallery we're using (decoding versus encoding)? I was real confused until I concluded that must be what's going on.

@scotts
Copy link
Contributor

scotts commented Jun 9, 2025

Moving the examples into decoding and encoding subdirectories makes sense, but I'm curious: will that change the resulting tutorial URL? We already have some pointers to these tutorials floating around blogs and social media.


# %%
# We first instantiate an :class:`~torchcodec.encoders.AudioEncoder`. We pass it
# the samples to be encoded. The samples must a 2D tensors of shape
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "The samples must be a 2D tensors of shape"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants