bleed API
maai.bleed
Speaker-bleed removal for two face-to-face lapel microphones.
When two people talk face to face with lapel mics, each mic also picks up the partner's voice. This package removes that bleed with an AEC-style approach that uses the partner's mic as the reference (2-pass linear AEC + residual suppression v2), so the near-end voice is kept even during overlapping speech.
Real-time
- :class:
BleedCanceller/ :class:StreamProcessor(low level) maai.input.BleedCancelwraps any MaaiInput source(s) (recommended)
Offline (recorded files):
- :func:process_pair for numpy arrays, :func:process_files for WAV files
maai.bleed.realtime.engine
Real-time 2ch (two lapel mics) speaker-bleed canceller.
core processor working on block samples at 16 kHz
(bidirectional x 2-pass linear AEC + residual suppression v2)
StreamProcessor : wrapper accepting any sample rate / chunk length (resampling, HPF, blocking)
Signal flow (side A; side B is symmetric): A mic --delay m--> AEC1(ref = B mic) -> e_A1 --+ (reference of B's 2nd pass) A mic --delay 2m-> AEC2(ref = e_B1) -> AES -> A out m = margin (default 32 samples = 2 ms). The mic is delayed slightly relative to the reference so that a causal filter can model the bleed even if the two input paths differ a little in delay. Algorithmic latency: passes * margin + AES latency = 64 + (nfft - hop) + look-ahead = 64 + 384 + 0 samples = 28 ms at 16 kHz (no look-ahead by default).
BleedCanceller
Core real-time bleed canceller for two synchronized 16 kHz channels.
Keyword arguments override :data:DEFAULTS. Call :meth:process with block samples
per channel; the output is delayed by :attr:latency samples.
Source code in src/maai/bleed/realtime/engine.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
process(a, b)
a, b: 16 kHz signals of length block. Returns (a_out, b_out), delayed by latency samples.
Source code in src/maai/bleed/realtime/engine.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
status()
Return a dict describing the current adaptation state (for monitoring).
Source code in src/maai/bleed/realtime/engine.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
StreamProcessor
Process 2ch chunks of any sample rate and length.
push(x): x is a float array of shape (n, 2) at sr_in. Returns the processed (m, 2) at
out_sr (m varies because samples are buffered up to block boundaries).
Source code in src/maai/bleed/realtime/engine.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
latency_ms()
Algorithmic latency incl. block buffering and resampler group delay (excl. device buffers).
Source code in src/maai/bleed/realtime/engine.py
199 200 201 202 203 204 205 206 207 | |
VariableDelay
Delay line whose delay can change on the fly (up to max_delay).
Source code in src/maai/bleed/realtime/engine.py
63 64 65 66 67 68 69 70 71 72 73 74 | |
maai.bleed.offline.pipeline
Offline bleed removal for one recorded session (two lapel mics).
mic A --+
+- delay estimation -> reference alignment -> linear AEC (PBFDAF) -> residual suppression -> A cleaned
mic B --+ (reference)
Side B is processed symmetrically with A as the reference.
aes_stage(mic, res, ref_al, p, log)
Residual suppression. Returns (output, output without comfort noise).
Source code in src/maai/bleed/offline/pipeline.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
linear_stage(mic, ref, delay, clock_drift, p, log)
Linear AEC. Returns (pbfdaf result dict, aligned reference).
Source code in src/maai/bleed/offline/pipeline.py
60 61 62 63 64 65 66 67 68 69 | |
process_files(s1=None, s2=None, stereo=None, out_dir='.', prefix=None, **params)
Apply offline bleed removal to recorded files and write the results.
Give either two mono files (s1, s2) or one stereo file (stereo, L=s1, R=s2).
Writes {prefix}_s1.wav, {prefix}_s2.wav, {prefix}_stereo.wav (16 kHz, PCM16)
and {prefix}_bleed_log.json into out_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s1
|
str
|
Mono WAV of speaker 1's mic. |
None
|
s2
|
str
|
Mono WAV of speaker 2's mic. |
None
|
stereo
|
str
|
Stereo WAV (L = speaker 1, R = speaker 2). |
None
|
out_dir
|
str
|
Output directory. |
'.'
|
prefix
|
str
|
Output file prefix (defaults to the input file name). |
None
|
**params
|
Overrides of :data: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Paths of the written files (keys: s1, s2, stereo, log). |
Source code in src/maai/bleed/offline/pipeline.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | |
process_pair(a, b, sr_in, **kw)
Remove the mutual bleed between two synchronized lapel-mic recordings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
ndarray
|
Mono signal of speaker 1's mic. |
required |
b
|
ndarray
|
Mono signal of speaker 2's mic (same clock / start as |
required |
sr_in
|
int
|
Sample rate of |
required |
**kw
|
Overrides of :data: |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(a_clean, b_clean, log). The outputs are float32 at |
Source code in src/maai/bleed/offline/pipeline.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |