import numpy as np
import numpy.typing as npt
import soundfile as sf
from . import assets_path

ident_fname = str(assets_path / "ident.wav")

class Ident:
    wav: npt.NDArray[np.float32]
    sample_rate: int
    duration: float

    def __init__(self):
        self.wav, self.sample_rate = sf.read(ident_fname, dtype="float32")
        self.duration = len(self.wav) / self.sample_rate
        if self.duration < 10:
            raise ValueError(
                f"Ident audio is too short: {self.duration:.2f}s "
                f"({ident_fname})"
            )

    def __repr__(self) -> str:
        return (
            "Ident("
            f"sample_rate={self.sample_rate}, "
            f"duration={self.duration:.2f}s, "
            f"shape={self.wav.shape}, "
            f"dtype={self.wav.dtype}"
            ")"
        )


ident: Ident = Ident()
