class_docstr: WaveRNN model from *Efficient Neural Audio Synthesis* :cite:`wavernn`
  based on the implementation from `fatchord/WaveRNN <https://github.com/fatchord/WaveRNN>`_.
  
  The original implementation was introduced in *Efficient Neural Audio Synthesis*
  :cite:`kalchbrenner2018efficient`. The input channels of waveform and spectrogram have to be 1.
  The product of `upsample_scales` must equal `hop_length`.
  
  See Also:
      * `Training example <https://github.com/pytorch/audio/tree/release/0.12/examples/pipeline_wavernn>`__
      * :class:`torchaudio.pipelines.Tacotron2TTSBundle`: TTS pipeline with pretrained model.
  
  Args:
      upsample_scales: the list of upsample scales.
      n_classes: the number of output classes.
      hop_length: the number of samples between the starts of consecutive frames.
      n_res_block: the number of ResBlock in stack. (Default: ``10``)
      n_rnn: the dimension of RNN layer. (Default: ``512``)
      n_fc: the dimension of fully connected layer. (Default: ``512``)
      kernel_size: the number of kernel size in the first Conv1d layer. (Default: ``5``)
      n_freq: the number of bins in a spectrogram. (Default: ``128``)
      n_hidden: the number of hidden dimensions of resblock. (Default: ``128``)
      n_output: the number of output dimensions of melresnet. (Default: ``128``)
  
  Example
      >>> wavernn = WaveRNN(upsample_scales=[5,5,8], n_classes=512, hop_length=200)
      >>> waveform, sample_rate = torchaudio.load(file)
      >>> # waveform shape: (n_batch, n_channel, (n_time - kernel_size + 1) * hop_length)
      >>> specgram = MelSpectrogram(sample_rate)(waveform)  # shape: (n_batch, n_channel, n_freq, n_time)
      >>> output = wavernn(waveform, specgram)
      >>> # output shape: (n_batch, n_channel, (n_time - kernel_size + 1) * hop_length, n_classes)
class_docstr_tok: ["WaveRNN","model","from","*","Efficient","Neural","Audio","Synthesis","*",":","cite",":","`","wavernn","`","based","on","the","implementation","from","`","fatchord\/WaveRNN","<","https",":","\/\/github.com\/fatchord\/WaveRNN",">","`","_",".","The","original","implementation","was","introduced","in","*","Efficient","Neural","Audio","Synthesis","*",":","cite",":","`","kalchbrenner2018efficient","`",".","The","input","channels","of","waveform","and","spectrogram","have","to","be","1",".","The","product","of","`","upsample_scales","`","must","equal","`","hop_length","`",".","See","Also",":","*","`","Training","example","<","https",":","\/\/github.com\/pytorch\/audio\/tree\/release\/0.12\/examples\/pipeline_wavernn",">","`","__","*",":","class",":","`","torchaudio.pipelines.Tacotron2TTSBundle","`",":","TTS","pipeline","with","pretrained","model",".","Args",":","upsample_scales",":","the","list","of","upsample","scales",".","n_classes",":","the","number","of","output","classes",".","hop_length",":","the","number","of","samples","between","the","starts","of","consecutive","frames",".","n_res_block",":","the","number","of","ResBlock","in","stack",".","(","Default",":","``","10","``",")","n_rnn",":","the","dimension","of","RNN","layer",".","(","Default",":","``","512","``",")","n_fc",":","the","dimension","of","fully","connected","layer",".","(","Default",":","``","512","``",")","kernel_size",":","the","number","of","kernel","size","in","the","first","Conv1d","layer",".","(","Default",":","``","5","``",")","n_freq",":","the","number","of","bins","in","a","spectrogram",".","(","Default",":","``","128","``",")","n_hidden",":","the","number","of","hidden","dimensions","of","resblock",".","(","Default",":","``","128","``",")","n_output",":","the","number","of","output","dimensions","of","melresnet",".","(","Default",":","``","128","``",")","Example",">",">",">","wavernn","=","WaveRNN","(","upsample_scales=","[","5,5,8","]",",","n_classes=512",",","hop_length=200",")",">",">",">","waveform",",","sample_rate","=","torchaudio.load","(","file",")",">",">",">","#","waveform","shape",":","(","n_batch",",","n_channel",",","(","n_time","-","kernel_size","+","1",")","*","hop_length",")",">",">",">","specgram","=","MelSpectrogram","(","sample_rate",")","(","waveform",")","#","shape",":","(","n_batch",",","n_channel",",","n_freq",",","n_time",")",">",">",">","output","=","wavernn","(","waveform",",","specgram",")",">",">",">","#","output","shape",":","(","n_batch",",","n_channel",",","(","n_time","-","kernel_size","+","1",")","*","hop_length",",","n_classes",")"]
code: def __init__(
      self,
      upsample_scales: List[int],
      n_classes: int,
      hop_length: int,
      n_res_block: int = 10,
      n_rnn: int = 512,
      n_fc: int = 512,
      kernel_size: int = 5,
      n_freq: int = 128,
      n_hidden: int = 128,
      n_output: int = 128,
  ) -> None:
      super().__init__()
  
      self.kernel_size = kernel_size
      self._pad = (
          kernel_size - 1 if kernel_size % 2 else kernel_size
      ) // 2
      self.n_rnn = n_rnn
      self.n_aux = n_output // 4
      self.hop_length = hop_length
      self.n_classes = n_classes
      self.n_bits: int = int(math.log2(self.n_classes))
  
      total_scale = 1
      for upsample_scale in upsample_scales:
          total_scale *= upsample_scale
      if total_scale != self.hop_length:
          raise ValueError(
              f"Expected: total_scale == hop_length, but found {total_scale} != {hop_length}"
          )
  
      self.upsample = UpsampleNetwork(
          upsample_scales,
          n_res_block,
          n_freq,
          n_hidden,
          n_output,
          kernel_size,
      )
      self.fc = nn.Linear(n_freq + self.n_aux + 1, n_rnn)
  
      self.rnn1 = nn.GRU(n_rnn, n_rnn, batch_first=True)
      self.rnn2 = nn.GRU(n_rnn + self.n_aux, n_rnn, batch_first=True)
  
      self.relu1 = nn.ReLU(inplace=True)
      self.relu2 = nn.ReLU(inplace=True)
  
      self.fc1 = nn.Linear(n_rnn + self.n_aux, n_fc)
      self.fc2 = nn.Linear(n_fc + self.n_aux, n_fc)
      self.fc3 = nn.Linear(n_fc, self.n_classes)
  
imports: import math
  from typing import List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn, Tensor
label_desc: Use image node_id 1 to create a new WaveRNN object from inherited base classes: nn with example: obj = WaveRNN(upsample_scales, n_classes, hop_length, n_res_block, n_rnn, n_fc, kernel_size, n_freq, n_hidden, n_output)