跳轉到

API 參考

這一頁的每個名稱都直接來自 import kudio:呼叫的是 kudio.file_load,不是 kudio.core.io.file_load。後面幾頁依模組記載同樣這些名稱,附上完整的簽名、每個參數,以及 docstring 裡的範例。API 的說明取自程式碼裡的 docstring,所以維持英文。

音訊檔案

完整說明在音訊檔案。

名稱 種類 用途(取自 docstring)
audio_info 函式 Describe an audio file (or an in-memory waveform) without interpreting it.
AudioDataManager 類別 Keyed store of audio clips: {name: {dir, wave, sr, ch}}.
AudioInfo 類別 What a file is, before you decide whether to load it.
check_file 函式 Normalize an output wave path: force the .wav suffix, create parent directories, and (optionally) rename to avoid overwriting an existing file.
check_input 函式 Recursively collect .wav files from input.
check_path 函式 Return path if it is free (or exist_ok), otherwise an incremented variant, e.g.
convert_folder 函式 Resample / re-encode / trim / normalise every .wav file under src.
ConvertResult 類別 What convert_folder did.
copy_waves 函式 Copy wave files into directory path and return where they went.
file_load 函式 Load a wave file;
load_wave 函式 Load one wave file or a list of them into (waveform, sr) tuples.
load_waves 函式 Convert every .wav in wave (see check_input) to waveform data.
LoadAudio 類別 Iterate over the .wav files found (recursively) in a directory, collected the way check_input collects them.
resample 函式 Resample a waveform already in memory.
save_wave 函式 Write wave to an audio file via soundfile.

STFT 與特徵

完整說明在STFT 與特徵。

名稱 種類 用途(取自 docstring)
ContextFrames 類別 stack_context over a whole corpus, stacked a batch at a time.
denoise_spec2wav 函式 Inverse of denoise_wav2spec;
denoise_wav2spec 函式 Peak-normalized magnitude spectrogram + phase, for denoising models.
features2matrix 函式 Concatenate feature matrices;
file_to_spectrogram 函式 File -> log-power spectrogram (see waveform_to_spectrogram).
frame_windows 函式 Cut a feature matrix into fixed-length windows.
logspec_from_files 函式 Convert each file to a log spectrogram and stack them.
melspectrogram 函式 Audio -> stacked log-mel feature vectors (n_vectors, n_mels * n_frames).
mfcc 函式 Waveform -> MFCC, shaped (1, n_frames, n_mfcc).
mfcc_from_files 函式 Load each wave file and stack their MFCC matrices (n_files, frames, n_mfcc).
save_spectrogram_as_wave 函式 Reconstruct a waveform from enhanced_spec (phase from noisy_file) and write it to wave_out_dir as 16-bit PCM, clipped at full scale.
spectrogram_to_waveform 函式 Log-power spectrogram -> waveform, reusing the phase of reference y.
SpectrogramStream 類別 A rolling log-magnitude spectrogram, one column per hop.
stack_context 函式 Stack ±context neighbouring frames onto each frame.
Standardizer 類別 Per-column mean/std normalisation, with the statistics saved alongside.
STFT 類別 Immutable STFT settings, with the two transforms attached.
wave_separate 函式 Split an interleaved multi-channel waveform into per-channel arrays.
wave_slicing 函式 Slice a waveform into overlapping frames (flattened if is_reshape).
waveform_to_spectrogram 函式 Waveform -> log-power spectrogram (frames, bins), log10(\|X\|^2).

檢查

完整說明在檢查。

