Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Cocoa/Cocoa.h>
- // compiled with: gcc -std=gnu99 -fobjc-exceptions -o dialog -framework Cocoa dialog.m
- int main(int argc, const char *argv[]) {
- if (argc<2) {
- printf( "Usage: dialog [filename] (interviewer voice) (guest voice)\n" );
- exit( 1 );
- }
- NSAutoreleasePool *pool = [NSAutoreleasePool new];
- NSString *guestVoice, *interviewerVoice;
- NSMutableString *currentVoice = [NSMutableString new];
- interviewerVoice = ( argc > 2 ? [NSString stringWithUTF8String:argv[2]] : @"Victoria" );
- guestVoice = ( argc > 3 ? [NSString stringWithUTF8String:argv[3]] : @"Bruce" );
- NSSpeechSynthesizer *interviewer = [[NSSpeechSynthesizer alloc] initWithVoice:
- [NSString stringWithFormat:@"com.apple.speech.synthesis.voice.%@", interviewerVoice]];
- NSSpeechSynthesizer *guest = [[NSSpeechSynthesizer alloc] initWithVoice:
- [NSString stringWithFormat:@"com.apple.speech.synthesis.voice.%@", guestVoice]];
- NSError *error;
- NSString *inputFile = [NSString stringWithUTF8String:argv[1]];
- NSString *inputText = [NSString stringWithContentsOfFile:inputFile
- encoding:NSUTF8StringEncoding error:&error];
- if (!inputText)
- NSLog(@"Error opening file: %@", [error localizedDescription]);
- else {
- NSArray *lines = [inputText componentsSeparatedByString:@"\n"];
- NSString *interviewerCue = [lines objectAtIndex:0];
- NSString *guestCue = [lines objectAtIndex:1];
- [currentVoice setString:@"interviewer"];
- for( int i=2; i<[lines count]; i++ ) {
- NSString *line = [lines objectAtIndex:i];
- if ([line hasPrefix:interviewerCue]) {
- [interviewer startSpeakingString:[line substringFromIndex:[interviewerCue length]]];
- [currentVoice setString:@"interviewer"];
- } else if ([line hasPrefix:guestCue]) {
- [guest startSpeakingString:[line substringFromIndex:[guestCue length]]];
- [currentVoice setString:@"guest"];
- } else if ([line length]) {
- usleep( 250 ); // pause for paragraph breaks
- if ([currentVoice isEqualToString:@"interviewer"])
- [interviewer startSpeakingString:line];
- else
- [guest startSpeakingString:line];
- }
- while( [NSSpeechSynthesizer isAnyApplicationSpeaking] ) usleep( 250 );
- sleep( 1 );
- }
- }
- [currentVoice release];
- [interviewer release];
- [guest release];
- [pool release];
- return 0;
- }
Add Comment
Please, Sign In to add comment