Commit c050c22
authored
fix(ios-sdk): propagate STTOptions.language to ONNX decoder via withCString (#404)
* fix(ios-sdk): propagate STTOptions.language to C bridge via withCString
STTOptions.language was silently ignored during transcription, causing
the Whisper ONNX decoder to always default to English regardless of
the language passed by the caller.
Root causes:
- Dangling pointer: (options.language as NSString).utf8String stored a
pointer into a temporary NSString. ARC released it after the
assignment, leaving cOptions.language pointing to freed memory before
the C call. The backend read garbage and fell back to 'en'.
- Incomplete mapping: only language and sample_rate were forwarded to
rac_stt_options_t. detect_language, enable_punctuation,
enable_diarization, enable_timestamps, audio_format, and max_speakers
were silently zero-initialized regardless of caller input.
- processStreamingAudio never set a language field at all.
Fix: add a private STTOptions.withCOptions<T> helper that uses
withCString to guarantee pointer validity for the full duration of the
C call and maps all fields in one place. Apply it to
transcribeWithOptions, transcribeStream, and processStreamingAudio.
Fixes #350
* refactor(ios-sdk): remove duplicate withCOptions, use existing STTTypes.swift impl
The private withCOptions extension in RunAnywhere+STT.swift duplicated
the public STTOptions.withCOptions already defined in STTTypes.swift:127.
Both used withCString for pointer safety and mapped all rac_stt_options_t
fields identically.
Remove the duplicate and update the three call sites to use the public
method's UnsafePointer signature (cOptionsPtr instead of &cOptions).
* fix(ios-sdk): address review comments on processStreamingAudio and STTStreamingContext
- Change processStreamingAudio signature from language: String to
options: STTOptions = STTOptions() so detectLanguage and all other
fields are preserved, matching transcribeWithOptions/transcribeStream
- Add missing isLoaded guard to processStreamingAudio before getHandle(),
surfacing an actionable notInitialized error instead of processingFailed
- Add clarifying comment on sttResult in processStreamingAudio: value is
intentionally unused as the C layer delivers results via CppEventBridge
- Fix STTStreamingContext data race: replace @unchecked Sendable + bare var
with OSAllocatedUnfairLock-protected finalText so C callback writes and
async continuation reads are properly synchronised
* fix(ios-sdk): address final review comments on STTStreamingContext and guard order
- Mark onPartialResult as @sendable so STTStreamingContext's explicit
Sendable conformance is sound; a non-@sendable stored closure makes
the conformance unsound under Swift's strict concurrency checking
- Swap guard order in processStreamingAudio to match transcribeWithOptions
and transcribeStream: getHandle() first, then isLoaded check1 parent e621246 commit c050c22
1 file changed
Lines changed: 71 additions & 65 deletions
Lines changed: 71 additions & 65 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | 81 | | |
86 | 82 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
95 | 93 | | |
96 | 94 | | |
97 | 95 | | |
| |||
213 | 211 | | |
214 | 212 | | |
215 | 213 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | 214 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
249 | 244 | | |
250 | 245 | | |
251 | 246 | | |
| |||
276 | 271 | | |
277 | 272 | | |
278 | 273 | | |
279 | | - | |
280 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
281 | 278 | | |
282 | 279 | | |
283 | 280 | | |
284 | 281 | | |
285 | 282 | | |
286 | 283 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
| 284 | + | |
| 285 | + | |
292 | 286 | | |
293 | 287 | | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
294 | 291 | | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
303 | 302 | | |
304 | 303 | | |
305 | 304 | | |
| |||
325 | 324 | | |
326 | 325 | | |
327 | 326 | | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
332 | 338 | | |
333 | | - | |
| 339 | + | |
334 | 340 | | |
335 | 341 | | |
336 | 342 | | |
0 commit comments