forked from jakeajames/say
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.m
61 lines (59 loc) · 1.79 KB
/
main.m
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
#include <stdlib.h>
#import <Foundation/Foundation.h>
#import <AppSupport/CPDistributedMessagingCenter.h>
void printUsage() {
printf("\nUsage: say [message]\n");
printf("Usage: say [-m] [message] [-l] [lang]\n");
printf("\nExample: say Hello\n");
printf("Example: say \"Hello World\"\n");
printf("Example: say -m Hello -l en-us\n");
printf("Example: say -m \"Hello World\" -l ja-jp\n");
printf("\nOptions:\n");
printf("\t-h Displays this help.\n");
printf("\t-m The message to say, with quotes if there are multile words.\n");
printf("\t-l The voice language for Siri to say, as language culture name. For example, en-us or ja-jp.\n");
}
int main(int argc, char **argv, char **envp) {
if (argc < 2) {
printUsage();
exit(EXIT_FAILURE);
}
NSString *message = nil;
NSString *lang = nil;
if (argc == 2) {
if (strcmp(argv[1], "-h") == 0) {
printUsage();
exit(EXIT_SUCCESS);
}
message = [NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:argv[1]]];
} else {
int opt;
while ((opt = getopt(argc, argv, "m:l:h")) != -1) {
switch (opt) {
case 'm':
message = [NSString stringWithFormat:@"%@", [NSString stringWithUTF8String:strdup(optarg)]];
break;
case 'l':
lang = [NSString stringWithFormat:@"%s", strdup(optarg)];
break;
case 'h':
printUsage();
exit(EXIT_SUCCESS);
default:
printUsage();
exit(EXIT_FAILURE);
}
}
}
if (message == nil) {
printf("Please specify the message to say in quotes.\n");
exit(EXIT_FAILURE);
}
CPDistributedMessagingCenter *messagingCenter = [CPDistributedMessagingCenter centerNamed:@"com.jakeashacks.saycenter"];
NSDictionary *userInfo = @{
@"message": message,
@"lang": lang ?: @"",
};
[messagingCenter sendMessageAndReceiveReplyName:@"whattosay" userInfo:userInfo];
return 0;
}