{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# StreamWriter Advanced Usage\n\n**Author**: [Moto Hira](moto@meta.com)_\n\nThis tutorial shows how to use :py:class:`torchaudio.io.StreamWriter` to\nplay audio and video.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
This tutorial uses hardware devices, thus it is not portable across\n different operating systems.\n\n The tutorial was written and tested on MacBook Pro (M1, 2020).
This tutorial requires torchaudio nightly build and FFmpeg libraries (>=4.1, <4.4).\n\n To install torchaudio nightly build, please refer to\n https://pytorch.org/get-started/locally/ .\n\n\n There are multiple ways to install FFmpeg libraries.\n If you are using Anaconda Python distribution,\n ``conda install 'ffmpeg<4.4'`` will install the required FFmpeg libraries,\n however, this distribution does not have SDL plugin, so it cannot play\n video.
TorchAudio dynamically loads compatible FFmpeg libraries\n installed on the system.\n The types of supported formats (media format, encoder, encoder\n options etc) depend on the libraries.\n\n To check the available devices, muxers and encoders, you can use the\n following commands\n\n```console\nffmpeg -muxers\nffmpeg -encoders\nffmpeg -devices\nffmpeg -protocols
Writing to \"audiotoolbox\" is blocking operation, but it will not\n wait for the aduio playback. The device must be kept open while\n audio is being played.\n\n The following code will close the device as soon as the audio is\n written and before the playback is completed.\n Adding :py:func:`time.sleep` will help keep the device open until\n the playback is completed.\n\n```\nwith s.open():\n s.write_audio_chunk(0, waveform)
`write_video_chunk` call against SDL device blocks until SDL finishes\n playing the video.