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: usizeImplementations§
Source§impl Segment
impl Segment
pub fn new( data: Vec<u8>, sample_width: usize, frame_rate: u32, channels: usize, ) -> Segment
fn spawn(&self, data: Vec<u8>) -> Segment
pub fn frame_width(&self) -> usize
Sourcepub fn silent_at(duration_ms: f64, frame_rate: u32) -> Segment
pub fn silent_at(duration_ms: f64, frame_rate: u32) -> Segment
AudioSegment.silent(duration, frame_rate).
Sourcepub fn silent(duration_ms: f64) -> Segment
pub fn silent(duration_ms: f64) -> Segment
AudioSegment.silent(duration) — at pydub’s default 11025 Hz.
Sourcepub fn frame_count(&self) -> f64
pub fn frame_count(&self) -> f64
frame_count() — whole frames, as a float.
Sourcepub fn frame_count_ms(&self, ms: f64) -> f64
pub fn frame_count_ms(&self, ms: f64) -> f64
frame_count(ms=...) — fractional frames for a duration.
fn parse_position(&self, val: f64) -> i64
fn slice_frames(&self, start: f64, end: f64) -> Segment
Sourcepub fn slice(&self, start: Option<f64>, end: Option<f64>) -> Segment
pub fn slice(&self, start: Option<f64>, end: Option<f64>) -> Segment
segment[start:end] in milliseconds; None is an open end.
pub fn set_sample_width(self, sample_width: usize) -> Segment
pub fn set_frame_rate(self, frame_rate: u32) -> Segment
pub fn set_channels(self, channels: usize) -> Segment
Sourcepub fn overlay(self, seg: Segment, position: i64) -> Segment
pub fn overlay(self, seg: Segment, position: i64) -> Segment
overlay(seg, position) with pydub’s defaults (no loop, one pass).
Sourcepub fn fade(
&self,
to_gain: f64,
from_gain: f64,
start: Option<f64>,
end: Option<f64>,
duration: Option<f64>,
) -> Segment
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).
pub fn fade_in(&self, duration_ms: f64) -> Segment
pub fn fade_out(&self, duration_ms: f64) -> Segment
Sourcepub fn split_to_mono(&self) -> Vec<Segment>
pub fn split_to_mono(&self) -> Vec<Segment>
split_to_mono() for mono and stereo.
Sourcepub fn apply_gain_stereo(&self, left_gain: f64, right_gain: f64) -> Segment
pub fn apply_gain_stereo(&self, left_gain: f64, right_gain: f64) -> Segment
effects.apply_gain_stereo(left_gain, right_gain).
Sourcepub fn pan(&self, pan_amount: f64) -> Segment
pub fn pan(&self, pan_amount: f64) -> Segment
effects.pan(pan_amount) — not equal-power; pydub’s own formula.
fn samples_i16(&self) -> Vec<i16>
fn spawn_i16(&self, s: &[i16]) -> Segment
Sourcepub fn low_pass_filter(&self, cutoff: f64) -> Segment
pub fn low_pass_filter(&self, cutoff: f64) -> Segment
effects.low_pass_filter(cutoff) — single pole, as pydub has it.
Sourcepub fn high_pass_filter(&self, cutoff: f64) -> Segment
pub fn high_pass_filter(&self, cutoff: f64) -> Segment
effects.high_pass_filter(cutoff).
Sourcepub fn from_file(path: &Path) -> Result<Segment, AudioError>
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.
Sourcepub fn export_wav(&self, path: &Path) -> Result<()>
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.
Sourcepub fn export_ffmpeg(
&self,
path: &Path,
format: &str,
parameters: &[&str],
) -> Result<(), AudioError>
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.