Skip to content

Commit 1f1b019

Browse files
author
Sam Anklesaria
committed
Remove tutorial section on streaming loading
1 parent b2b5f40 commit 1f1b019

File tree

1 file changed

+0
-45
lines changed

1 file changed

+0
-45
lines changed

examples/tutorials/audio_io_tutorial.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -262,51 +262,6 @@ def plot_specgram(waveform, sample_rate, title="Spectrogram"):
262262
plot_specgram(waveform, sample_rate, title="From S3")
263263

264264

265-
######################################################################
266-
# Tips on slicing
267-
# ---------------
268-
#
269-
# Providing ``num_frames`` and ``frame_offset`` arguments restricts
270-
# decoding to the corresponding segment of the input.
271-
#
272-
# The same result can be achieved using vanilla Tensor slicing,
273-
# (i.e. ``waveform[:, frame_offset:frame_offset+num_frames]``). However,
274-
# providing ``num_frames`` and ``frame_offset`` arguments is more
275-
# efficient.
276-
#
277-
# This is because the function will end data acquisition and decoding
278-
# once it finishes decoding the requested frames. This is advantageous
279-
# when the audio data are transferred via network as the data transfer will
280-
# stop as soon as the necessary amount of data is fetched.
281-
#
282-
# The following example illustrates this.
283-
#
284-
285-
# Illustration of two different decoding methods.
286-
# The first one will fetch all the data and decode them, while
287-
# the second one will stop fetching data once it completes decoding.
288-
# The resulting waveforms are identical.
289-
290-
frame_offset, num_frames = 16000, 16000 # Fetch and decode the 1 - 2 seconds
291-
292-
url = "https://download.pytorch.org/torchaudio/tutorial-assets/Lab41-SRI-VOiCES-src-sp0307-ch127535-sg0042.wav"
293-
print("Fetching all the data...")
294-
with requests.get(url, stream=True) as response:
295-
waveform1, sample_rate1 = load_torchcodec(_hide_seek(response.raw))
296-
waveform1 = waveform1[:, frame_offset : frame_offset + num_frames]
297-
print(f" - Fetched {response.raw.tell()} bytes")
298-
299-
print("Fetching until the requested frames are available...")
300-
with requests.get(url, stream=True) as response:
301-
waveform2, sample_rate2 = load_torchcodec(
302-
_hide_seek(response.raw), frame_offset=frame_offset, num_frames=num_frames
303-
)
304-
print(f" - Fetched {response.raw.tell()} bytes")
305-
306-
print("Checking the resulting waveform ... ", end="")
307-
assert (waveform1 == waveform2).all()
308-
print("matched!")
309-
310265
######################################################################
311266
# Saving audio to file
312267
# --------------------

0 commit comments

Comments
 (0)