名稱 種類 用途(取自 docstring)
audio_report 函式 Inspect y without needing a clean reference to compare it against.
AudioReport 類別 Reference-free measurements of one clip.
dnsmos 函式 Predict P.835 opinion scores for y.
DnsmosScore 類別 Three P.835 opinion scores, each on the 1–5 MOS scale.
find_dnsmos_model 函式 Locate sig_bak_ovr.onnx.
loudness 函式 Gated integrated loudness of y, in LUFS.
loudness_over_time 函式 Loudness measured over a sliding window -- where a take drifted.
loudness_range 函式 Loudness range in LU, to EBU Tech 3342.
LoudnessCurve 類別 Loudness measured over a sliding window, in LUFS.
match_loudness 函式 Scale y until it is as loud as reference.
MOMENTARY 常數 Convert a string or number to a floating-point number, if possible.
normalize_lufs 函式 Scale y to lufs integrated loudness.
SHORT_TERM 常數 Convert a string or number to a floating-point number, if possible.
true_peak 函式 Peak of the reconstructed waveform, in dBTP (BS.1770-4 Annex 2).

語音活動與音高

完整說明在語音活動與音高。

名稱 種類 用途(取自 docstring)
f0 函式 Track the fundamental frequency of y with pYIN.
PitchTrack 類別 A pitch contour plus the voicing decision that makes it readable.
speech_ratio 函式 Fraction of the clip that vad calls speech, in [0, 1].
vad 函式 Find the spans of y that contain speech, in seconds.
vad_frames 函式 vad as one decision per STFT frame, True for speech.
vad_split 函式 The speech segments themselves, as waveforms.
vad_trim 函式 Trim to the first and last speech, keeping whatever is between them.

編輯與效果

完整說明在編輯與效果。

名稱 種類 用途(取自 docstring)
add_noise_snr 函式 Mix noise into y at the target signal-to-noise ratio (dB).
band_filter 函式 Butterworth filter of any of the four kinds.
bandpass 函式 Keep only low..high Hz.
bandstop 函式 Remove low..high Hz.
crossfade 函式 Join two clips through a short overlap, instead of butting them together.
DEFAULT_CROSSFADE 常數 Convert a string or number to a floating-point number, if possible.
fade 函式 Fade both ends in one call.
fade_in 函式 Ramp the first duration seconds up from silence.
fade_out 函式 Ramp the last duration seconds down to silence.
gain 函式 Apply a fixed gain in decibels.
highpass 函式 Remove everything below cutoff Hz — rumble, handling noise, DC drift.
lowpass 函式 Remove everything above cutoff Hz — hiss, and anything past the band a downstream model was trained on.
normalize 函式 Scale so the loudest sample sits at peak.
normalize_db 函式 Scale so the peak sits at dbfs decibels below full scale.
pitch_shift 函式 Shift pitch by n_steps semitones without changing duration.
random_gain 函式 Apply a random gain sampled uniformly from db_range dB.
remove_dc 函式 Subtract the mean, per channel.
reverb 函式 Cheap synthetic reverb via an exponentially-decaying comb filter: an echo every delay_ms, each decay times the one before.
reverse 函式 Play the waveform backwards.
spec_augment 函式 SpecAugment: mask random frequency bands and time spans of a spectrogram.
splice 函式 Join several clips end to end, crossfading every seam.
split_on_silence 函式 Split y into non-silent segments (each below-top_db gap is a cut).
time_stretch 函式 Speed up (rate>1) or slow down (rate<1) without changing pitch.
trim_silence 函式 Trim leading/trailing silence below top_db dB under peak.

房間與通道

完整說明在房間與通道。

名稱 種類 用途(取自 docstring)
a_law 函式 The same, through the A-law curve -- G.711 as Europe specifies it.
A_LAW_A 常數 Convert a string or number to a floating-point number, if possible.
apply_channel 函式 Run y through a whole link in the order a link does it.
apply_rir 函式 Put y in the room described by ir.
bit_depth 函式 Requantise y to bits, linearly.
CHANNEL_DEFAULTS 常數 dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.
CHANNEL_PRESETS 常數 dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.
channel_spec 函式 Normalise spec -- a preset name, a dict, or None -- to a dict.
channel_tag 函式 A short, stable description of spec, for a manifest or a filename.
dropouts 函式 Drop packets, the way a bad link does.
independent_burst 函式 The mean run length that independent loss at rate loss produces.
mu_law 函式 Push y through the G.711 mu-law companding curve and back.
MU_LAW_MU 常數 Convert a string or number to a floating-point number, if possible.
PACKET_MS 常數 Convert a string or number to a floating-point number, if possible.
Reverberation 類別 What a room does, measured from its impulse response.
rir 函式 A synthetic room impulse response: exponentially decaying noise.
rt60 函式 Measure a room from its impulse response, to ISO 3382-1.
schroeder_curve 函式 Backward-integrated energy decay of ir, in dB, starting at 0.
telephone 函式 Everything a phone line does, in the order it does it.
TELEPHONE_BAND 常數 Built-in immutable sequence.

