audio.py 718 B

123456789101112131415161718192021
  1. from dataclasses import dataclass
  2. from typing import Literal, Tuple
  3. from urllib.parse import urljoin
  4. import librosa
  5. import numpy as np
  6. from aphrodite.assets.base import get_vllm_public_assets, vLLM_S3_BUCKET_URL
  7. ASSET_DIR = "multimodal_asset"
  8. @dataclass(frozen=True)
  9. class AudioAsset:
  10. name: Literal["winning_call", "mary_had_lamb"]
  11. @property
  12. def audio_and_sample_rate(self) -> Tuple[np.ndarray, int]:
  13. audio_path = get_vllm_public_assets(filename=f"{self.name}.ogg",
  14. s3_prefix=ASSET_DIR)
  15. return librosa.load(audio_path, sr=None)
  16. @property
  17. def url(self) -> str:
  18. return urljoin(vLLM_S3_BUCKET_URL, f"{ASSET_DIR}/{self.name}.ogg")