Repository: pytorch/audio

Issue:
Offer pretrained wavernn model
Offer WaveRNN model with pretrained weights (8 bits waveform mode) on LJSpeech using the method as [torchvision example](https://github.com/pytorch/vision/blob/master/torchvision/models/alexnet.py#L52).

Related to #735  #749 
[Internal](https://drive.google.com/drive/folders/10XmuONMpff1zZIh-qc2pJgnHRKztpMSJ?usp=sharing)


Discussion:
# [Codecov](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=h1) Report
> Merging [#776](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=desc) into [master](https://codecov.io/gh/pytorch/audio/commit/26941fa3777618dfc659e638e524b65f22dd32a6&el=desc) will **decrease** coverage by `0.21%`.
> The diff coverage is `46.15%`.

[![Impacted file tree graph](https://codecov.io/gh/pytorch/audio/pull/776/graphs/tree.svg?width=650&height=150&src=pr&token=jWPz6v58TG)](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #776      +/-   ##
==========================================
- Coverage   89.53%   89.31%   -0.22%     
==========================================
  Files          32       33       +1     
  Lines        2617     2629      +12     
==========================================
+ Hits         2343     2348       +5     
- Misses        274      281       +7     
```


| [Impacted Files](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [torchaudio/models/\_wavernn.py](https://codecov.io/gh/pytorch/audio/pull/776/diff?src=pr&el=tree#diff-dG9yY2hhdWRpby9tb2RlbHMvX3dhdmVybm4ucHk=) | `94.06% <44.44%> (-4.12%)` | :arrow_down: |
| [torchaudio/models/utils.py](https://codecov.io/gh/pytorch/audio/pull/776/diff?src=pr&el=tree#diff-dG9yY2hhdWRpby9tb2RlbHMvdXRpbHMucHk=) | `50.00% <50.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=footer). Last update [26941fa...84a8831](https://codecov.io/gh/pytorch/audio/pull/776?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Has Linda Johnson consented to voice cloning? Without consent from Linda Johnson, this risks infringing on her [personality rights](https://en.wikipedia.org/wiki/Personality_rights), I think. This could also infringe on her "right to privacy" (the right to be left alone) or ["likeness rights"](https://www.dmlp.org/legal-guide/using-name-or-likeness-another). 

The [dataset website](https://keithito.com/LJ-Speech-Dataset/) does not mention that Linda Johnson was involved in the decision-making process for creating this dataset. I think it'd be important to consider Linda Johnson's perspective before distributing a clone of her voice to the public! Thank you!
> Has Linda Johnson consented to voice cloning? Unless you get consent from Linda Johnson, you risk infringing on her personality rights: https://en.wikipedia.org/wiki/Personality_rights
> 
> Linda Johnson as not agreed to license her voice, at least the dataset does not give any indication that she has.
> 
> Please consider Linda Johnson's personal rights before distributing a clone of her voice to the public! Thank you!

Thank you @PetrochukM for the input! Let me bring @keithito to this discussion.

@keithito -- I'm planning to offer pre-trained weights for a WaveRNN model based on LJSpeech in torchaudio. Can you add clarity about whether the license of this dataset allows doing so? Thank you!

cc @soumith @vincentqb @astaff @dongreenberg
Hi @jimchen90, all text and audio in the LJ Speech Dataset is in the public domain. For more information, please see these resources from LibriVox, the project that originally released the recordings:
  * https://librivox.org/pages/public-domain/
  * https://wiki.librivox.org/index.php/Copyright_and_Public_Domain

I have personally corresponded with Linda (the voice actor who read the audiobooks), and she has been very supportive of having her recordings used as the basis of a public domain speech dataset.
Hi @jimchen90! 

Thank you for your pull request. We require contributors to sign our Contributor License Agreement, and yours needs attention.

You currently have a record in our system, but we do not have a signature on file. 

In order for us to review and merge your code, please sign at <https://code.facebook.com/cla>. **If you are contributing on behalf of someone else (eg your employer)**, the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at [cla@fb.com](mailto:cla@fb.com?subject=CLA%20for%20pytorch%2Faudio%20%23776). Thanks!
@jimchen90 @vincentqb 

Thanks for working on it. Is any ETA?
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Resolving patch:
diff --git a/torchaudio/models/__init__.py b/torchaudio/models/__init__.py
--- a/torchaudio/models/__init__.py
+++ b/torchaudio/models/__init__.py
@@ -1,5 +1,5 @@
 from .wav2letter import Wav2Letter
-from .wavernn import WaveRNN
+from .wavernn import WaveRNN, wavernn
 from .conv_tasnet import ConvTasNet
 from .deepspeech import DeepSpeech
 from .wav2vec2 import (
@@ -13,6 +13,7 @@
 __all__ = [
     'Wav2Letter',
     'WaveRNN',
+    'wavernn',
     'ConvTasNet',
     'DeepSpeech',
     'Wav2Vec2Model',
diff --git a/torchaudio/models/wavernn.py b/torchaudio/models/wavernn.py
--- a/torchaudio/models/wavernn.py
+++ b/torchaudio/models/wavernn.py
@@ -1,8 +1,10 @@
-from typing import List, Tuple
+from typing import List, Tuple, Dict, Any
 
 import torch
 from torch import Tensor
 from torch import nn
+from torch.hub import load_state_dict_from_url
+
 
 __all__ = [
     "ResBlock",
@@ -10,9 +12,29 @@
     "Stretch2d",
     "UpsampleNetwork",
     "WaveRNN",
+    "wavernn",
 ]
 
 
+_MODEL_CONFIG_AND_URLS: Dict[str, Tuple[str, Dict[str, Any]]] = {
+    'wavernn_10k_epochs_8bits_ljspeech': (
+        'https://download.pytorch.org/models/audio/wavernn_10k_epochs_8bits_ljspeech.pth',
+        {
+            'upsample_scales': [5, 5, 11],
+            'n_classes': 2 ** 8,  # n_bits = 8
+            'hop_length': 275,
+            'n_res_block': 10,
+            'n_rnn': 512,
+            'n_fc': 512,
+            'kernel_size': 5,
+            'n_freq': 80,
+            'n_hidden': 128,
+            'n_output': 128
+        }
+    )
+}
+
+
 class ResBlock(nn.Module):
     r"""ResNet block based on *Efficient Neural Audio Synthesis* [:footcite:`kalchbrenner2018efficient`].
 
@@ -324,3 +346,28 @@ def forward(self, waveform: Tensor, specgram: Tensor) -> Tensor:
 
         # bring back channel dimension
         return x.unsqueeze(1)
+
+
+def wavernn(checkpoint_name: str) -> WaveRNN:
+    r"""Get pretrained WaveRNN model.
+
+    Args:
+        checkpoint_name (str): The name of the checkpoint to load. Available checkpoints:
+
+            - ``"wavernn_10k_epochs_8bits_ljspeech"``:
+
+                WaveRNN model trained with 10k epochs and 8 bits depth waveform on the LJSpeech dataset.
+                The model is trained using the default parameters and code of the
+                `examples/pipeline_wavernn/main.py
+                <https://github.com/pytorch/audio/tree/master/examples/pipeline_wavernn>`_.
+    """
+    if checkpoint_name not in _MODEL_CONFIG_AND_URLS:
+        raise ValueError(
+            f"Unexpected checkpoint_name: '{checkpoint_name}'. "
+            f"Valid choices are; {list(_MODEL_CONFIG_AND_URLS.keys())}")
+
+    url, configs = _MODEL_CONFIG_AND_URLS[checkpoint_name]
+    model = WaveRNN(**configs)
+    state_dict = load_state_dict_from_url(url, progress=False)
+    model.load_state_dict(state_dict)
+    return model


Test patch: