Skip to content
This repository has been archived by the owner on Aug 22, 2018. It is now read-only.

Commit

Permalink
Added configurations of keywordsThreshold, maxAlternatives, wordAlter…
Browse files Browse the repository at this point in the history
…nativesThreshold, keywords for STT and xWatsonLearningOptOut for STT and TTS
  • Loading branch information
Michael committed Jul 6, 2016
1 parent 9178c71 commit 4b20393
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 22 deletions.
5 changes: 5 additions & 0 deletions watsonsdk/AuthConfiguration.h
Expand Up @@ -24,6 +24,11 @@
@property (readonly) NSString *token;
@property (copy, nonatomic) void (^tokenGenerator) (void (^tokenHandler)(NSString *token));

@property NSString* apiURL;
@property NSURL* apiEndpoint;
@property BOOL isCertificateValidationDisabled;
@property BOOL xWatsonLearningOptOut;

- (void) invalidateToken;
- (void)requestToken:(void (^)(AuthConfiguration *config))completionHandler refreshCache:(BOOL) refreshCachedToken;
- (NSDictionary*) createRequestHeaders;
Expand Down
1 change: 1 addition & 0 deletions watsonsdk/AuthConfiguration.m
Expand Up @@ -25,6 +25,7 @@ @implementation AuthConfiguration
- (id) init {
self = [super init];
_token = nil;
_xWatsonLearningOptOut = NO;
return self;
}

Expand Down
9 changes: 5 additions & 4 deletions watsonsdk/stt/STTConfiguration.h
Expand Up @@ -37,15 +37,16 @@

@interface STTConfiguration : AuthConfiguration

@property NSString *apiURL;
@property NSString *modelName;
@property NSString *audioCodec;
@property BOOL interimResults;
@property BOOL continuous;
@property NSNumber *inactivityTimeout;

@property NSURL *apiEndpoint;
@property BOOL isCertificateValidationDisabled;
@property NSNumber *connectionTimeout;
@property NSNumber *keywordsThreshold;
@property NSNumber *maxAlternatives;
@property NSNumber *wordAlternativesThreshold;
@property NSArray *keywords;

@property float audioSampleRate;
@property int audioFrameSize;
Expand Down
29 changes: 22 additions & 7 deletions watsonsdk/stt/STTConfiguration.m
Expand Up @@ -18,7 +18,6 @@

@implementation STTConfiguration

@synthesize apiURL = _apiURL;
@synthesize audioSampleRate = _audioSampleRate;
@synthesize audioFrameSize = _audioFrameSize;

Expand All @@ -36,6 +35,11 @@ - (id)init {
[self setContinuous: NO];
[self setInactivityTimeout:[NSNumber numberWithInt:30]];

[self setKeywordsThreshold:[NSNumber numberWithDouble:-1]];
[self setMaxAlternatives:[NSNumber numberWithInt:1]];
[self setWordAlternativesThreshold:[NSNumber numberWithDouble:-1]];
[self setKeywords:nil];

return self;
}

Expand All @@ -46,15 +50,10 @@ - (id)init {
*/
- (void)setApiURL:(NSString *)apiURLStr {

_apiURL = apiURLStr;
self.apiURL = apiURLStr;
[self setApiEndpoint:[NSURL URLWithString:apiURLStr]];
}

- (NSString*) apiURL {
return _apiURL;
}


#pragma mark convenience methods for obtaining service URLs

- (NSURL*)getModelsServiceURL {
Expand Down Expand Up @@ -108,6 +107,22 @@ - (NSString *)getStartMessage {
[inputParameters setValue:[NSNumber numberWithBool:self.continuous] forKey:@"continuous"];
[inputParameters setValue:self.inactivityTimeout forKey:@"inactivity_timeout"];

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([NSJSONSerialization isValidJSONObject:inputParameters]){
NSError *error = nil;
NSData *data = [NSJSONSerialization dataWithJSONObject:inputParameters options:NSJSONWritingPrettyPrinted error:&error];
Expand Down
4 changes: 1 addition & 3 deletions watsonsdk/tts/TTSConfiguration.h
Expand Up @@ -35,11 +35,9 @@

@interface TTSConfiguration : AuthConfiguration

@property NSString* apiURL;
@property NSString* voiceName;
@property NSString* audioCodec;
@property NSURL* apiEndpoint;
@property BOOL isCertificateValidationDisabled;


- (id)init;
- (NSURL*)getVoicesServiceURL;
Expand Down
8 changes: 1 addition & 7 deletions watsonsdk/tts/TTSConfiguration.m
Expand Up @@ -18,8 +18,6 @@

@implementation TTSConfiguration

@synthesize apiURL = _apiURL;

- (id)init {
self = [super init];

Expand All @@ -38,14 +36,10 @@ - (id)init {
*/
- (void)setApiURL:(NSString *)apiURLStr {

_apiURL = apiURLStr;
self.apiURL = apiURLStr;
[self setApiEndpoint:[NSURL URLWithString:apiURLStr]];
}

- (NSString*) apiURL {
return _apiURL;
}


#pragma mark convenience methods for obtaining service URLs

Expand Down
6 changes: 5 additions & 1 deletion watsonsdk/websocket/WebSocketAudioStreamer.m
Expand Up @@ -55,14 +55,18 @@ - (void) connect:(STTConfiguration*)config headers:(NSDictionary*)headers comple
self.hasDataBeenSent = NO;

NSLog(@"websocket connection using %@",[[self.sConfig getWebSocketRecognizeURL] absoluteString]);

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[self.sConfig getWebSocketRecognizeURL]];

// set headers
for(id headerName in headers) {
[req setValue:[headers objectForKey:headerName] forHTTPHeaderField:headerName];
}

if(config.xWatsonLearningOptOut) {
[req setValue:@"true" forHTTPHeaderField:@"X-Watson-Learning-Opt-Out"];
}

self.webSocket = [[SRWebSocket alloc] initWithURLRequest:req];
self.webSocket.delegate = self;
self.closureCallback = closureCallback;
Expand Down

0 comments on commit 4b20393

Please sign in to comment.