KIFTests talk
You can use iPhone speech synthesizer to announce runs of integration tests.
Hear the sounds what will warm your heart every time. It shows that tests are working.
If you have Siri on your phone Siri’s voice will pronounce the phrases.
VSSpeechSynthesizer could be found in XCode 4.4 in iOS PrivateFrameworks
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/PrivateFrameworks/VoiceServices.framework
Add new VSSpeechSynthesizer.h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// VSSpeechSynthesizer.h
@interface VSSpeechSynthesizer : NSObject {}
+ (id)availableLanguageCodes;
+ (BOOL)isSystemSpeaking;
- (id)startSpeakingString:(id)string;
- (id)startSpeakingString:(id)string toURL:(id)url;
- (id)startSpeakingString:(id)string toURL:(id)url withLanguageCode:(id)code;
- (float)rate; // default rate: 1
- (id)setRate:(float)rate;
- (float)pitch; // default pitch: 0.5
- (id)setPitch:(float)pitch;
- (float)volume; // default volume: 0.8
- (id)setVolume:(float)volume;
@end |
Add to your EXTestController.m
1 2 3 4 5 6 7 8 9 10 11 12 |
VSSpeechSynthesizer *synthesizer;
- (void)initializeScenarios {
...
synthesizer = [VSSpeechSynthesizer new];
}
- (void)startTestingWithCompletionBlock:(KIFTestControllerCompletionBlock)inCompletionBlock {
[synthesizer startSpeakingString:@"starting testing"];
...
} |
Next if you like your test to speak on iOS Simulator too you can add this implementation of
VSSpeechSynthesizer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#import "VSSpeechSynthesizer.h"
#if TARGET_IPHONE_SIMULATOR
@implementation VSSpeechSynthesizer
+ (id)availableLanguageCodes {
return nil;
}
+ (BOOL)isSystemSpeaking {
return NO;
}
-(NSString *)selectVoiceForPhrase:(NSString *)phrase {
NSDictionary *keywordToVoice = @{
@"failures!" : @"Bad",
@"failure!" : @"Bruce",
@"FAIL" : @"Agnes"
};
NSString *keyword = nil;
for (keyword in [keywordToVoice allKeys]) {
BOOL found = NSNotFound != [phrase rangeOfString:keyword].location;
if (found) {
break;
}
}
return keyword ? [keywordToVoice objectForKey:keyword] : @"Vicki -r 150";
}
- (id)startSpeakingString:(id)what {
NSString *voice = [self selectVoiceForPhrase:what];
NSString *command = [NSString stringWithFormat:@"say -v %@ %@", voice, what];
system([command cStringUsingEncoding:NSASCIIStringEncoding]);
DLogObject(what);
return nil;
}
- (id)startSpeakingString:(id)string toURL:(id)url {
return nil;
}
- (id)startSpeakingString:(id)string toURL:(id)url withLanguageCode:(id)code {
return nil;
}
- (float)rate {
return 1;
}
- (id)setRate:(float)rate {
return nil;
}
- (float)pitch {
return 0.5;
}
- (id)setPitch:(float)pitch {
return nil;
}
- (float)volume {
return 0.8;
}
- (id)setVolume:(float)volume {
return nil;
}
@end
#endif |
Hear the sound of all tests passed.
Next we added an announcement of the first failure in the test suite to help us debug the issue. That announcement comes from a voice called “bad news” logically. See more voices available on Mac OS X System Preferences Speech panel: