pub trait AudioGpu: Send + Sync {
// Required methods
fn sample_audio_frame(
&self,
embedding: &[f32],
temperature: f32,
top_k: usize,
) -> [i32; 8];
fn detokenize_to_spectrum(
&self,
cpu_weights: &DetokenizerWeights,
codes: &[i32],
) -> Vec<f32>;
fn reset_depthformer(&self);
fn reset_detokenizer(&self);
fn supports_depthformer(&self) -> bool;
// Provided methods
fn sample_audio_frame_async<'a>(
&'a self,
embedding: &'a [f32],
temperature: f32,
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<[i32; 8]>> + Send + 'a>> { ... }
fn detokenize_to_spectrum_async<'a>(
&'a self,
cpu_weights: &'a DetokenizerWeights,
codes: &'a [i32],
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>> { ... }
fn istft_to_pcm(
&self,
spectrum: &[f32],
n_fft: usize,
hop_length: usize,
) -> Vec<f32> { ... }
fn istft_to_pcm_async<'a>(
&'a self,
spectrum: &'a [f32],
n_fft: usize,
hop_length: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>> { ... }
fn try_acquire_session(&self) -> bool { ... }
fn release_session(&self) { ... }
}Expand description
GPU-accelerated audio backend. Implementations provide Metal or WGPU dispatch for the depthformer (code sampling) and detokenizer (spectrum).
Required Methods§
Sourcefn sample_audio_frame(
&self,
embedding: &[f32],
temperature: f32,
top_k: usize,
) -> [i32; 8]
fn sample_audio_frame( &self, embedding: &[f32], temperature: f32, top_k: usize, ) -> [i32; 8]
Sample 8 audio codes from an LLM embedding using the depthformer.
Sourcefn detokenize_to_spectrum(
&self,
cpu_weights: &DetokenizerWeights,
codes: &[i32],
) -> Vec<f32>
fn detokenize_to_spectrum( &self, cpu_weights: &DetokenizerWeights, codes: &[i32], ) -> Vec<f32>
Convert 8 audio codes to spectrum [n_frames × n_fft_bins × 2].
Sourcefn reset_depthformer(&self)
fn reset_depthformer(&self)
Reset depthformer KV caches (called per audio frame).
Sourcefn reset_detokenizer(&self)
fn reset_detokenizer(&self)
Reset detokenizer state (conv buffers + KV caches, called per generation).
Sourcefn supports_depthformer(&self) -> bool
fn supports_depthformer(&self) -> bool
Whether AudioGpu::sample_audio_frame is actually implemented here.
Provided Methods§
Sourcefn sample_audio_frame_async<'a>(
&'a self,
embedding: &'a [f32],
temperature: f32,
top_k: usize,
) -> Pin<Box<dyn Future<Output = Result<[i32; 8]>> + Send + 'a>>
fn sample_audio_frame_async<'a>( &'a self, embedding: &'a [f32], temperature: f32, top_k: usize, ) -> Pin<Box<dyn Future<Output = Result<[i32; 8]>> + Send + 'a>>
Async version of Self::sample_audio_frame for WebGPU / browser wasm.
Sourcefn detokenize_to_spectrum_async<'a>(
&'a self,
cpu_weights: &'a DetokenizerWeights,
codes: &'a [i32],
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>>
fn detokenize_to_spectrum_async<'a>( &'a self, cpu_weights: &'a DetokenizerWeights, codes: &'a [i32], ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>>
Async version of Self::detokenize_to_spectrum.
Sourcefn istft_to_pcm(
&self,
spectrum: &[f32],
n_fft: usize,
hop_length: usize,
) -> Vec<f32>
fn istft_to_pcm( &self, spectrum: &[f32], n_fft: usize, hop_length: usize, ) -> Vec<f32>
Convert the accumulated spectrum [n_frames × n_fft_bins × 2] (log-mag,
angle) to PCM via ISTFT. Defaults to the CPU istft_to_pcm; GPU backends
override to run the iDFT-matmul + windowed overlap-add on-device.
Sourcefn istft_to_pcm_async<'a>(
&'a self,
spectrum: &'a [f32],
n_fft: usize,
hop_length: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>>
fn istft_to_pcm_async<'a>( &'a self, spectrum: &'a [f32], n_fft: usize, hop_length: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<f32>>> + Send + 'a>>
Async version of Self::istft_to_pcm.
Sourcefn try_acquire_session(&self) -> bool
fn try_acquire_session(&self) -> bool
Attempt to acquire an exclusive session lease for multi-frame generation. Returns true if acquired, or false if another session is actively generating audio.
Sourcefn release_session(&self)
fn release_session(&self)
Release the exclusive session lease acquired by Self::try_acquire_session.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".