1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
158
159
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
//! STS per-domain load entry points, ported from
//! [`mlx_audio.sts.utils`][sts-utils].
//!
//! Faithful 1:1 of mlx-audio's two-tier shape:
//!
//! - [`load_model`] ([sts-utils.py:112-163][sts-utils-loadmodel]) — the
//! inner factory call mlx-audio funnels (post `_resolve_model_type`)
//! into `base_load_model(model_path=…, category="sts",
//! model_remapping=MODEL_REMAPPING, model_type=model_type, …)` plus
//! the Moshi `from_pretrained(...)` early-return.
//! - [`load`] ([sts-utils.py:166-173][sts-utils-load]) — the alias over
//! [`load_model`] (`return load_model(...)`). Mirrored for parity
//! with `from mlx_audio.sts import load`.
//!
//! mlx-audio's `MODEL_REMAPPING` table ([sts-utils.py:13-26][sts-utils-remap])
//! routes STS architecture aliases (`deepfilter`/`deepfilternet`/`deepfilternet3`
//! → `deepfilternet`; `lfm_audio`/`lfm2_audio`/`lfm2.5` → `lfm_audio`;
//! `moshi`/`moshiko` → `moshi`; `mossformer2`/`mossformer2_se` →
//! `mossformer2_se`; `sam_audio`/`samaudio` → `sam_audio`) into
//! `mlx_audio.sts.models.<arch>`; per the no-per-model-arch rule mlxrs
//! returns a [`Model`] trait object the per-architecture loader's
//! caller constructs, so the table is exposed in
//! [`MODEL_REMAPPING`] for reference but no arch crate is imported
//! here.
//!
//! [sts-utils]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py
//! [sts-utils-loadmodel]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L112-L163
//! [sts-utils-load]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L166-L173
//! [sts-utils-remap]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L13-L26
use crate::;
/// The mlx-audio `MODEL_REMAPPING` table for STS architectures
/// ([sts-utils.py:13-26][sts-utils-remap]) — `(alias,
/// canonical_module_name)` pairs.
///
/// **Reference-only**: per the no per-model arch porting
/// rule, mlxrs does NOT import per-architecture crates from this table.
///
/// [sts-utils-remap]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L13-L26
pub const MODEL_REMAPPING: & = &;
/// The trait every per-architecture STS model implements — the analogue
/// of mlx-audio's per-arch `Model.process(audio) -> Array` /
/// `SAMAudio.separate(audio) -> SeparationResult` /
/// DeepFilterNet's `enhance(audio) -> Array` shape.
///
/// Per the no per-model arch porting rule, mlxrs ships no
/// concrete STS models; this trait is the *shape* per-architecture
/// crates (lfm_audio / sam_audio / deepfilternet / mossformer2_se /
/// moshi) implement so a caller can hand-off any STS architecture as a
/// `Box<dyn Model>` from [`load`] / [`load_model`].
///
/// `process` is the unified entry point (mlx-audio uses different
/// method names per architecture — `enhance` for noise suppression,
/// `separate` for source separation, generic forward for end-to-end
/// speech models; mlxrs unifies on `process` since the trait's contract
/// is "speech in, speech out" regardless of the per-model term).
///
/// `&self` because weights are immutable after load.
///
/// Construct a [`Model`] from a local on-disk model directory —
/// faithful 1:1 of `mlx_audio.sts.utils.load_model`
/// ([sts-utils.py:112-163][sts-utils-loadmodel]).
///
/// Routes through the shared
/// [`crate::audio::load::base_load_model`] factory. The returned bundle
/// is handed to the caller-supplied `constructor` closure — per the
/// no per-model arch porting rule mlxrs does not bundle a
/// built-in registry / Moshi-special-case branch (the caller's
/// closure dispatches on `bundle.config_json` if it wants per-model
/// behavior).
///
/// `path` is the local on-disk path (a `hf://…` / `org/name` repo id
/// is rejected by [`crate::audio::load::get_model_path`] with a clear
/// no-network message).
///
/// Failures are typed: missing dir →
/// [`Error::MissingKey`](crate::error::Error::MissingKey), hub path →
/// [`Error::OutOfRange`](crate::error::Error::OutOfRange), malformed JSON →
/// [`Error::Parse`](crate::error::Error::Parse), constructor
/// error → caller-defined.
///
/// [sts-utils-loadmodel]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L112-L163
/// The **main entry point** for loading an STS model — faithful 1:1 of
/// `mlx_audio.sts.utils.load` ([sts-utils.py:166-173][sts-utils-load]).
/// Thin alias over [`load_model`].
///
/// [sts-utils-load]: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/sts/utils.py#L166-L173