mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 02:04:20 +00:00
Clean up the code and the GNUmakefile of the say tool.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33091 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
f881df45ed
commit
1964b0d902
3 changed files with 69 additions and 47 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-05-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Tools/say/GNUmakefile
|
||||
* Tools/say/say.m: Clean these up a bit to correctly compile wiht
|
||||
gcc 4.6.
|
||||
|
||||
2011-05-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSControl.h:
|
||||
|
|
|
@ -17,7 +17,7 @@ say_INCLUDE_DIRS += -I../../Headers -I../../Headers/Additions
|
|||
say_LIB_DIRS += -L../../Source/$(GNUSTEP_OBJ_DIR) \
|
||||
-L/usr/local/lib
|
||||
|
||||
say_OBJCFLAGS += -std=c99 -g -Werror
|
||||
#say_OBJCFLAGS += -std=c99 -g -Werror
|
||||
say_LDFLAGS += -lgnustep-gui
|
||||
|
||||
-include GNUmakefile.preamble
|
||||
|
|
108
Tools/say/say.m
108
Tools/say/say.m
|
@ -2,61 +2,77 @@
|
|||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
|
||||
@interface SpeechDelegate : NSObject @end
|
||||
@interface SpeechDelegate : NSObject
|
||||
@end
|
||||
|
||||
@implementation SpeechDelegate
|
||||
- (void)speechSynthesizer: (NSSpeechSynthesizer*)sender
|
||||
didFinishSpeaking: (BOOL)success
|
||||
{
|
||||
exit((int)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;
|
||||
NSAutoreleasePool * p = [NSAutoreleasePool new];
|
||||
NSMutableString *words = nil;
|
||||
NSString *outFile = nil;
|
||||
NSString *voice = nil;
|
||||
NSString *inFile = nil;
|
||||
NSSpeechSynthesizer *say;
|
||||
int ch;
|
||||
int i;
|
||||
|
||||
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: @" "];
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (nil != inFile)
|
||||
{
|
||||
NSData *file = [NSData dataWithContentsOfFile: inFile];
|
||||
words = [NSString stringWithCString: [file bytes]];
|
||||
}
|
||||
else
|
||||
{
|
||||
words = [NSMutableString string];
|
||||
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];
|
||||
}
|
||||
|
||||
// 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;
|
||||
say = [[NSSpeechSynthesizer alloc] initWithVoice: voice];
|
||||
[say setDelegate: [SpeechDelegate new]];
|
||||
if (nil != outFile)
|
||||
{
|
||||
[say startSpeakingString: words toURL: [NSURL fileURLWithPath: outFile]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[say startSpeakingString: words];
|
||||
}
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
// Not reached.
|
||||
RELEASE(p);
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue