Skip to content

Commit 1acd939

Browse files
committed
Docs
1 parent 8ed45a7 commit 1acd939

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

examples/audio_decoding.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
import requests
2121
from IPython.display import Audio
2222

23+
2324
def play_audio(samples):
2425
return Audio(samples.data, rate=samples.sample_rate)
2526

27+
2628
# Audio source is CC0: https://opengameart.org/content/town-theme-rpg
2729
# Attribution: cynicmusic.com pixelsphere.org
2830
url = "https://opengameart.org/sites/default/files/TownTheme.mp3"
@@ -61,6 +63,7 @@ def play_audio(samples):
6163
# which returns an :class:`~torchcodec.AudioSamples` object:
6264

6365
samples = decoder.get_samples_played_in_range(start_seconds=0)
66+
6467
print(samples)
6568
play_audio(samples)
6669

@@ -76,16 +79,21 @@ def play_audio(samples):
7679
# the entire audio stream, but we can specify a custom range:
7780

7881
samples = decoder.get_samples_played_in_range(start_seconds=10, stop_seconds=70)
82+
83+
print(samples)
7984
play_audio(samples)
8085

86+
# %%
8187
# Custom sample rate
8288
# ------------------
8389
#
8490
# We can also decode the samples into a desired sample rate using the
85-
# ``sample_rate`` parameter of :class:`~torchcodec.decoders.AudioDecoder`:
91+
# ``sample_rate`` parameter of :class:`~torchcodec.decoders.AudioDecoder`. The
92+
# ouput will sound the same, but note that the number of samples greatly
93+
# increased:
8694

87-
sample_rate = 16_000
88-
decoder = AudioDecoder(raw_audio_bytes, sample_rate=sample_rate)
95+
decoder = AudioDecoder(raw_audio_bytes, sample_rate=16_000)
8996
samples = decoder.get_samples_played_in_range(start_seconds=0)
97+
9098
print(samples)
9199
play_audio(samples)

src/torchcodec/decoders/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
from ._audio_decoder import AudioDecoder # noqa
78
from ._core import AudioStreamMetadata, VideoStreamMetadata
89
from ._video_decoder import VideoDecoder # noqa
9-
from ._audio_decoder import AudioDecoder # noqa
1010

1111
SimpleVideoDecoder = VideoDecoder

src/torchcodec/decoders/_audio_decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AudioDecoder:
2424
etc.), or from videos that contain audio streams (e.g. mp4 videos).
2525
2626
Returned samples are float samples normalized in [-1, 1]
27-
27+
2828
Args:
2929
source (str, ``Pathlib.path``, ``torch.Tensor``, or bytes): The source of the audio:
3030

0 commit comments

Comments
 (0)