Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 134 lines (102 sloc) 4.958 kb
dc5be1c0 » uli
2009-07-04 Initial check-in.
1 //
2 // UKSpeechSynthesizer.h
3 // UKSpeechSynthesizer
4 //
5 // Created by Uli Kusterer on Mon Jun 30 2003.
720b0e7b »
2010-03-04 Added licensing information to the source files.
6 // Copyright (c) 2003-07 M. Uli Kusterer. Uli Kusterer
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 // claim that you wrote the original software. If you use this software
18 // in a product, an acknowledgment in the product documentation would be
19 // appreciated but is not required.
20 //
21 // 2. Altered source versions must be plainly marked as such, and must not be
22 // misrepresented as being the original software.
23 //
24 // 3. This notice may not be removed or altered from any source
25 // distribution.
dc5be1c0 » uli
2009-07-04 Initial check-in.
26 //
27
28 /* -----------------------------------------------------------------------------
29 Headers:
30 -------------------------------------------------------------------------- */
31
32 #import <Foundation/Foundation.h>
33
34
35 /* -----------------------------------------------------------------------------
36 Forwards:
37 -------------------------------------------------------------------------- */
38
39 // This avoids our users from having to include all of Carbon.h every time:
40 #ifndef __SPEECHSYNTHESIS__
41 typedef struct SpeechChannelRecord SpeechChannelRecord;
42 typedef SpeechChannelRecord* SpeechChannel;
43 #endif
44
45
46 /* -----------------------------------------------------------------------------
47 UKSpeechSynthesizer:
48 -------------------------------------------------------------------------- */
49
50 @interface UKSpeechSynthesizer : NSObject
51 {
52 SpeechChannel speechChannel; // The actual Carbon speech channel that is used for speech output.
53 IBOutlet id delegate; // The delegate that gets notified of all those callbacks.
54 BOOL usesFeedbackWindow; // Dummy for NSSpeechSynthesizer compatibility.
55 BOOL isSpeaking; // Keep track whether we're speaking.
56 NSString* currVoice; // The currently assigned voice.
57
58 // private:
59 short phonemeOpcode; // We can't pass parameters when calling back to the main thread, so we stash the phoneme here.
60 void* speechDoneUPP; // cast to SpeechDoneUPP
61 void* speechPhonemeUPP; // cast to SpeechPhonemeUPP
62 char* buffer; // Keeps a copy of the text being spoken.
63 }
64
65 // Class methods:
66 +(id) speechSynthesizer; // UKSpeechSynthesizer-specific.
67 +(id) speechSynthesizerWithVoice: (NSString*)voiceName; // UKSpeechSynthesizer-specific.
68
69 +(NSArray*) availableVoices;
70 +(NSDictionary*)attributesForVoice:(NSString*)voice;
71
72 +(BOOL) isAnyApplicationSpeaking;
73
74 +(VoiceSpec) voiceSpecFromVoice: (NSString*)voiceName; // UKSpeechSynthesizer-specific.
75 +(NSString*) voiceFromVoiceSpec: (VoiceSpec*)spec; // UKSpeechSynthesizer-specific.
76 +(NSString*) prettifyString: (NSString*)inString; // UKSpeechSynthesizer-specific.
77
78 // Instance methods:
79 -(id) init;
80 -(id) initWithVoice: (NSString*)voiceName;
81
82 -(void) setDelegate: (id)delly;
83 -(id) delegate;
84
85 -(void) setVoice: (NSString*)voiceName; // Recreates the internal speech channel.
86 -(NSString*) voice;
87
88 -(void) startSpeakingString: (NSString*)str; // This retains the channel until speech is done.
89 -(BOOL) isSpeaking;
90 -(void) stopSpeaking;
91
92 -(void) setRate: (float)n;
93 -(float) rate;
94
95 -(void) setVolume: (float)n;
96 -(float) volume;
97
98 // Only implements NSSpeechPitchBaseProperty for now:
99 -(id) objectForProperty: (NSString *)property error: (NSError **)outError;
100 -(BOOL) setObject: (id)object forProperty: (NSString *)property error: (NSError **)outError;
101
102 // Dummied out:
103 -(void) setUsesFeedbackWindow: (BOOL)n; // This remembers the state, but doesn't actually bring up a feedback window.
104 -(BOOL) usesFeedbackWindow;
105 //-(void) startSpeakingString: (NSString*)str toURL:(NSURL*)url;
106
107 // UKSpeechChannel-specific:
108 -(void) stopSpeakingAt: (long)whereToStop;
109 -(void) pauseSpeakingAt: (long)whereToStop;
110 -(void) continueSpeaking;
111
112 -(void) setSpeechPitch: (double)pitch;
113 -(double) speechPitch;
114
115 -(NSDictionary*) settingsDictionary;
116 -(void) setSettingsDictionary: (NSDictionary*)dict;
117
118 -(SpeechChannel) channel;
119
120 -(BOOL) isSpeaking;
121
122 @end
123
124
125 // Delegate methods: (informal protocol)
126 @interface NSObject (UKSpeechSynthesizerDelegate)
127
128 - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking;
129 //- (void)speechSynthesizer:(UKSpeechSynthesizer *)sender willSpeakWord:(NSRange)characterRange ofString:(NSString *)string;
130 - (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakPhoneme:(short)phonemeOpcode;
131
132 @end
133
134 extern NSString* const NSSpeechPitchBaseProperty; // 10.5-only property that we fake on 10.4 and before.
Something went wrong with that request. Please try again.