oadsrust 0.2.0

Content-addressed dataset packs and loaders for OA
// @generated by tool/gen/ds/generate.py — edit tool/gen/ds/schema/packs.json instead.
use crate::pack::{FetchProgress, Pack, PackFile};
use oa::{Engine, Result};
use std::path::PathBuf;

pub(crate) const LJSPEECH_PACK: Pack = Pack {
	name: "ljspeech",
	version: "1.1.0",
	license: "public domain (librivox)",
	files: &[PackFile {
		name: "LJSpeech-1.1.tar.bz2",
		size: 2_748_572_632,
		shake256: "7b8a9d69d9004dec8c9b5f43684944b072b5713e3aa8b9a94ec039f920f9c40a",
		urls: &["https://data.keithito.com/data/speech/LJSpeech-1.1.tar.bz2"],
	}],
};

/// PCM samples per second; every clip is 22,050 Hz mono 16-bit.
pub const SAMPLE_RATE: usize = 22050;

/// Load options for [`LjSpeech`][crate::audio::ljspeech::LjSpeech].
#[derive(Clone, Debug, Default)]
pub struct LjSpeechConfig {
	/// Cache root override. `None` resolves `OA_DATA_DIR`, then the platform
	/// cache directory; see [`data_root`](crate::pack::data_root).
	pub cache_dir: Option<PathBuf>,
}

impl LjSpeechConfig {
	/// Construct the record with its default state.
	#[inline]
	#[must_use]
	pub fn new() -> Self {
		Self::default()
	}
}

impl super::LjSpeech {
	/// Decode the selected split and upload it on this thread's
	/// default engine.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_on`](Self::load_on).
	#[inline]
	pub fn load(config: &LjSpeechConfig) -> Result<Self> {
		Self::load_on(&Engine::current()?, config)
	}

	/// Decode the selected split and upload it on `engine`.
	///
	/// This is the [`load`](Self::load) contract evaluated on
	/// `engine` instead of this thread's default engine.
	///
	/// # Errors
	///
	/// Returns the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_on(engine: &Engine, config: &LjSpeechConfig) -> Result<Self> {
		Self::load_with_progress_on(engine, config, &mut |_| true)
	}

	/// [`load`](Self::load) with a fetch progress callback.
	///
	/// # Errors
	///
	/// Returns an error when the default engine cannot be
	/// initialized, plus the errors of
	/// [`load_with_progress_on`](Self::load_with_progress_on).
	#[inline]
	pub fn load_with_progress(
		config: &LjSpeechConfig,
		progress: &mut impl FnMut(FetchProgress) -> bool,
	) -> Result<Self> {
		Self::load_with_progress_on(&Engine::current()?, config, progress)
	}
}