Skip to content
Permalink
Browse files

TextToSpeech_macx: fix 10.4 compatibility.

Remove @Property and @synthesize to make the
code work on 10.4.

Also import AppKit.h to fix the build when
building without PCH support.
  • Loading branch information...
zorgiepoo authored and mkrautz committed Jan 21, 2014
1 parent 15f7610 commit c2f75bbd5568d6f366980a13f54db14224336a97
Showing with 26 additions and 21 deletions.
  1. +26 −21 src/mumble/TextToSpeech_macx.mm
@@ -31,56 +31,60 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#import <AppKit/AppKit.h>

#include "mumble_pch.hpp"

#include "Global.h"
#include "TextToSpeech.h"

@interface MUSpeechSynthesizerPrivateHelper : NSObject <NSSpeechSynthesizerDelegate>
@property (nonatomic, readonly) NSSpeechSynthesizer *synthesizer;
@interface MUSpeechSynthesizerPrivateHelper : NSObject <NSSpeechSynthesizerDelegate> {
NSMutableArray *m_messages;
NSSpeechSynthesizer *m_synthesizer;
}
- (NSSpeechSynthesizer *)synthesizer;
- (void)appendMessage:(NSString *)message;
- (void)processSpeech;
@end

@interface MUSpeechSynthesizerPrivateHelper ()
@property (nonatomic, retain) NSMutableArray *messages;
@property (nonatomic, retain) NSSpeechSynthesizer *synthesizer;
@end

@implementation MUSpeechSynthesizerPrivateHelper

- (id)init {
if ((self = [super init])) {
self.synthesizer = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
self.messages = [NSMutableArray array];
self.synthesizer.delegate = self;
m_synthesizer = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
m_messages = [[NSMutableArray alloc] init];
[m_synthesizer setDelegate:self];
}
return self;
}

- (void)dealloc {
self.synthesizer = nil;
self.messages = nil;
[m_synthesizer release];
[m_messages release];
[super dealloc];
}

- (NSSpeechSynthesizer *)synthesizer {
return m_synthesizer;
}

- (void)appendMessage:(NSString *)message {
[self.messages insertObject:message atIndex:0];
[m_messages insertObject:message atIndex:0];
}

- (void)processSpeech {
Q_ASSERT(self.messages.count == 0);
Q_ASSERT([m_messages count] == 0);

NSString *poppedMessage = [self.messages lastObject];
[self.synthesizer startSpeakingString:poppedMessage];
[self.messages removeLastObject];
NSString *poppedMessage = [m_messages lastObject];
[m_synthesizer startSpeakingString:poppedMessage];
[m_messages removeLastObject];
}

- (void)speechSynthesizer:(NSSpeechSynthesizer *)synthesizer didFinishSpeaking:(BOOL)success {
Q_UNUSED(synthesizer);
Q_UNUSED(success);

if (self.messages.count != 0) {
if ([m_messages count] != 0) {
[self processSpeech];
}
}
@@ -108,22 +112,23 @@ - (void)speechSynthesizer:(NSSpeechSynthesizer *)synthesizer didFinishSpeaking:(
void TextToSpeechPrivate::say(const QString &text) {
QByteArray byteArray = text.toUtf8();
NSString *message = [[NSString alloc] initWithBytes:byteArray.constData() length:byteArray.size() encoding:NSUTF8StringEncoding];

if (message == nil) {
return;
}

[m_synthesizerHelper appendMessage:message];
[message release];

if (![m_synthesizerHelper.synthesizer isSpeaking]) {
if (![[m_synthesizerHelper synthesizer] isSpeaking]) {
[m_synthesizerHelper processSpeech];
}
}

void TextToSpeechPrivate::setVolume(int volume) {
// Check for setVolume: availability. It's only available on 10.5+.
if ([m_synthesizerHelper.synthesizer respondsToSelector:@selector(setVolume:)]) {
[m_synthesizerHelper.synthesizer setVolume:volume / 100.0];
if ([[m_synthesizerHelper synthesizer] respondsToSelector:@selector(setVolume:)]) {
[[m_synthesizerHelper synthesizer] setVolume:volume / 100.0];
}
}

0 comments on commit c2f75bb

Please sign in to comment.
You can’t perform that action at this time.