Struct AudioEncoder

Source
pub struct AudioEncoder {
    pub config: AudioConfig,
    pub audio_token_id: u32,
    pub begin_audio_token_id: u32,
}
Expand description

Encoder for converting audio data into token sequences.

The AudioEncoder processes audio waveforms and converts them into token sequences that can be mixed with text tokens in multimodal applications.

§Fields

  • config - Audio processing configuration
  • audio_token_id - Token ID (u32) for audio content tokens
  • begin_audio_token_id - Token ID (u32) for marking the start of audio

Fields§

§config: AudioConfig§audio_token_id: u32§begin_audio_token_id: u32

Implementations§

Source§

impl AudioEncoder

Source

pub fn new( config: AudioConfig, audio_token_id: u32, begin_audio_token_id: u32, ) -> Self

Creates a new AudioEncoder.

§Arguments
  • config - Audio processing configuration
  • audio_token_id - Token ID (u32) representing audio content
  • begin_audio_token_id - Token ID (u32) marking the start of audio sequence
§Returns

A new AudioEncoder instance.

Source

pub fn encode(&self, audio: Audio) -> Result<AudioEncoding>

Encodes audio data into a token sequence.

This method processes the audio through resampling, padding, and tokenization to produce a sequence of tokens that represents the audio content.

§Arguments
  • audio - The audio data to encode
§Returns

An AudioEncoding containing the token sequence and processed audio.

§Errors

Returns an error if audio processing fails.

§Examples
use tekken::audio::{Audio, AudioConfig, AudioSpectrogramConfig, AudioEncoder};

let audio = Audio::from_file("audio.wav")?;
let spectrogram_config = AudioSpectrogramConfig::new(80, 160, 400)?;
let audio_config = AudioConfig::new(16000, 12.5, spectrogram_config, None)?;
let encoder = AudioEncoder::new(audio_config, 1000, 1001);

let encoding = encoder.encode(audio)?;
println!("Audio encoded to {} tokens", encoding.tokens.len());

Trait Implementations§

Source§

impl Clone for AudioEncoder

Source§

fn clone(&self) -> AudioEncoder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.