class_docstr: Pipeline for text-to-audio generation using AudioLDM.
  
  This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
  implemented for all pipelines (downloading, saving, running on a particular device, etc.).
  
  Args:
      vae ([`AutoencoderKL`]):
          Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
      text_encoder ([`~transformers.ClapTextModelWithProjection`]):
          Frozen text-encoder (`ClapTextModelWithProjection`, specifically the
          [laion/clap-htsat-unfused](https://huggingface.co/laion/clap-htsat-unfused) variant.
      tokenizer ([`PreTrainedTokenizer`]):
          A [`~transformers.RobertaTokenizer`] to tokenize text.
      unet ([`UNet2DConditionModel`]):
          A `UNet2DConditionModel` to denoise the encoded audio latents.
      scheduler ([`SchedulerMixin`]):
          A scheduler to be used in combination with `unet` to denoise the encoded audio latents. Can be one of
          [`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
      vocoder ([`~transformers.SpeechT5HifiGan`]):
          Vocoder of class `SpeechT5HifiGan`.
docstr: The call function to the pipeline for generation.
  
  Args:
      prompt (`str` or `List[str]`, *optional*):
          The prompt or prompts to guide audio generation. If not defined, you need to pass `prompt_embeds`.
      audio_length_in_s (`int`, *optional*, defaults to 5.12):
          The length of the generated audio sample in seconds.
      num_inference_steps (`int`, *optional*, defaults to 10):
          The number of denoising steps. More denoising steps usually lead to a higher quality audio at the
          expense of slower inference.
      guidance_scale (`float`, *optional*, defaults to 2.5):
          A higher guidance scale value encourages the model to generate audio that is closely linked to the text
          `prompt` at the expense of lower sound quality. Guidance scale is enabled when `guidance_scale > 1`.
      negative_prompt (`str` or `List[str]`, *optional*):
          The prompt or prompts to guide what to not include in audio generation. If not defined, you need to
          pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
      num_waveforms_per_prompt (`int`, *optional*, defaults to 1):
          The number of waveforms to generate per prompt.
      eta (`float`, *optional*, defaults to 0.0):
          Corresponds to parameter eta (η) from the [DDIM](https://arxiv.org/abs/2010.02502) paper. Only applies
          to the [`~schedulers.DDIMScheduler`], and is ignored in other schedulers.
      generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
          A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
          generation deterministic.
      latents (`torch.FloatTensor`, *optional*):
          Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
          generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
          tensor is generated by sampling using the supplied random `generator`.
      prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
          provided, text embeddings are generated from the `prompt` input argument.
      negative_prompt_embeds (`torch.FloatTensor`, *optional*):
          Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
          not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
      return_dict (`bool`, *optional*, defaults to `True`):
          Whether or not to return a [`~pipelines.AudioPipelineOutput`] instead of a plain tuple.
      callback (`Callable`, *optional*):
          A function that calls every `callback_steps` steps during inference. The function is called with the
          following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
      callback_steps (`int`, *optional*, defaults to 1):
          The frequency at which the `callback` function is called. If not specified, the callback is called at
          every step.
      cross_attention_kwargs (`dict`, *optional*):
          A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
          [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
      output_type (`str`, *optional*, defaults to `"np"`):
          The output format of the generated image. Choose between `"np"` to return a NumPy `np.ndarray` or
          `"pt"` to return a PyTorch `torch.Tensor` object.
  
  Examples:
  
  Returns:
      [`~pipelines.AudioPipelineOutput`] or `tuple`:
          If `return_dict` is `True`, [`~pipelines.AudioPipelineOutput`] is returned, otherwise a `tuple` is
          returned where the first element is a list with the generated audio.
docstr_tok: ["The","call","function","to","the","pipeline","for","generation",".","Args",":","prompt","(","`","str","`","or","`","List","[","str","]","`",",","*","optional","*",")",":","The","prompt","or","prompts","to","guide","audio","generation",".","If","not","defined",",","you","need","to","pass","`","prompt_embeds","`",".","audio_length_in_s","(","`","int","`",",","*","optional","*",",","defaults","to","5.12",")",":","The","length","of","the","generated","audio","sample","in","seconds",".","num_inference_steps","(","`","int","`",",","*","optional","*",",","defaults","to","10",")",":","The","number","of","denoising","steps",".","More","denoising","steps","usually","lead","to","a","higher","quality","audio","at","the","expense","of","slower","inference",".","guidance_scale","(","`","float","`",",","*","optional","*",",","defaults","to","2.5",")",":","A","higher","guidance","scale","value","encourages","the","model","to","generate","audio","that","is","closely","linked","to","the","text","`","prompt","`","at","the","expense","of","lower","sound","quality",".","Guidance","scale","is","enabled","when","`","guidance_scale",">","1","`",".","negative_prompt","(","`","str","`","or","`","List","[","str","]","`",",","*","optional","*",")",":","The","prompt","or","prompts","to","guide","what","to","not","include","in","audio","generation",".","If","not","defined",",","you","need","to","pass","`","negative_prompt_embeds","`","instead",".","Ignored","when","not","using","guidance","(","`","guidance_scale","<","1","`",")",".","num_waveforms_per_prompt","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","number","of","waveforms","to","generate","per","prompt",".","eta","(","`","float","`",",","*","optional","*",",","defaults","to","0.0",")",":","Corresponds","to","parameter","eta","(","\u03b7",")","from","the","[","DDIM","]","(","https",":","\/\/arxiv.org\/abs\/2010.02502",")","paper",".","Only","applies","to","the","[","`","~schedulers.DDIMScheduler","`","]",",","and","is","ignored","in","other","schedulers",".","generator","(","`","torch.Generator","`","or","`","List","[","torch.Generator","]","`",",","*","optional","*",")",":","A","[","`","torch.Generator","`","]","(","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.Generator.html",")","to","make","generation","deterministic",".","latents","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","noisy","latents","sampled","from","a","Gaussian","distribution",",","to","be","used","as","inputs","for","image","generation",".","Can","be","used","to","tweak","the","same","generation","with","different","prompts",".","If","not","provided",",","a","latents","tensor","is","generated","by","sampling","using","the","supplied","random","`","generator","`",".","prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs","(","prompt","weighting",")",".","If","not","provided",",","text","embeddings","are","generated","from","the","`","prompt","`","input","argument",".","negative_prompt_embeds","(","`","torch.FloatTensor","`",",","*","optional","*",")",":","Pre-generated","negative","text","embeddings",".","Can","be","used","to","easily","tweak","text","inputs","(","prompt","weighting",")",".","If","not","provided",",","`","negative_prompt_embeds","`","are","generated","from","the","`","negative_prompt","`","input","argument",".","return_dict","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","or","not","to","return","a","[","`","~pipelines.AudioPipelineOutput","`","]","instead","of","a","plain","tuple",".","callback","(","`","Callable","`",",","*","optional","*",")",":","A","function","that","calls","every","`","callback_steps","`","steps","during","inference",".","The","function","is","called","with","the","following","arguments",":","`","callback","(","step",":","int",",","timestep",":","int",",","latents",":","torch.FloatTensor",")","`",".","callback_steps","(","`","int","`",",","*","optional","*",",","defaults","to","1",")",":","The","frequency","at","which","the","`","callback","`","function","is","called",".","If","not","specified",",","the","callback","is","called","at","every","step",".","cross_attention_kwargs","(","`","dict","`",",","*","optional","*",")",":","A","kwargs","dictionary","that","if","specified","is","passed","along","to","the","[","`","AttentionProcessor","`","]","as","defined","in","[","`","self.processor","`","]","(","https",":","\/\/github.com\/huggingface\/diffusers\/blob\/main\/src\/diffusers\/models\/attention_processor.py",")",".","output_type","(","`","str","`",",","*","optional","*",",","defaults","to","`","``","np","''","`",")",":","The","output","format","of","the","generated","image",".","Choose","between","`","``","np","''","`","to","return","a","NumPy","`","np.ndarray","`","or","`","``","pt","''","`","to","return","a","PyTorch","`","torch.Tensor","`","object",".","Examples",":","Returns",":","[","`","~pipelines.AudioPipelineOutput","`","]","or","`","tuple","`",":","If","`","return_dict","`","is","`","True","`",",","[","`","~pipelines.AudioPipelineOutput","`","]","is","returned",",","otherwise","a","`","tuple","`","is","returned","where","the","first","element","is","a","list","with","the","generated","audio","."]
code: def __call__(
      self,
      prompt: Union[str, List[str]] = None,
      audio_length_in_s: Optional[float] = None,
      num_inference_steps: int = 10,
      guidance_scale: float = 2.5,
      negative_prompt: Optional[Union[str, List[str]]] = None,
      num_waveforms_per_prompt: Optional[int] = 1,
      eta: float = 0.0,
      generator: Optional[
          Union[torch.Generator, List[torch.Generator]]
      ] = None,
      latents: Optional[torch.FloatTensor] = None,
      prompt_embeds: Optional[torch.FloatTensor] = None,
      negative_prompt_embeds: Optional[torch.FloatTensor] = None,
      return_dict: bool = True,
      callback: Optional[
          Callable[[int, int, torch.FloatTensor], None]
      ] = None,
      callback_steps: Optional[int] = 1,
      cross_attention_kwargs: Optional[Dict[str, Any]] = None,
      output_type: Optional[str] = "np",
  ):
      r"""
      The call function to the pipeline for generation.
  
      Args:
          prompt (`str` or `List[str]`, *optional*):
              The prompt or prompts to guide audio generation. If not defined, you need to pass `prompt_embeds`.
          audio_length_in_s (`int`, *optional*, defaults to 5.12):
              The length of the generated audio sample in seconds.
          num_inference_steps (`int`, *optional*, defaults to 10):
              The number of denoising steps. More denoising steps usually lead to a higher quality audio at the
              expense of slower inference.
          guidance_scale (`float`, *optional*, defaults to 2.5):
              A higher guidance scale value encourages the model to generate audio that is closely linked to the text
              `prompt` at the expense of lower sound quality. Guidance scale is enabled when `guidance_scale > 1`.
          negative_prompt (`str` or `List[str]`, *optional*):
              The prompt or prompts to guide what to not include in audio generation. If not defined, you need to
              pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
          num_waveforms_per_prompt (`int`, *optional*, defaults to 1):
              The number of waveforms to generate per prompt.
          eta (`float`, *optional*, defaults to 0.0):
              Corresponds to parameter eta (η) from the [DDIM](https://arxiv.org/abs/2010.02502) paper. Only applies
              to the [`~schedulers.DDIMScheduler`], and is ignored in other schedulers.
          generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
              A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
              generation deterministic.
          latents (`torch.FloatTensor`, *optional*):
              Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
              generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
              tensor is generated by sampling using the supplied random `generator`.
          prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
              provided, text embeddings are generated from the `prompt` input argument.
          negative_prompt_embeds (`torch.FloatTensor`, *optional*):
              Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If
              not provided, `negative_prompt_embeds` are generated from the `negative_prompt` input argument.
          return_dict (`bool`, *optional*, defaults to `True`):
              Whether or not to return a [`~pipelines.AudioPipelineOutput`] instead of a plain tuple.
          callback (`Callable`, *optional*):
              A function that calls every `callback_steps` steps during inference. The function is called with the
              following arguments: `callback(step: int, timestep: int, latents: torch.FloatTensor)`.
          callback_steps (`int`, *optional*, defaults to 1):
              The frequency at which the `callback` function is called. If not specified, the callback is called at
              every step.
          cross_attention_kwargs (`dict`, *optional*):
              A kwargs dictionary that if specified is passed along to the [`AttentionProcessor`] as defined in
              [`self.processor`](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
          output_type (`str`, *optional*, defaults to `"np"`):
              The output format of the generated image. Choose between `"np"` to return a NumPy `np.ndarray` or
              `"pt"` to return a PyTorch `torch.Tensor` object.
  
      Examples:
  
      Returns:
          [`~pipelines.AudioPipelineOutput`] or `tuple`:
              If `return_dict` is `True`, [`~pipelines.AudioPipelineOutput`] is returned, otherwise a `tuple` is
              returned where the first element is a list with the generated audio.
      """
      # 0. Convert audio input length from seconds to spectrogram height
      vocoder_upsample_factor = (
          np.prod(self.vocoder.config.upsample_rates)
          / self.vocoder.config.sampling_rate
      )
  
      if audio_length_in_s is None:
          audio_length_in_s = (
              self.unet.config.sample_size
              * self.vae_scale_factor
              * vocoder_upsample_factor
          )
  
      height = int(audio_length_in_s / vocoder_upsample_factor)
  
      original_waveform_length = int(
          audio_length_in_s * self.vocoder.config.sampling_rate
      )
      if height % self.vae_scale_factor != 0:
          height = (
              int(np.ceil(height / self.vae_scale_factor))
              * self.vae_scale_factor
          )
          logger.info(
              f"Audio length in seconds {audio_length_in_s} is increased to {height * vocoder_upsample_factor} "
              f"so that it can be handled by the model. It will be cut to {audio_length_in_s} after the "
              f"denoising process."
          )
  
      # 1. Check inputs. Raise error if not correct
      self.check_inputs(
          prompt,
          audio_length_in_s,
          vocoder_upsample_factor,
          callback_steps,
          negative_prompt,
          prompt_embeds,
          negative_prompt_embeds,
      )
  
      # 2. Define call parameters
      if prompt is not None and isinstance(prompt, str):
          batch_size = 1
      elif prompt is not None and isinstance(prompt, list):
          batch_size = len(prompt)
      else:
          batch_size = prompt_embeds.shape[0]
  
      device = self._execution_device
      # here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
      # of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale = 1`
      # corresponds to doing no classifier free guidance.
      do_classifier_free_guidance = guidance_scale > 1.0
  
      # 3. Encode input prompt
      prompt_embeds = self._encode_prompt(
          prompt,
          device,
          num_waveforms_per_prompt,
          do_classifier_free_guidance,
          negative_prompt,
          prompt_embeds=prompt_embeds,
          negative_prompt_embeds=negative_prompt_embeds,
      )
  
      # 4. Prepare timesteps
      self.scheduler.set_timesteps(num_inference_steps, device=device)
      timesteps = self.scheduler.timesteps
  
      # 5. Prepare latent variables
      num_channels_latents = self.unet.config.in_channels
      latents = self.prepare_latents(
          batch_size * num_waveforms_per_prompt,
          num_channels_latents,
          height,
          prompt_embeds.dtype,
          device,
          generator,
          latents,
      )
  
      # 6. Prepare extra step kwargs
      extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)
  
      # 7. Denoising loop
      num_warmup_steps = (
          len(timesteps) - num_inference_steps * self.scheduler.order
      )
      with self.progress_bar(total=num_inference_steps) as progress_bar:
          for i, t in enumerate(timesteps):
              # expand the latents if we are doing classifier free guidance
              latent_model_input = (
                  torch.cat([latents] * 2)
                  if do_classifier_free_guidance
                  else latents
              )
              latent_model_input = self.scheduler.scale_model_input(
                  latent_model_input, t
              )
  
              # predict the noise residual
              noise_pred = self.unet(
                  latent_model_input,
                  t,
                  encoder_hidden_states=None,
                  class_labels=prompt_embeds,
                  cross_attention_kwargs=cross_attention_kwargs,
              ).sample
  
              # perform guidance
              if do_classifier_free_guidance:
                  noise_pred_uncond, noise_pred_text = noise_pred.chunk(
                      2
                  )
                  noise_pred = noise_pred_uncond + guidance_scale * (
                      noise_pred_text - noise_pred_uncond
                  )
  
              # compute the previous noisy sample x_t -> x_t-1
              latents = self.scheduler.step(
                  noise_pred, t, latents, **extra_step_kwargs
              ).prev_sample
  
              # call the callback, if provided
              if i == len(timesteps) - 1 or (
                  (i + 1) > num_warmup_steps
                  and (i + 1) % self.scheduler.order == 0
              ):
                  progress_bar.update()
                  if callback is not None and i % callback_steps == 0:
                      step_idx = i // getattr(
                          self.scheduler, "order", 1
                      )
                      callback(step_idx, t, latents)
  
      # 8. Post-processing
      mel_spectrogram = self.decode_latents(latents)
  
      audio = self.mel_spectrogram_to_waveform(mel_spectrogram)
  
      audio = audio[:, :original_waveform_length]
  
      if output_type == "np":
          audio = audio.numpy()
  
      if not return_dict:
          return (audio,)
  
      return AudioPipelineOutput(audios=audio)
  
imports: import inspect
  from typing import Any, Callable, Dict, List, Optional, Union
  import numpy
  import torch
  import torch.nn.functional
  from transformers import ClapTextModelWithProjection, RobertaTokenizer, RobertaTokenizerFast, SpeechT5HifiGan
  from ...models import AutoencoderKL, UNet2DConditionModel
  from ...schedulers import KarrasDiffusionSchedulers
  from ...utils import logging, replace_example_docstring
  from ...utils.torch_utils import randn_tensor
  from ..pipeline_utils import AudioPipelineOutput, DiffusionPipeline
label_desc: Use image node_id 10 for calling the AudioLDMPipeline obj's underlying member method code with example usage: obj.__call__(prompt, audio_length_in_s, num_inference_steps, guidance_scale, negative_prompt, num_waveforms_per_prompt, eta, generator, latents, prompt_embeds, negative_prompt_embeds, return_dict, callback, callback_steps, cross_attention_kwargs, output_type) and returns: AudioPipelineOutput, audio