diff --git a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py index 57b93e35d9..aa79e9d740 100644 --- a/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py +++ b/examples/tutorials/asr_inference_with_ctc_decoder_tutorial.py @@ -72,6 +72,26 @@ import torch import torchaudio +try: + import torchaudio.prototype.ctc_decoder +except ModuleNotFoundError: + try: + import google.colab + + print( + """ + To enable running this notebook in Google Colab, install nightly + torch and torchaudio builds by adding the following code block to the top + of the notebook before running it: + + !pip3 uninstall -y torch torchvision torchaudio + !pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu + """ + ) + except ModuleNotFoundError: + pass + raise + ###################################################################### # Acoustic Model and Data diff --git a/examples/tutorials/device_asr.py b/examples/tutorials/device_asr.py index 46804a5d97..6aeaf7a8a3 100644 --- a/examples/tutorials/device_asr.py +++ b/examples/tutorials/device_asr.py @@ -10,7 +10,7 @@ .. note:: - This tutorial requires prototype Streaming API and ffmpeg>=4.1. + This tutorial requires prototype Streaming API, ffmpeg>=4.1, and SentencePiece. Prototype features are not part of binary releases, but available in nightly build. Please refer to https://pytorch.org for installing @@ -20,6 +20,8 @@ ``conda install -c anaconda ffmpeg`` will install the required libraries. + You can install SentencePiece by running ``pip install sentencepiece``. + .. note:: This tutorial was tested on MacBook Pro and Dynabook with Windows 10. diff --git a/examples/tutorials/online_asr_tutorial.py b/examples/tutorials/online_asr_tutorial.py index 71e0e75aa5..0c1d279346 100644 --- a/examples/tutorials/online_asr_tutorial.py +++ b/examples/tutorials/online_asr_tutorial.py @@ -13,8 +13,8 @@ # # .. note:: # -# This tutorial requires torchaudio with prototype features and -# FFmpeg libraries (>=4.1). +# This tutorial requires torchaudio with prototype features, +# FFmpeg libraries (>=4.1), and SentencePiece. # # torchaudio prototype features are available on nightly builds. # Please refer to https://pytorch.org/get-started/locally/ @@ -30,13 +30,7 @@ # ``conda install -c anaconda ffmpeg`` will install # the required libraries. # -# When running this tutorial in Google Colab, the following -# command should do. -# -# .. code:: -# -# !add-apt-repository -y ppa:savoury1/ffmpeg4 -# !apt-get -qq install -y ffmpeg +# You can install SentencePiece by running ``pip install sentencepiece``. ###################################################################### # 1. Overview @@ -59,10 +53,32 @@ import torch import torchaudio +try: + from torchaudio.prototype.io import Streamer +except ModuleNotFoundError: + try: + import google.colab + + print( + """ + To enable running this notebook in Google Colab, install nightly + torch and torchaudio builds and the requisite third party libraries by + adding the following code block to the top of the notebook before running it: + + !pip3 uninstall -y torch torchvision torchaudio + !pip3 install --pre torch torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu + !pip3 install sentencepiece + !add-apt-repository -y ppa:savoury1/ffmpeg4 + !apt-get -qq install -y ffmpeg + """ + ) + except ModuleNotFoundError: + pass + raise + print(torch.__version__) print(torchaudio.__version__) -from torchaudio.prototype.io import Streamer ###################################################################### # 3. Construct the pipeline diff --git a/examples/tutorials/streaming_api_tutorial.py b/examples/tutorials/streaming_api_tutorial.py index 106366afe7..ec5a85ac3d 100644 --- a/examples/tutorials/streaming_api_tutorial.py +++ b/examples/tutorials/streaming_api_tutorial.py @@ -29,13 +29,6 @@ # ``conda install -c anaconda ffmpeg`` will install # the required libraries. # -# When running this tutorial in Google Colab, the following -# command should do. -# -# .. code:: -# -# !add-apt-repository -y ppa:savoury1/ffmpeg4 -# !apt-get -qq install -y ffmpeg ###################################################################### # 1. Overview @@ -77,7 +70,28 @@ import matplotlib.pyplot as plt import torch import torchaudio -from torchaudio.prototype.io import Streamer + +try: + from torchaudio.prototype.io import Streamer +except ModuleNotFoundError: + try: + import google.colab + + print( + """ + To enable running this notebook in Google Colab, install nightly + torch and torchaudio builds and the requisite third party libraries by + adding the following code block to the top of the notebook before running it: + + !pip3 uninstall -y torch torchvision torchaudio + !pip3 install --pre torch torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu + !add-apt-repository -y ppa:savoury1/ffmpeg4 + !apt-get -qq install -y ffmpeg + """ + ) + except ModuleNotFoundError: + pass + raise print(torch.__version__) print(torchaudio.__version__)