Skip to main content

Segment

Struct Segment 

Source
pub struct Segment {
    pub data: Vec<u8>,
    pub sample_width: usize,
    pub frame_rate: u32,
    pub channels: usize,
}
Expand description

An immutable-in-spirit block of interleaved PCM. Methods consume and return segments the way pydub’s _spawn hands back new objects.

Fields§

§data: Vec<u8>§sample_width: usize§frame_rate: u32§channels: usize

Implementations§

Source§

impl Segment

Source

pub fn new( data: Vec<u8>, sample_width: usize, frame_rate: u32, channels: usize, ) -> Segment

Source

fn spawn(&self, data: Vec<u8>) -> Segment

Source

pub fn frame_width(&self) -> usize

Source

pub fn empty() -> Segment

AudioSegment.empty().

Source

pub fn silent_at(duration_ms: f64, frame_rate: u32) -> Segment

AudioSegment.silent(duration, frame_rate).

Source

pub fn silent(duration_ms: f64) -> Segment

AudioSegment.silent(duration) — at pydub’s default 11025 Hz.

Source

pub fn frame_count(&self) -> f64

frame_count() — whole frames, as a float.

Source

pub fn frame_count_ms(&self, ms: f64) -> f64

frame_count(ms=...) — fractional frames for a duration.

Source

pub fn len_ms(&self) -> i64

len(segment) in milliseconds.

Source

fn parse_position(&self, val: f64) -> i64

Source

fn slice_frames(&self, start: f64, end: f64) -> Segment

Source

pub fn slice(&self, start: Option<f64>, end: Option<f64>) -> Segment

segment[start:end] in milliseconds; None is an open end.

Source

pub fn at(&self, ms: f64) -> Segment

segment[ms] — one millisecond, deliberately not clamped.

Source

fn get_frame(&self, index: i64) -> &[u8] ⓘ

get_frame(index).

Source

pub fn repeat(&self, n: i64) -> Segment

segment * n for an integer n.

Source

pub fn gain(&self, db: f64) -> Segment

segment + db / segment - db — apply_gain.

Source

pub fn set_sample_width(self, sample_width: usize) -> Segment

Source

pub fn set_frame_rate(self, frame_rate: u32) -> Segment

Source

pub fn set_channels(self, channels: usize) -> Segment

Source

pub fn sync(a: Segment, b: Segment) -> (Segment, Segment)

AudioSegment._sync(a, b).

Source

pub fn append(self, other: Segment) -> Segment

self + other — append(other, crossfade=0).

Source

pub fn overlay(self, seg: Segment, position: i64) -> Segment

overlay(seg, position) with pydub’s defaults (no loop, one pass).

Source

pub fn fade( &self, to_gain: f64, from_gain: f64, start: Option<f64>, end: Option<f64>, duration: Option<f64>, ) -> Segment

fade(to_gain, from_gain, start, end, duration).

Source

pub fn fade_in(&self, duration_ms: f64) -> Segment

Source

pub fn fade_out(&self, duration_ms: f64) -> Segment

Source

pub fn split_to_mono(&self) -> Vec<Segment>

split_to_mono() for mono and stereo.

Source

pub fn apply_gain_stereo(&self, left_gain: f64, right_gain: f64) -> Segment

effects.apply_gain_stereo(left_gain, right_gain).

Source

pub fn pan(&self, pan_amount: f64) -> Segment

effects.pan(pan_amount) — not equal-power; pydub’s own formula.

Source

fn samples_i16(&self) -> Vec<i16>

Source

fn spawn_i16(&self, s: &[i16]) -> Segment

Source

pub fn low_pass_filter(&self, cutoff: f64) -> Segment

effects.low_pass_filter(cutoff) — single pole, as pydub has it.

Source

pub fn high_pass_filter(&self, cutoff: f64) -> Segment

effects.high_pass_filter(cutoff).

Source

pub fn from_file(path: &Path) -> Result<Segment, AudioError>

AudioSegment.from_file(path): WAVs by name are read directly, everything else goes through ffmpeg exactly as pydub drives it.

Source

pub fn export_wav(&self, path: &Path) -> Result<()>

export(path, format="wav") with no codec or parameters — Python’s wave module writes the file, no ffmpeg involved.

Source

pub fn wav_bytes(&self) -> Vec<u8> ⓘ

The bytes wave.open(f, "wb") produces for this segment.

Source

pub fn export_ffmpeg( &self, path: &Path, format: &str, parameters: &[&str], ) -> Result<(), AudioError>

export(path, format=fmt, parameters=...) through ffmpeg: a temporary WAV in, ffmpeg -y -f wav -i tmp [params] -f fmt out — the exact command pydub builds, so the encoded bytes match.

Trait Implementations§

Source§

impl Clone for Segment

Source§

fn clone(&self) -> Segment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Segment

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Segment

Source§

fn eq(&self, other: &Segment) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Segment

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> Same for T

Source§

type Output = T

Should always be Self
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.