資料集

完整說明在資料集。

名稱 種類 用途(取自 docstring)
Label 類別 A named span of a recording, in seconds.
load_labels 函式 Read labels written by save_labels, or by Audacity.
load_manifest 函式 Read a manifest written by save_manifest.
Pair 類別 One training example: a degraded file and the clean signal behind it.
save_labels 函式 Write labels as JSON, or as an Audacity label track.
save_manifest 函式 Write pairs to path as JSON.
split_pairs 函式 Shuffle once, then cut into (train, validation, test).
Synthesizer 類別 Mix clean audio with noise at the requested SNRs.

增強

完整說明在增強。

名稱 種類 用途(取自 docstring)
compare_enhancers 函式 Run several methods over the same clip and measure each one.
CUSTOM_NOISE 常數 str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
CustomEnhancer 類別 Anything that denoises, wrapped so it can be ranked with the rest.
DecisionDirected 類別 The a priori SNR estimator of Ephraim & Malah, as state plus an update.
enhance_folder 函式 Denoise every .wav file under src into dst.
EnhanceFolderResult 類別 What enhance_folder did.
EnhanceResult 類別 One run's output, with everything needed to rank it against another.
estimate_noise_psd 函式 Noise power spectrum for every frame of power (frames, bins).
make_gain_rule 函式 The per-frame gain function for one of RECURSIVE_METHODS.
make_noise_tracker 函式 A stateful tracker for method.
Method 類別 An enhancement method: what it is, and what it lets you turn.
METHODS 常數 dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.
NOISE_ESTIMATORS 常數 dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list.
NoiseTracker 類別 A noise estimator as state plus one update, not a whole-file pass.
Param 類別 One tunable knob, described well enough to build a control from it.
RECURSIVE_METHODS 常數 Built-in immutable sequence.
spectral_enhance 函式 Enhance y with one of the methods in METHODS.
STREAMABLE_METHODS 常數 Built-in immutable sequence.
StreamEnhancer 類別 Denoise a stream block by block, with a one-frame delay.
trad_enhance 函式 Enhance waveform y using spectral subtraction with MCRA noise estimation and a Wiener-style gain function.
wavelet_low_pass_filter 函式 Soft-threshold the detail coefficients of a wavelet decomposition.

指標與對齊

完整說明在指標與對齊。

名稱 種類 用途(取自 docstring)
align 函式 Return ref and deg trimmed to the region they share, lined up.
Alignment 類別 Where two recordings sit relative to each other.
AudioEvaluate 類別 Evaluate enhanced audio against clean references.
check_metrics_install 函式 Report availability of the optional metric back-ends.
eval_metrics 函式 Score a single (reference, degraded) pair with every available metric.
find_delay 函式 Measure how far deg sits after ref, to the nearest sample.
MIN_CORRELATION 常數 Convert a string or number to a floating-point number, if possible.
pesq 函式 PESQ of deg against ref (ITU-T P.862 / P.862.2).
score 函式 Score deg against ref: {metric: value}.
sdi 函式 Speech distortion index: sum((ref - deg)**2) / sum(ref**2).
segmental_snr 函式 Frame-averaged (segmental) SNR in dB, clipped to [-10, 35] per frame.
si_sdr 函式 Scale-invariant SDR (dB) — immune to overall gain differences.
snr 函式 Signal-to-noise ratio (dB) of deg relative to ref (pure numpy).

即時音訊

