Quantcast
Channel: » iOS
Viewing all articles
Browse latest Browse all 5

KIFTests talk

0
0

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.

Starting 13 test scenarios


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:

// 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

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

#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.

All 13 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:


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images