File: say.m

package info (click to toggle)
gnustep-gui 0.20.0-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 11,760 kB
  • sloc: objc: 141,760; ansic: 16,825; cpp: 451; yacc: 418; makefile: 253; sh: 5
file content (62 lines) | stat: -rw-r--r-- 1,440 bytes parent folder | download
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 <AppKit/AppKit.h>
#include <unistd.h>
#include <getopt.h>

@interface SpeechDelegate : NSObject @end
@implementation SpeechDelegate
- (void)speechSynthesizer: (NSSpeechSynthesizer*)sender 
        didFinishSpeaking: (BOOL)success
{
	exit((int)success);
}
@end
int main(int argc, char **argv)
{
	[NSAutoreleasePool new];
	NSMutableString *words = [NSMutableString string];
	// NSString *outFile = nil;
	NSString *voice = nil;
	NSString *inFile = nil;

	int ch;
	while ((ch = getopt(argc, argv, "o:v:f:")) != -1)
	{
		switch (ch)
		{
			case 'o':
				// outFile = [NSString stringWithUTF8String: optarg];
				break;
			case 'f':
				inFile = [NSString stringWithUTF8String: optarg];
				break;
			case 'v':
				voice = [NSString stringWithUTF8String: optarg];
				break;
		}
	}
	int i;
	for (i=optind ; i<argc ; i++)
	{
		[words appendString: [NSString stringWithUTF8String: argv[i]]];
		[words appendString: @" "];
	}

	NSSpeechSynthesizer *say = [[NSSpeechSynthesizer alloc] initWithVoice: voice];
	if (nil != inFile)
	{
		[words release];
		NSData *file = [NSData dataWithContentsOfFile: inFile];
		words = [NSString stringWithCString: [file bytes]];
	}

	// Don't interrupt other apps.
	while ([NSSpeechSynthesizer isAnyApplicationSpeaking])
	{
		[NSThread sleepForTimeInterval: 0.1];
	}
	[say setDelegate: [SpeechDelegate new]];
	[say startSpeakingString: words];
	[[NSRunLoop currentRunLoop] run];
	// Not reached.
	return 0;
}