AudioCollector
methodAudioCollector(config: DeviceConfig | None=None, backend_type: AudioBackendType | None=None) → NoneView implementation Find the function you need. Signatures, defaults, and return types extracted from the published Python package.
phonotensor, operations from phonotensor.ops, and formatting helpers from phonotensor.fmt. Source links point to the matching GitHub commit. Internal backend classes and Python special methods are excluded.186 of 186 entries
Deprecated compatibility API. Prefer MicrophoneSource and AudioPlayer in new code. read() and collect() require an active open() context.
AudioCollector(config: DeviceConfig | None=None, backend_type: AudioBackendType | None=None) → NoneView implementation AudioCollector.list_devices() → list[AudioDevice]View implementation AudioCollector.default_input_device() → AudioDevice | NoneView implementation AudioCollector.default_output_device() → AudioDevice | NoneView implementation AudioCollector.open(config: DeviceConfig | None=None) → Iterator['AudioCollector']View implementation AudioCollector.read(frames: int) → np.ndarrayView implementation AudioCollector.collect(duration_seconds: float) → np.ndarrayView implementation AudioCollector.play(data: np.ndarray, config: DeviceConfig | None=None) → NoneView implementation AudioCollector.is_streaming → boolView implementation AudioCollector.backend_type → AudioBackendTypeView implementation AudioCollector.config → DeviceConfigView implementation Frozen configuration dataclasses and stream enums. A block_size of 0 lets the backend choose its buffer size.
SampleFormat
FLOAT32 = auto()
INT32 = auto()
INT24 = auto()
INT16 = auto()View implementation StreamMode
INPUT = auto()
OUTPUT = auto()
DUPLEX = auto()View implementation StreamConfig
sample_rate: int = 44100
channels: int = 1
sample_format: SampleFormat = SampleFormat.FLOAT32
block_size: int = 0
latency: float | None = NoneView implementation DeviceConfig
stream_config: StreamConfig = field(default_factory=StreamConfig)
mode: StreamMode = StreamMode.INPUT
device_name: str | None = None
device_index: int | None = NoneView implementation Feature data is shaped (frames, features) and can be complex. Frame timing is available when hop_length is set. to_dict() exports metadata, not data.
FeatureTensor(data: Any, sample_rate: int, feature_type: str='custom', n_fft: int | None=None, hop_length: int | None=None) → NoneView implementation FeatureTensor.data → np.ndarrayView implementation FeatureTensor.sample_rate → intView implementation FeatureTensor.feature_type → strView implementation FeatureTensor.n_fft → int | NoneView implementation FeatureTensor.hop_length → int | NoneView implementation FeatureTensor.n_frames → intView implementation FeatureTensor.n_features → intView implementation FeatureTensor.frame_rate → float | NoneView implementation FeatureTensor.duration → float | NoneView implementation FeatureTensor.dtype → np.dtypeView implementation FeatureTensor.shape → tuple[int, ...]View implementation FeatureTensor.is_complex → boolView implementation FeatureTensor.to_numpy() → np.ndarrayView implementation FeatureTensor.to_dict() → dict[str, Any]View implementation FeatureTensor.summary() → strView implementation FeatureTensor.from_dict(d: dict[str, Any], data: np.ndarray) → 'FeatureTensor'View implementation Audio samples are float32 arrays shaped (samples, channels). Time values are seconds; sample rates are Hz. Use to_numpy() for a writable copy.
AudioTensor(data: Any, sample_rate: int=44100, channels: int | None=None) → NoneView implementation AudioTensor.data → np.ndarrayView implementation AudioTensor.sample_rate → intView implementation AudioTensor.channels → intView implementation AudioTensor.num_samples → intView implementation AudioTensor.duration → floatView implementation AudioTensor.dtype → np.dtypeView implementation AudioTensor.shape → tuple[int, ...]View implementation AudioTensor.is_mono → boolView implementation AudioTensor.is_stereo → boolView implementation AudioTensor.summary() → strView implementation AudioTensor.describe() → strView implementation AudioTensor.to_numpy() → np.ndarrayView implementation AudioTensor.to_mono() → 'AudioTensor'View implementation AudioTensor.to_stereo() → 'AudioTensor'View implementation AudioTensor.channel(index: int) → 'AudioTensor'View implementation AudioTensor.copy() → 'AudioTensor'View implementation AudioTensor.time_slice(start: float=0.0, end: float | None=None) → 'AudioTensor'View implementation AudioTensor.zeros(duration: float, sample_rate: int=44100, channels: int=1) → 'AudioTensor'View implementation AudioTensor.from_numpy(data: np.ndarray, sample_rate: int=44100) → 'AudioTensor'View implementation AudioTensor.from_list(data: list[float] | list[list[float]], sample_rate: int=44100) → 'AudioTensor'View implementation AudioTensor.from_function(fn: Any, duration: float, sample_rate: int=44100, channels: int=1) → 'AudioTensor'View implementation Audio device information returned by backend device enumeration. Check input and output channel capabilities before opening a stream.
AudioDevice
index: int
name: str
max_input_channels: int
max_output_channels: int
default_sample_rate: float
is_default_input: bool
is_default_output: bool
host_api_name: strView implementation AudioDevice.supports_input → boolView implementation AudioDevice.supports_output → boolView implementation AudioDevice.supports_duplex → boolView implementation Library error hierarchy. External codec, NumPy, and OS exceptions are not always wrapped in PhonotensorError.
PhonotensorError(Exception)View implementation BackendUnavailableError(PhonotensorError)View implementation DeviceNotFoundError(PhonotensorError)View implementation StreamError(PhonotensorError)View implementation ConfigurationError(PhonotensorError)View implementation PhonotensorPermissionError(PhonotensorError)View implementation FilePermissionError(PhonotensorPermissionError)View implementation DevicePermissionError(PhonotensorPermissionError)View implementation MicrophonePermissionError(DevicePermissionError)View implementation Convert AudioTensor data to Python or serialized representations. Use matching from_dict/from_json helpers to restore audio with sample-rate metadata.
to_list(tensor: AudioTensor) → list[float] | list[list[float]]View implementation to_dict(tensor: AudioTensor) → dict[str, Any]View implementation to_json(tensor: AudioTensor, indent: int=2) → strView implementation to_csv_string(tensor: AudioTensor, delimiter: str=',') → strView implementation from_dict(d: dict[str, Any]) → AudioTensorView implementation from_json(json_str: str) → AudioTensorView implementation from_function(fn: Callable[[np.ndarray], np.ndarray], duration: float, sample_rate: int=44100, channels: int=1) → AudioTensorView implementation Text summaries and terminal-friendly sample or waveform displays. These helpers do not create graphical plots or play audio.
summary(tensor: AudioTensor) → strView implementation describe(tensor: AudioTensor) → strView implementation waveform_ascii(tensor: AudioTensor, width: int=72, height: int=16, channel: int=0) → strView implementation print_samples(tensor: AudioTensor, n: int=20, fmt: str='fixed', offset: int=0) → strView implementation File paths may be strings or pathlib.Path values. WAV, FLAC, and OGG use soundfile; MP3 needs pydub and a separate FFmpeg installation.
FileIO()View implementation FileIO.read(path: str | Path) → AudioTensorView implementation FileIO.write(tensor: AudioTensor, path: str | Path, format: str | None=None, subtype: str | None=None) → NoneView implementation FileIO.supported_formats() → list[str]View implementation Local microphone capture through PortAudio. Construction checks permissions by default. Recording is synchronous; durations are seconds and silence threshold is linear RMS amplitude.
MicrophoneSource(sample_rate: int=44100, channels: int=1, device: str | int | None=None, backend_type: AudioBackendType | None=None, skip_permission_check: bool=False) → NoneView implementation MicrophoneSource.record(duration: float) → AudioTensorView implementation MicrophoneSource.record_until_silence(threshold: float=0.01, silence_duration: float=1.0, max_duration: float=30.0) → AudioTensorView implementation MicrophoneSource.list_devices() → list[AudioDevice]View implementation MicrophoneSource.default_device() → AudioDevice | NoneView implementation Local output through PortAudio. In 0.2.2, playback is synchronous even with blocking=False. play_numpy() infers channels from the data and ignores its channels argument.
AudioPlayer(device: str | int | None=None, backend_type: AudioBackendType | None=None, skip_permission_check: bool=False) → NoneView implementation AudioPlayer.play(tensor: AudioTensor, blocking: bool=True) → NoneView implementation AudioPlayer.play_numpy(data: np.ndarray, sample_rate: int=44100, channels: int=1) → NoneView implementation JSON carries sample-rate metadata. CSV and text arrays need a sample rate on import. Rows represent samples, columns represent channels.
TextIO()View implementation TextIO.read_csv(path: str | Path, sample_rate: int=44100, delimiter: str=',', has_header: bool=True) → AudioTensorView implementation TextIO.read_json(path: str | Path) → AudioTensorView implementation TextIO.read_array(path: str | Path, sample_rate: int=44100, separator: str | None=None) → AudioTensorView implementation TextIO.write_csv(tensor: AudioTensor, path: str | Path, delimiter: str=',', include_header: bool=True) → NoneView implementation TextIO.write_json(tensor: AudioTensor, path: str | Path, indent: int=2) → NoneView implementation TextIO.write_array(tensor: AudioTensor, path: str | Path, separator: str=' ', precision: int=8) → NoneView implementation TextIO.from_list(data: list[float] | list[list[float]], sample_rate: int=44100) → AudioTensorView implementation TextIO.from_function(fn: Any, duration: float, sample_rate: int=44100, channels: int=1) → AudioTensorView implementation Scalar analysis over audio samples. dB measurements use a full-scale reference of 1. Avoid empty input for reductions such as peak, min, and max.
rms(tensor: AudioTensor) → floatRoot mean square amplitude.
View implementationpeak(tensor: AudioTensor) → floatMaximum absolute sample amplitude.
View implementationduration(tensor: AudioTensor) → floatAudio duration in seconds.
View implementationzero_crossings(tensor: AudioTensor) → intCount sign changes in the first channel, including transitions through zero.
View implementationenergy(tensor: AudioTensor) → floatSum of squared sample values.
View implementationdb_peak(tensor: AudioTensor) → floatPeak amplitude in decibels relative to 1.
View implementationdb_rms(tensor: AudioTensor) → floatRMS amplitude in decibels relative to 1.
View implementationmin_sample(tensor: AudioTensor) → floatMinimum sample value.
View implementationmax_sample(tensor: AudioTensor) → floatMaximum sample value.
View implementationmean(tensor: AudioTensor) → floatMean sample value.
View implementationstd(tensor: AudioTensor) → floatStandard deviation of sample values.
View implementationUnlike tensor operators, ops.add/subtract/multiply check sample rates and channels, then zero-pad the shorter input. mix() also pads lengths and defaults to equal averaging weights.
add(a: AudioTensor, b: AudioTensor) → AudioTensorAdd two tensors elementwise.
View implementationsubtract(a: AudioTensor, b: AudioTensor) → AudioTensorSubtract the second tensor from the first.
View implementationmultiply(a: AudioTensor, b: AudioTensor) → AudioTensorMultiply two tensors elementwise.
View implementationscale(tensor: AudioTensor, factor: float) → AudioTensorMultiply samples by a scalar factor.
View implementationmix(tensors: list[AudioTensor], weights: list[float] | None=None) → AudioTensorCombine tensors using optional weights.
View implementationConvolution and correlation of audio signals. Paired inputs must have matching sample rates. Convolution reuses a mono kernel across channels; correlation downmixes input to mono. Convolution mode controls the output length.
convolve(tensor: AudioTensor, kernel: AudioTensor, mode: Any='full') → AudioTensorConvolve signals per channel.
View implementationcross_correlate(a: AudioTensor, b: AudioTensor) → AudioTensorDownmix inputs to mono and return their full cross-correlation.
View implementationauto_correlate(tensor: AudioTensor) → AudioTensorDownmix to mono, autocorrelate, normalize by maximum absolute correlation, and retain nonnegative lags.
View implementationTime positions and durations are seconds. Concatenation and overlays require matching sample rates and channels. Use nonnegative offsets for overlays.
trim(tensor: AudioTensor, start: float=0.0, end: float | None=None) → AudioTensorExtract a time interval; bounds are clamped to the audio.
View implementationpad(tensor: AudioTensor, before: float=0.0, after: float=0.0) → AudioTensorAdd zero-valued samples before or after audio.
View implementationconcatenate(*tensors: AudioTensor) → AudioTensorJoin tensors in sequence.
View implementationsplit(tensor: AudioTensor, at: float) → tuple[AudioTensor, AudioTensor]Split into two tensors at a time in seconds.
View implementationrepeat(tensor: AudioTensor, times: int) → AudioTensorRepeat the signal a positive integer number of times.
View implementationoverlay(base: AudioTensor, layer: AudioTensor, offset: float=0.0) → AudioTensorAdd a layer at an offset, extending the output when necessary.
View implementationsilence(duration: float, sample_rate: int=44100, channels: int=1) → AudioTensorCreate zero-valued audio.
View implementationtrim_silence(tensor: AudioTensor, threshold: float=0.01, pad_seconds: float=0.05) → AudioTensorRemove quiet ends using a linear amplitude threshold, retaining optional padding.
View implementationEnvelope and dynamics operations return AudioTensors. Inspect individual parameter names for time and level units; use positive attack and release values.
adsr(attack: float, decay: float, sustain_level: float, release: float, duration: float, sample_rate: int=44100) → AudioTensorCreate a mono attack-decay-sustain-release envelope. Times are seconds; keep stage durations within the total duration.
View implementationcompress(tensor: AudioTensor, threshold: float=0.5, ratio: float=4.0) → AudioTensorReduce amplitudes above a linear threshold by ratio; this is samplewise processing without attack/release smoothing.
View implementationexpand(tensor: AudioTensor, threshold: float=0.1, ratio: float=2.0) → AudioTensorDivide samples below a linear amplitude threshold by ratio.
View implementationgate(tensor: AudioTensor, threshold: float=0.01) → AudioTensorSet samples below the absolute amplitude threshold to zero.
View implementationfollow_envelope(tensor: AudioTensor, attack: float=0.01, release: float=0.1) → AudioTensorTrack amplitude with attack and release times in seconds; returns a mono envelope.
View implementationapply_envelope(tensor: AudioTensor, envelope: AudioTensor) → AudioTensorMultiply audio by a mono or channel-matched envelope. Uncovered trailing samples become zero. Sample rates are not checked; align them first.
View implementationFeatures use mono-downmixed STFT frames. Mel values are power; MFCC uses natural-log mel values and a custom cosine transform starting at coefficient 1.
mel_spectrogram(tensor: AudioTensor, n_fft: int=2048, hop_length: int | None=None, n_mels: int=128, fmin: float=0.0, fmax: float | None=None) → FeatureTensorProject STFT power onto triangular mel bands.
View implementationmfcc(tensor: AudioTensor, n_mfcc: int=13, n_mels: int=128, n_fft: int=2048, hop_length: int | None=None, fmin: float=0.0, fmax: float | None=None) → FeatureTensorCompute coefficients from natural-log mel power using the package’s custom cosine transform.
View implementationspectral_centroid(tensor: AudioTensor, n_fft: int=2048, hop_length: int | None=None) → FeatureTensorMagnitude-weighted frequency center in Hz per frame.
View implementationspectral_rolloff(tensor: AudioTensor, threshold: float=0.85, n_fft: int=2048, hop_length: int | None=None) → FeatureTensorFrequency below which the threshold fraction of frame power lies.
View implementationspectral_flatness(tensor: AudioTensor, n_fft: int=2048, hop_length: int | None=None) → FeatureTensorRatio of geometric to arithmetic mean magnitude per frame.
View implementationspectral_bandwidth(tensor: AudioTensor, n_fft: int=2048, hop_length: int | None=None, order: int=2) → FeatureTensorMagnitude-weighted spread about the centroid in Hz.
View implementationCausal filters operate per channel. Frequencies are Hz, strictly between zero and Nyquist. Butterworth filters use second-order sections; notch uses an IIR notch filter.
lowpass(tensor: AudioTensor, cutoff: float, order: int=5) → AudioTensorButterworth low-pass filter.
View implementationhighpass(tensor: AudioTensor, cutoff: float, order: int=5) → AudioTensorButterworth high-pass filter.
View implementationbandpass(tensor: AudioTensor, low_cutoff: float, high_cutoff: float, order: int=5) → AudioTensorButterworth band-pass filter; low_cutoff must be below high_cutoff.
View implementationbandstop(tensor: AudioTensor, low_cutoff: float, high_cutoff: float, order: int=5) → AudioTensorButterworth band-stop filter.
View implementationnotch(tensor: AudioTensor, freq: float, q: float=30.0) → AudioTensorReject a frequency with quality factor q.
View implementationGenerators return mono AudioTensors. Use positive durations, sample rates, and frequencies below Nyquist for meaningful sampled signals. The current pink_noise implementation does not establish a 1/f spectrum.
sine(freq: float, duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorGenerate a sine tone; frequency is in Hz.
View implementationsquare(freq: float, duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorGenerate a square wave from the sign of a sine wave.
View implementationsawtooth(freq: float, duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorGenerate a sawtooth wave.
View implementationtriangle(freq: float, duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorGenerate a triangle wave.
View implementationimpulse(duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorCreate zeros with an impulse at the first sample.
View implementationwhite_noise(duration: float, sample_rate: int=44100, amplitude: float=1.0, seed: int | None=None) → AudioTensorGenerate uniform random noise with an optional reproducible seed.
View implementationpink_noise(duration: float, sample_rate: int=44100, amplitude: float=1.0, seed: int | None=None) → AudioTensorGenerate normalized summed Gaussian noise. The current implementation is not verified pink noise.
View implementationsweep(start_freq: float, end_freq: float, duration: float, sample_rate: int=44100, amplitude: float=1.0) → AudioTensorGenerate a sine sweep with linearly changing frequency.
View implementationPitch and time operations downmix to mono and duplicate output channels. Stereo separation is not preserved. rate must be positive; use signals long enough for the 2048-sample analysis window.
pitch_shift(tensor: AudioTensor, semitones: float) → AudioTensorShift pitch by semitones and restore the original sample count.
View implementationtime_stretch(tensor: AudioTensor, rate: float) → AudioTensorChange duration by a rate factor. A rate above one makes audio shorter.
View implementationestimate_f0(tensor: AudioTensor, frame_duration: float=0.05) → list[float]Estimate fundamental frequency per complete frame using autocorrelation; 0.0 represents unvoiced frames.
View implementationMultichannel input is averaged to mono. STFT produces complex frames; fft produces magnitudes. Default STFT hop is n_fft // 4. Supported windows: hann, hamming, blackman, bartlett, rectangular, boxcar.
fft(tensor: AudioTensor) → FeatureTensorReturn the magnitude of the one-sided FFT as a single feature frame.
View implementationpower_spectrum(tensor: AudioTensor, n_fft: int | None=None) → FeatureTensorReturn squared FFT magnitudes.
View implementationmagnitude_spectrum(tensor: AudioTensor, n_fft: int | None=None) → FeatureTensorReturn one-sided FFT magnitudes with an optional FFT length.
View implementationphase_spectrum(tensor: AudioTensor, n_fft: int | None=None) → FeatureTensorReturn one-sided FFT phases in radians.
View implementationfrequency_axis(tensor_or_rate: AudioTensor | int, n_fft: int | None=None) → np.ndarrayReturn real FFT frequency bins in Hz. Supply n_fft when passing an integer sample rate.
View implementationstft(tensor: AudioTensor, n_fft: int=2048, hop_length: int | None=None, window: str='hann') → FeatureTensorCompute complex short-time Fourier frames, padding the tail as needed.
View implementationistft(feature: FeatureTensor, n_fft: int | None=None, hop_length: int | None=None, window: str='hann', length: int | None=None) → AudioTensorReconstruct mono audio from complex STFT frames by overlap-add. Optional length trims the result.
View implementationmagnitude(feature: FeatureTensor) → FeatureTensorExtract magnitudes from complex features; real input is returned unchanged.
View implementationphase(feature: FeatureTensor) → FeatureTensorExtract angles in radians; requires complex features.
View implementationReturn transformed audio. gain uses decibels; fade durations are seconds. normalize scales the global peak. Use positive durations of at least one sample for fades.
normalize(tensor: AudioTensor, peak_level: float=1.0) → AudioTensorScale samples so the global absolute peak equals peak_level. Silent input returns a copy.
View implementationresample(tensor: AudioTensor, target_rate: int) → AudioTensorChange sample rate using SciPy Fourier resampling.
View implementationreverse(tensor: AudioTensor) → AudioTensorReverse sample order.
View implementationfade_in(tensor: AudioTensor, duration: float) → AudioTensorApply a linear ramp from zero to one at the start.
View implementationfade_out(tensor: AudioTensor, duration: float) → AudioTensorApply a linear ramp from one to zero at the end.
View implementationgain(tensor: AudioTensor, db: float) → AudioTensorApply an amplitude gain of 10 ** (db / 20).
View implementationinvert_phase(tensor: AudioTensor) → AudioTensorNegate the sample values.
View implementationclip(tensor: AudioTensor, min_val: float=-1.0, max_val: float=1.0) → AudioTensorLimit samples to the supplied minimum and maximum.
View implementationBest-effort file and audio permission checks. Successful preflight checks do not guarantee a device can open; OS and backend errors can still propagate.
check_microphone_access() → NoneView implementation can_access_microphone() → boolView implementation check_output_device_access() → NoneView implementation can_access_output_device() → boolView implementation check_file_readable(path: str | Path) → NoneView implementation check_file_writable(path: str | Path) → NoneView implementation check_directory_writable(path: str | Path) → NoneView implementation can_read_file(path: str | Path) → boolView implementation can_write_file(path: str | Path) → boolView implementation Platform detection and backend selection. PortAudio is the implemented backend; other enum names are not separate implemented engines.
OperatingSystem
WINDOWS = auto()
MACOS = auto()
LINUX = auto()
UNKNOWN = auto()View implementation AudioBackendType
PORTAUDIO = auto()
WASAPI = auto()
COREAUDIO = auto()
ALSA = auto()
PULSEAUDIO = auto()View implementation PlatformInfo
os: OperatingSystem
os_version: str
machine: str
python_version: strView implementation detect_os() → OperatingSystemView implementation get_platform_info() → PlatformInfoView implementation select_backend(preferred: AudioBackendType | None=None) → AudioBackendTypeView implementation