Skip to content

Commit

Permalink
Address germanattanasio#41. Adds more parameters for STT
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho4d committed Sep 3, 2016
1 parent ae50f44 commit b57a28b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
16 changes: 14 additions & 2 deletions watsonsdk/stt/STTConfiguration.h
Expand Up @@ -32,6 +32,9 @@
#define WATSONSDK_AUDIO_FRAME_SIZE 160
#define WATSONSDK_AUDIO_SAMPLE_RATE 16000.0

// timeout
#define WATSONSDK_INACTIVITY_TIMEOUT 30

// models
#define WATSONSDK_DEFAULT_STT_MODEL @"en-US_BroadbandModel"

Expand All @@ -43,16 +46,25 @@
@property NSNumber *interimResults;
@property NSNumber *continuous;
@property NSNumber *inactivityTimeout;
@property NSDictionary<NSString*, NSObject*> *additionalParameters; // i.e.: @{ @"smart_formatting": @(YES), @"max_alternatives", @(3) };
@property NSNumber *keywordsThreshold;
@property NSNumber *maxAlternatives;
@property NSNumber *wordAlternativesThreshold;
@property BOOL wordConfidence;
@property BOOL timestamps;
@property NSArray *keywords;

@property BOOL profanityFilter;
@property BOOL smartFormatting;

@property NSURL *apiEndpoint;
@property BOOL isCertificateValidationDisabled;


- (id)init;

- (NSURL*)getModelsServiceURL;
- (NSURL*)getModelServiceURL:(NSString*) modelName;
- (NSURL*)getWebSocketRecognizeURL;

- (NSString *)getStartMessage;

@end
50 changes: 43 additions & 7 deletions watsonsdk/stt/STTConfiguration.m
Expand Up @@ -27,9 +27,19 @@ - (id)init {
[self setApiEndpoint:[NSURL URLWithString:WATSONSDK_DEFAULT_STT_API_ENDPOINT]];
[self setModelName:WATSONSDK_DEFAULT_STT_MODEL];
[self setAudioCodec:WATSONSDK_AUDIO_CODEC_TYPE_PCM];

[self setInterimResults: [NSNumber numberWithBool:YES]];
[self setContinuous:[NSNumber numberWithBool:NO]];
[self setInactivityTimeout:[NSNumber numberWithInt:30]];
[self setInactivityTimeout:[NSNumber numberWithInt:WATSONSDK_INACTIVITY_TIMEOUT]];

[self setKeywordsThreshold:[NSNumber numberWithDouble:-1]];
[self setMaxAlternatives:[NSNumber numberWithInt:1]];
[self setWordAlternativesThreshold:[NSNumber numberWithDouble:-1]];
[self setKeywords:nil];
[self setProfanityFilter:YES];
[self setSmartFormatting:NO];
[self setTimestamps:NO];
[self setWordConfidence:NO];

return self;
}
Expand Down Expand Up @@ -99,13 +109,39 @@ - (NSString *)getStartMessage{
NSMutableDictionary *inputParameters = [[NSMutableDictionary alloc] init];
[inputParameters setValue:@"start" forKey:@"action"];
[inputParameters setValue:self.audioCodec forKey:@"content-type"];
[inputParameters setValue:self.interimResults forKey:@"interim_results"];
[inputParameters setValue:self.continuous forKey:@"continuous"];
[inputParameters setValue:self.inactivityTimeout forKey:@"inactivity_timeout"];
for (NSString *key in self.additionalParameters.allKeys) {
[inputParameters setValue:self.additionalParameters[key] forKey:key];
if (self.interimResults) {
[inputParameters setValue:[NSNumber numberWithBool:YES] forKey:@"interim_results"];
}
if ([self.inactivityTimeout intValue] != WATSONSDK_INACTIVITY_TIMEOUT) {
[inputParameters setValue:self.inactivityTimeout forKey:@"inactivity_timeout"];
}
if (self.continuous) {
[inputParameters setValue:[NSNumber numberWithBool:YES] forKey:@"continuous"];
}
if ([self.maxAlternatives intValue] > 1) {
[inputParameters setValue:self.maxAlternatives forKey:@"max_alternatives"];
}
if ([self.keywordsThreshold doubleValue] >= 0 && [self.keywordsThreshold doubleValue] <= 1) {
[inputParameters setValue:self.keywordsThreshold forKey:@"keywords_threshold"];
}
if ([self.wordAlternativesThreshold doubleValue] >= 0 && [self.wordAlternativesThreshold doubleValue] <= 1) {
[inputParameters setValue:self.wordAlternativesThreshold forKey:@"word_alternatives_threshold"];
}
if (self.keywords && [self.keywords count] > 0) {
[inputParameters setValue:self.keywords forKey:@"keywords"];
}
if (self.smartFormatting) {
[inputParameters setValue:[NSNumber numberWithBool:YES] forKey:@"smart_formatting"];
}
if (self.timestamps) {
[inputParameters setValue:[NSNumber numberWithBool:YES] forKey:@"timestamps"];
}
if (self.profanityFilter == NO) {
[inputParameters setValue:[NSNumber numberWithBool:NO] forKey:@"profanity_filter"];
}
if (self.wordConfidence) {
[inputParameters setValue:[NSNumber numberWithBool:YES] forKey:@"word_confidence"];
}

NSError *error = nil;
if([NSJSONSerialization isValidJSONObject:inputParameters]){
NSData *data = [NSJSONSerialization dataWithJSONObject:inputParameters options:NSJSONWritingPrettyPrinted error:&error];
Expand Down

0 comments on commit b57a28b

Please sign in to comment.