Skip to content

Commit

Permalink
No idea what I was working on here, left uncommited. Throwing into a …
Browse files Browse the repository at this point in the history
…branch for next time I work on "Listen"
  • Loading branch information
scosman committed Dec 10, 2023
1 parent b7ea512 commit 09243b8
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 10 deletions.
1 change: 1 addition & 0 deletions ios/voicebox/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#define ACTION_BUTTON_UICOLOR [UIColor colorWithRed:0.4 green:0.502 blue:0.694 alpha:1.0]
#define ACTION_BUTTON_HIGHLIGHT_UICOLOR [UIColor colorWithRed:0.32 green:0.402 blue:0.555 alpha:1.0]
#define ACTION_BUTTON_DISABLED_UICOLOR [[UIColor systemGray4Color] colorWithAlphaComponent:0.6]
#define KEYBOARD_BUTTON_UICOLOR [UIColor colorWithRed:0.6 green:0.702 blue:0.894 alpha:1.0]

#define OPEN_AI_API_TIMEOUT_SECONDS 12.0

Expand Down
50 changes: 45 additions & 5 deletions ios/voicebox/UI/ListenViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface ListenViewController () <VBAudioListenerDelegate>
@property (nonatomic, weak) UILabel *loadingLabel, *transcriptLabel;
@property (nonatomic, weak) UIActivityIndicatorView* spinner;
@property (nonatomic, weak) UIButton* closeBtn;
@property (nonatomic, strong) NSArray<NSString*>* priorSegments;

@end

Expand All @@ -41,7 +42,7 @@ - (void)viewDidLoad

UILabel* transcriptLabel = [[UILabel alloc] init];
transcriptLabel.text = @"";
transcriptLabel.font = [UIFont systemFontOfSize:MAX(22.0, [UIFont labelFontSize])];
transcriptLabel.font = [UIFont systemFontOfSize:MAX(16.0, [UIFont labelFontSize])];
transcriptLabel.textColor = [UIColor systemGrayColor];
transcriptLabel.translatesAutoresizingMaskIntoConstraints = NO;
transcriptLabel.lineBreakMode = NSLineBreakByWordWrapping;
Expand Down Expand Up @@ -119,11 +120,50 @@ - (void)stateUpdate:(bool)running segments:(NSArray<NSString*>*)segments
weakself.loadingLabel.text = @"Listening...";

if (segments) {
NSString* transcript = @"";
for (NSString* segment in segments) {
transcript = [transcript stringByAppendingString:segment];
NSString* liveContent = @"";
NSString* readyToProcess = @"";
/*
NSString* transcript = @"";
for (NSString* segment in segments) {
NSString* segmentString = [NSString stringWithFormat:@" - %@\n", segment];
transcript = [transcript stringByAppendingString:segmentString];
}*/
// weakself.transcriptLabel.text = transcript;

NSArray* priorSegments = weakself.priorSegments;
if (priorSegments) {
// Check if prior segments don't match, with exclusion of last segment
for (int i = 0; i < (int)priorSegments.count - 2; i++) {
NSString* priorSegment = priorSegments[i];
NSString* curSegment = segments[i];
if (![priorSegment isEqualToString:curSegment]) {
/* Findings:
- very often changing last segment, it's the "in progress" segment.
- pretty often changing n-1 segment -- not stable
- rarely but sometimes changes n-2 segment. Doesn't seem to be any stability guaruntee. Changes I've seen:
- correct a word
- fix punctuation
- move word from one segment to another
*/
NSLog(@"segment changed!\nPrior: %@\nCurrent: %@", priorSegment, curSegment);
}
}
}
weakself.transcriptLabel.text = transcript;

for (int i = 0; i < segments.count; i++) {
NSString* segment = segments[i];

if (priorSegments && i < (int)priorSegments.count - 2) {
// stable enough, ready to process this
readyToProcess = [readyToProcess stringByAppendingString:segment];
} else {
liveContent = [liveContent stringByAppendingString:segment];
}
}

weakself.transcriptLabel.text = [NSString stringWithFormat:@"Ready to Process:\n%@\n\nLive:\n%@", readyToProcess, liveContent];

weakself.priorSegments = segments;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions ios/voicebox/UI/VBButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initOptionButtonWithTitle:(NSString*)title;
- (instancetype)initOptionCancelButton;
- (instancetype)initKeyboardButton;

@end

Expand Down
14 changes: 14 additions & 0 deletions ios/voicebox/UI/VBButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ - (instancetype)initOptionCancelButton
return self;
}

- (instancetype)initKeyboardButton
{
self = [super init];
if (self) {
UIButtonConfiguration* config = UIButtonConfiguration.grayButtonConfiguration;
config.attributedTitle = [[NSAttributedString alloc] initWithString:@"" attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:MAX([UIFont labelFontSize], 24.0)] }];
config.contentInsets = NSDirectionalEdgeInsetsMake(16, 16, 16, 16);
;
config.baseBackgroundColor = [UIColor systemGray6Color];
self.configuration = config;
}
return self;
}

- (void)setupStandardActionButtonColor
{
self.backgroundColor = ACTION_BUTTON_UICOLOR;
Expand Down
12 changes: 11 additions & 1 deletion ios/voicebox/Util/VBSpeechSynthesizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ - (void)speak:(NSString*)textToSpeak

// TODO -- specify voice. List all with AVSpeechSynthesisVoice.speechVoices, find
// highest quality matching curent locale. Save result for next time.
// AVSpeechSynthesisVoice* voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
// voice = [AVSpeechSynthesisVoice voiceWithIdentifier:@"com.apple.speech.synthesis.voice.Fred"];
// en-US, Name: Fred, Quality: Default [com.apple.speech.synthesis.voice.Fred]
AVSpeechSynthesisVoice* voice = [[AVSpeechSynthesisVoice alloc] init];
;
/*NSArray* speechVoices = [AVSpeechSynthesisVoice speechVoices];
NSLog(@"Voices: (%d) %@", speechVoices.count, speechVoices);
for (AVSpeechSynthesisVoice* candidateVoice in speechVoices) {
if (candidateVoice.quality > voice.quality) {
// Need to check gender, and region
voice = candidateVoice;
}
}*/
utterance.voice = voice;

// Create a speech synthesizer if not available. May be removed under memory presure so always check.
Expand Down
3 changes: 2 additions & 1 deletion ios/voicebox/Whisper/VBAudioListener.m
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,12 @@ - (IBAction)onTranscribe
params.print_special = false;
params.translate = false;
params.language = "en";
// TODO P1: `params.suppress_non_speech_tokens = true;` once it makes it to stable release
params.n_threads = max_threads;
// TODO: think we're processing whole thing each time?
params.offset_ms = 0;
params.no_context = true;
params.single_segment = true;
params.single_segment = false;

CFTimeInterval startTime = CACurrentMediaTime();

Expand Down
4 changes: 2 additions & 2 deletions morse/Morse.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -459,7 +459,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
1 change: 1 addition & 0 deletions morse/Morse/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

2 changes: 1 addition & 1 deletion morse/Morse/BaseTestViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ -(void) selectNextTestButton {

// highlight button
UIButtonConfiguration* config = UIButtonConfiguration.grayButtonConfiguration;
config.baseBackgroundColor = [UIColor greenColor];
config.baseBackgroundColor = [UIColor systemBlueColor];
_currentTestTarget.configuration = config;
}

Expand Down

0 comments on commit 09243b8

Please sign in to comment.