fix: ios record on simulator - #158
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes iOS simulator recording issues by implementing a retry mechanism for audio tap installation, addressing format availability timing problems that commonly occur on iOS simulators.
- Refactored the audio tap installation to use a retry-based approach with proper error handling
- Added new instance variables to track retry state and prevent concurrent tap installations
- Moved audio engine startup to occur before tap installation to ensure proper format availability
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| package.json | Version bump from 2.1.5 to 2.1.6 |
| ios/Vosk.mm | Major refactoring of tap installation logic with retry mechanism and improved error handling |
| CHANGELOG.md | Added changelog entry for version 2.1.6 with multiple fixes and features |
| int dataLen = (int)(frames * sizeof(int16_t)); | ||
| accepted = vosk_recognizer_accept_waveform(recognizer, (const char *)pcm16.data(), (int32_t)dataLen); | ||
| } else { return; } | ||
| const char *cstr = NULL; BOOL isFinal = NO; if (accepted) { cstr = vosk_recognizer_result(recognizer); isFinal = YES; } else { cstr = vosk_recognizer_partial_result(recognizer); } |
There was a problem hiding this comment.
These lines contain extremely long single-line statements that are difficult to read and maintain. The original multi-line formatting should be preserved for better code readability and debugging.
| const char *cstr = NULL; BOOL isFinal = NO; if (accepted) { cstr = vosk_recognizer_result(recognizer); isFinal = YES; } else { cstr = vosk_recognizer_partial_result(recognizer); } | |
| const char *cstr = NULL; | |
| BOOL isFinal = NO; | |
| if (accepted) { | |
| cstr = vosk_recognizer_result(recognizer); | |
| isFinal = YES; | |
| } else { | |
| cstr = vosk_recognizer_partial_result(recognizer); | |
| } |
| } else { return; } | ||
| const char *cstr = NULL; BOOL isFinal = NO; if (accepted) { cstr = vosk_recognizer_result(recognizer); isFinal = YES; } else { cstr = vosk_recognizer_partial_result(recognizer); } | ||
| NSString *json = cstr ? [NSString stringWithUTF8String:cstr] : nil; | ||
| dispatch_async(dispatch_get_main_queue(), ^{ if (!json) return; NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *parsed = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil; if (![parsed isKindOfClass:[NSDictionary class]]) { if (isFinal) { [self emitOnResult:json]; } else { [self emitOnPartialResult:json]; } return; } NSString *text = parsed[@"text"]; NSString *partial = parsed[@"partial"]; if (isFinal) { if (text.length > 0) { [self emitOnResult:text]; } self->_lastPartial = nil; } else { if (partial.length > 0 && (!self->_lastPartial || ![self->_lastPartial isEqualToString:partial])) { [self emitOnPartialResult:partial]; } self->_lastPartial = partial ?: self->_lastPartial; } }); |
There was a problem hiding this comment.
These lines contain extremely long single-line statements that are difficult to read and maintain. The original multi-line formatting should be preserved for better code readability and debugging.
| dispatch_async(dispatch_get_main_queue(), ^{ if (!json) return; NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *parsed = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil; if (![parsed isKindOfClass:[NSDictionary class]]) { if (isFinal) { [self emitOnResult:json]; } else { [self emitOnPartialResult:json]; } return; } NSString *text = parsed[@"text"]; NSString *partial = parsed[@"partial"]; if (isFinal) { if (text.length > 0) { [self emitOnResult:text]; } self->_lastPartial = nil; } else { if (partial.length > 0 && (!self->_lastPartial || ![self->_lastPartial isEqualToString:partial])) { [self emitOnPartialResult:partial]; } self->_lastPartial = partial ?: self->_lastPartial; } }); | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| if (!json) return; | |
| NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding]; | |
| NSDictionary *parsed = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil; | |
| if (![parsed isKindOfClass:[NSDictionary class]]) { | |
| if (isFinal) { | |
| [self emitOnResult:json]; | |
| } else { | |
| [self emitOnPartialResult:json]; | |
| } | |
| return; | |
| } | |
| NSString *text = parsed[@"text"]; | |
| NSString *partial = parsed[@"partial"]; | |
| if (isFinal) { | |
| if (text.length > 0) { | |
| [self emitOnResult:text]; | |
| } | |
| self->_lastPartial = nil; | |
| } else { | |
| if (partial.length > 0 && (!self->_lastPartial || ![self->_lastPartial isEqualToString:partial])) { | |
| [self emitOnPartialResult:partial]; | |
| } | |
| self->_lastPartial = partial ?: self->_lastPartial; | |
| } | |
| }); |
No description provided.