完整說明在即時音訊。

名稱 種類 用途(取自 docstring)
AudioBuffer 類別 Bounded FIFO of audio frames shared between producer/consumer threads.
check_device 函式 List system devices and probe an input;
CheckDevice 類別 Query/validate PortAudio devices.
FetchBuffer 類別 Collect a fixed number of frames from an AudioBuffer in a background thread.
is_available 函式 Smoke-test the terminal colors and the audio input stack.
list_devices 函式 Devices as sounddevice sees them.
LocalStreamReader 類別 Stream from a local microphone into an AudioBuffer, with optional live monitoring through the default output device.
PA_FLOAT32 常數 int([x]) -> integer int(x, base=10) -> integer
PA_INT16 常數 int([x]) -> integer int(x, base=10) -> integer
play_audio 函式 Play audio from a file path, an opened wave.Wave_read, or an ndarray.
record 函式 Blocking record for seconds via sounddevice (modern backend).
Recorder 類別 Blocking recorder for a fixed duration.
RemoteStreamReader 類別 Receive an audio stream over TCP and feed it into an AudioBuffer (optionally playing it back locally).
StreamRecorder 類別 Record for as long as you like, and watch the level while it happens.
wave_decode 函式 Raw int16 bytes -> array of shape (chunk_length, channels).
wave_encode 函式 Multi-channel array -> interleaved int16 bytes.

設定與錯誤

完整說明在設定與錯誤。

名稱 種類 用途(取自 docstring)
AudioIOError 類別 Reading or writing an audio file failed.
DependencyError 類別 An optional dependency is required for this operation but not installed.
DeviceError 類別 An audio input/output device could not be opened or configured.
FeatureError 類別 A feature, effect, room, channel or enhancement step refused its input or its settings: the wrong shape of audio, a parameter out of range, a clip too short to frame.
KC 類別 Attribute-style config with YAML load/save and audio-centric defaults.
KudioConfig 類別 Attribute-style config with YAML load/save and audio-centric defaults.
KudioError 類別 Base class for every error raised by kudio.
SynthesisError 類別 Noisy-data synthesis failed.
UnsupportedFormatError 類別 The file type / dtype is not supported.

工具

完整說明在工具。

名稱 種類 用途(取自 docstring)
find_duplicate 函式 Return the Counter dict of file_list, logging duplicated entries.
lowercase 函式 The strings in lst, lower-cased.
map_waves 函式 Apply fn to every item, optionally across workers processes.
Timer 類別 Decorator: run func in a daemon thread, optionally joining for at most time_delay seconds.
timer 函式 Decorator: log the wall-clock run time of func.
uppercase 函式 The strings in lst, upper-cased.

舊名稱

這些名稱還能匯入,但每次呼叫都會發出警告,並指出新名稱。之後的版本會把它們移除。

舊名稱 新名稱
blu kudio.util.blu
color_test kudio.util.color_test
concat_logspec logspec_from_files
concat_logspec_ logspec_from_files
concat_mfcc mfcc_from_files
concat_mfcc_ mfcc_from_files
contextual_LogSpectrogram logspec_from_files
cya kudio.util.cya
dkblu kudio.util.dkblu
dkcya kudio.util.dkcya
dkgre kudio.util.dkgre
dkpur kudio.util.dkpur
dkred kudio.util.dkred
dkyel kudio.util.dkyel
error kudio.util.error
f2s file_to_spectrogram
fGre kudio.util.fGre
fRed kudio.util.fRed
gre kudio.util.gre
h1 kudio.util.h1
info kudio.util.info
pur kudio.util.pur
red kudio.util.red
s2w save_spectrogram_as_wave
spec2wav save_spectrogram_as_wave
spec2wavform spectrogram_to_waveform
upercase uppercase
w2mfcc mfcc
w2s waveform_to_spectrogram
warn kudio.util.warn
wav2mel melspectrogram
wav2mfcc mfcc
wav2spec file_to_spectrogram
wavform2spec waveform_to_spectrogram
yel kudio.util.yel