|
10 | 10 | # AsrResponseFormat, |
11 | 11 | # ApiAsrOptions, |
12 | 12 | InferenceAsrFramework, |
13 | | - InlineAsrNativeWhisperOptions, |
14 | 13 | InlineAsrMlxWhisperOptions, |
| 14 | + InlineAsrNativeWhisperOptions, |
15 | 15 | TransformersModelType, |
16 | 16 | ) |
17 | 17 |
|
18 | 18 | _log = logging.getLogger(__name__) |
19 | 19 |
|
| 20 | + |
20 | 21 | def _get_whisper_tiny_model(): |
21 | 22 | """ |
22 | 23 | Get the best Whisper Tiny model for the current hardware. |
23 | | - |
| 24 | +
|
24 | 25 | Automatically selects MLX Whisper Tiny for Apple Silicon (MPS) if available, |
25 | 26 | otherwise falls back to native Whisper Tiny. |
26 | 27 | """ |
27 | 28 | # Check if MPS is available (Apple Silicon) |
28 | 29 | try: |
29 | 30 | import torch |
| 31 | + |
30 | 32 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
31 | 33 | except ImportError: |
32 | 34 | has_mps = False |
33 | | - |
| 35 | + |
34 | 36 | # Check if mlx-whisper is available |
35 | 37 | try: |
36 | 38 | import mlx_whisper # type: ignore |
| 39 | + |
37 | 40 | has_mlx_whisper = True |
38 | 41 | except ImportError: |
39 | 42 | has_mlx_whisper = False |
40 | | - |
| 43 | + |
41 | 44 | # Use MLX Whisper if both MPS and mlx-whisper are available |
42 | 45 | if has_mps and has_mlx_whisper: |
43 | 46 | return InlineAsrMlxWhisperOptions( |
@@ -66,27 +69,30 @@ def _get_whisper_tiny_model(): |
66 | 69 | # Create the model instance |
67 | 70 | WHISPER_TINY = _get_whisper_tiny_model() |
68 | 71 |
|
| 72 | + |
69 | 73 | def _get_whisper_small_model(): |
70 | 74 | """ |
71 | 75 | Get the best Whisper Small model for the current hardware. |
72 | | - |
| 76 | +
|
73 | 77 | Automatically selects MLX Whisper Small for Apple Silicon (MPS) if available, |
74 | 78 | otherwise falls back to native Whisper Small. |
75 | 79 | """ |
76 | 80 | # Check if MPS is available (Apple Silicon) |
77 | 81 | try: |
78 | 82 | import torch |
| 83 | + |
79 | 84 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
80 | 85 | except ImportError: |
81 | 86 | has_mps = False |
82 | | - |
| 87 | + |
83 | 88 | # Check if mlx-whisper is available |
84 | 89 | try: |
85 | 90 | import mlx_whisper # type: ignore |
| 91 | + |
86 | 92 | has_mlx_whisper = True |
87 | 93 | except ImportError: |
88 | 94 | has_mlx_whisper = False |
89 | | - |
| 95 | + |
90 | 96 | # Use MLX Whisper if both MPS and mlx-whisper are available |
91 | 97 | if has_mps and has_mlx_whisper: |
92 | 98 | return InlineAsrMlxWhisperOptions( |
@@ -115,27 +121,30 @@ def _get_whisper_small_model(): |
115 | 121 | # Create the model instance |
116 | 122 | WHISPER_SMALL = _get_whisper_small_model() |
117 | 123 |
|
| 124 | + |
118 | 125 | def _get_whisper_medium_model(): |
119 | 126 | """ |
120 | 127 | Get the best Whisper Medium model for the current hardware. |
121 | | - |
| 128 | +
|
122 | 129 | Automatically selects MLX Whisper Medium for Apple Silicon (MPS) if available, |
123 | 130 | otherwise falls back to native Whisper Medium. |
124 | 131 | """ |
125 | 132 | # Check if MPS is available (Apple Silicon) |
126 | 133 | try: |
127 | 134 | import torch |
| 135 | + |
128 | 136 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
129 | 137 | except ImportError: |
130 | 138 | has_mps = False |
131 | | - |
| 139 | + |
132 | 140 | # Check if mlx-whisper is available |
133 | 141 | try: |
134 | 142 | import mlx_whisper # type: ignore |
| 143 | + |
135 | 144 | has_mlx_whisper = True |
136 | 145 | except ImportError: |
137 | 146 | has_mlx_whisper = False |
138 | | - |
| 147 | + |
139 | 148 | # Use MLX Whisper if both MPS and mlx-whisper are available |
140 | 149 | if has_mps and has_mlx_whisper: |
141 | 150 | return InlineAsrMlxWhisperOptions( |
@@ -164,27 +173,30 @@ def _get_whisper_medium_model(): |
164 | 173 | # Create the model instance |
165 | 174 | WHISPER_MEDIUM = _get_whisper_medium_model() |
166 | 175 |
|
| 176 | + |
167 | 177 | def _get_whisper_base_model(): |
168 | 178 | """ |
169 | 179 | Get the best Whisper Base model for the current hardware. |
170 | | - |
| 180 | +
|
171 | 181 | Automatically selects MLX Whisper Base for Apple Silicon (MPS) if available, |
172 | 182 | otherwise falls back to native Whisper Base. |
173 | 183 | """ |
174 | 184 | # Check if MPS is available (Apple Silicon) |
175 | 185 | try: |
176 | 186 | import torch |
| 187 | + |
177 | 188 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
178 | 189 | except ImportError: |
179 | 190 | has_mps = False |
180 | | - |
| 191 | + |
181 | 192 | # Check if mlx-whisper is available |
182 | 193 | try: |
183 | 194 | import mlx_whisper # type: ignore |
| 195 | + |
184 | 196 | has_mlx_whisper = True |
185 | 197 | except ImportError: |
186 | 198 | has_mlx_whisper = False |
187 | | - |
| 199 | + |
188 | 200 | # Use MLX Whisper if both MPS and mlx-whisper are available |
189 | 201 | if has_mps and has_mlx_whisper: |
190 | 202 | return InlineAsrMlxWhisperOptions( |
@@ -213,27 +225,30 @@ def _get_whisper_base_model(): |
213 | 225 | # Create the model instance |
214 | 226 | WHISPER_BASE = _get_whisper_base_model() |
215 | 227 |
|
| 228 | + |
216 | 229 | def _get_whisper_large_model(): |
217 | 230 | """ |
218 | 231 | Get the best Whisper Large model for the current hardware. |
219 | | - |
| 232 | +
|
220 | 233 | Automatically selects MLX Whisper Large for Apple Silicon (MPS) if available, |
221 | 234 | otherwise falls back to native Whisper Large. |
222 | 235 | """ |
223 | 236 | # Check if MPS is available (Apple Silicon) |
224 | 237 | try: |
225 | 238 | import torch |
| 239 | + |
226 | 240 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
227 | 241 | except ImportError: |
228 | 242 | has_mps = False |
229 | | - |
| 243 | + |
230 | 244 | # Check if mlx-whisper is available |
231 | 245 | try: |
232 | 246 | import mlx_whisper # type: ignore |
| 247 | + |
233 | 248 | has_mlx_whisper = True |
234 | 249 | except ImportError: |
235 | 250 | has_mlx_whisper = False |
236 | | - |
| 251 | + |
237 | 252 | # Use MLX Whisper if both MPS and mlx-whisper are available |
238 | 253 | if has_mps and has_mlx_whisper: |
239 | 254 | return InlineAsrMlxWhisperOptions( |
@@ -262,27 +277,30 @@ def _get_whisper_large_model(): |
262 | 277 | # Create the model instance |
263 | 278 | WHISPER_LARGE = _get_whisper_large_model() |
264 | 279 |
|
| 280 | + |
265 | 281 | def _get_whisper_turbo_model(): |
266 | 282 | """ |
267 | 283 | Get the best Whisper Turbo model for the current hardware. |
268 | | - |
| 284 | +
|
269 | 285 | Automatically selects MLX Whisper Turbo for Apple Silicon (MPS) if available, |
270 | 286 | otherwise falls back to native Whisper Turbo. |
271 | 287 | """ |
272 | 288 | # Check if MPS is available (Apple Silicon) |
273 | 289 | try: |
274 | 290 | import torch |
| 291 | + |
275 | 292 | has_mps = torch.backends.mps.is_built() and torch.backends.mps.is_available() |
276 | 293 | except ImportError: |
277 | 294 | has_mps = False |
278 | | - |
| 295 | + |
279 | 296 | # Check if mlx-whisper is available |
280 | 297 | try: |
281 | 298 | import mlx_whisper # type: ignore |
| 299 | + |
282 | 300 | has_mlx_whisper = True |
283 | 301 | except ImportError: |
284 | 302 | has_mlx_whisper = False |
285 | | - |
| 303 | + |
286 | 304 | # Use MLX Whisper if both MPS and mlx-whisper are available |
287 | 305 | if has_mps and has_mlx_whisper: |
288 | 306 | return InlineAsrMlxWhisperOptions( |
|
0 commit comments