Mercurial > projects > dstep
diff dstep/appkit/NSSpeechSynthesizer.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | |
children | b9de51448c6b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dstep/appkit/NSSpeechSynthesizer.d Sun Jan 03 22:06:11 2010 +0100 @@ -0,0 +1,720 @@ +/** + * Copyright: Copyright (c) 2009 Jacob Carlborg. + * Authors: Jacob Carlborg + * Version: Initial created: Sep 24, 2009 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) + */ +module dstep.appkit.NSSpeechSynthesizer; + +import dstep.appkit.AppKitDefines; +import dstep.foundation.NSArray; +import dstep.foundation.NSDictionary; +import dstep.foundation.NSError; +import dstep.foundation.NSObjCRuntime; +import dstep.foundation.NSObject; +import dstep.foundation.NSRange; +import dstep.foundation.NSString; +import dstep.foundation.NSURL; +import dstep.objc.bridge.Bridge; +import dstep.objc.objc; + +import bindings = dstep.appkit.NSSpeechSynthesizer_bindings; + +alias NSUInteger NSSpeechBoundary; + +private +{ + NSString NSVoiceName_; + NSString NSVoiceIdentifier_; + NSString NSVoiceAge_; + NSString NSVoiceGender_; + NSString NSVoiceDemoText_; + NSString NSVoiceLocaleIdentifier_; + NSString NSVoiceSupportedCharacters_; + NSString NSVoiceIndividuallySpokenCharacters_; + NSString NSVoiceGenderNeuter_; + NSString NSVoiceGenderMale_; + NSString NSVoiceGenderFemale_; + NSString NSSpeechStatusProperty_; + NSString NSSpeechErrorsProperty_; + NSString NSSpeechInputModeProperty_; + NSString NSSpeechCharacterModeProperty_; + NSString NSSpeechNumberModeProperty_; + NSString NSSpeechRateProperty_; + NSString NSSpeechPitchBaseProperty_; + NSString NSSpeechPitchModProperty_; + NSString NSSpeechVolumeProperty_; + NSString NSSpeechSynthesizerInfoProperty_; + NSString NSSpeechRecentSyncProperty_; + NSString NSSpeechPhonemeSymbolsProperty_; + NSString NSSpeechCurrentVoiceProperty_; + NSString NSSpeechCommandDelimiterProperty_; + NSString NSSpeechResetProperty_; + NSString NSSpeechOutputToFileURLProperty_; + NSString NSSpeechModeText_; + NSString NSSpeechModePhoneme_; + NSString NSSpeechModeNormal_; + NSString NSSpeechModeLiteral_; + NSString NSSpeechStatusOutputBusy_; + NSString NSSpeechStatusOutputPaused_; + NSString NSSpeechStatusNumberOfCharactersLeft_; + NSString NSSpeechStatusPhonemeCode_; + NSString NSSpeechErrorCount_; + NSString NSSpeechErrorOldestCode_; + NSString NSSpeechErrorOldestCharacterOffset_; + NSString NSSpeechErrorNewestCode_; + NSString NSSpeechErrorNewestCharacterOffset_; + NSString NSSpeechSynthesizerInfoIdentifier_; + NSString NSSpeechSynthesizerInfoVersion_; + NSString NSSpeechPhonemeInfoOpcode_; + NSString NSSpeechPhonemeInfoSymbol_; + NSString NSSpeechPhonemeInfoExample_; + NSString NSSpeechPhonemeInfoHiliteStart_; + NSString NSSpeechPhonemeInfoHiliteEnd_; + NSString NSSpeechCommandPrefix_; + NSString NSSpeechCommandSuffix_; + NSString NSSpeechDictionaryLocaleIdentifier_; + NSString NSSpeechDictionaryModificationDate_; + NSString NSSpeechDictionaryPronunciations_; + NSString NSSpeechDictionaryAbbreviations_; + NSString NSSpeechDictionaryEntrySpelling_; + NSString NSSpeechDictionaryEntryPhonemes_; +} + +NSString NSVoiceName () +{ + if (NSVoiceName_) + return NSVoiceName_; + + return NSVoiceName_ = new NSString(bindings.NSVoiceName); +} + +NSString NSVoiceIdentifier () +{ + if (NSVoiceIdentifier_) + return NSVoiceIdentifier_; + + return NSVoiceIdentifier_ = new NSString(bindings.NSVoiceIdentifier); +} + +NSString NSVoiceAge () +{ + if (NSVoiceAge_) + return NSVoiceAge_; + + return NSVoiceAge_ = new NSString(bindings.NSVoiceAge); +} + +NSString NSVoiceGender () +{ + if (NSVoiceGender_) + return NSVoiceGender_; + + return NSVoiceGender_ = new NSString(bindings.NSVoiceGender); +} + +NSString NSVoiceDemoText () +{ + if (NSVoiceDemoText_) + return NSVoiceDemoText_; + + return NSVoiceDemoText_ = new NSString(bindings.NSVoiceDemoText); +} + +NSString NSVoiceLocaleIdentifier () +{ + if (NSVoiceLocaleIdentifier_) + return NSVoiceLocaleIdentifier_; + + return NSVoiceLocaleIdentifier_ = new NSString(bindings.NSVoiceLocaleIdentifier); +} + +NSString NSVoiceSupportedCharacters () +{ + if (NSVoiceSupportedCharacters_) + return NSVoiceSupportedCharacters_; + + return NSVoiceSupportedCharacters_ = new NSString(bindings.NSVoiceSupportedCharacters); +} + +NSString NSVoiceIndividuallySpokenCharacters () +{ + if (NSVoiceIndividuallySpokenCharacters_) + return NSVoiceIndividuallySpokenCharacters_; + + return NSVoiceIndividuallySpokenCharacters_ = new NSString(bindings.NSVoiceIndividuallySpokenCharacters); +} + +NSString NSVoiceGenderNeuter () +{ + if (NSVoiceGenderNeuter_) + return NSVoiceGenderNeuter_; + + return NSVoiceGenderNeuter_ = new NSString(bindings.NSVoiceGenderNeuter); +} + +NSString NSVoiceGenderMale () +{ + if (NSVoiceGenderMale_) + return NSVoiceGenderMale_; + + return NSVoiceGenderMale_ = new NSString(bindings.NSVoiceGenderMale); +} + +NSString NSVoiceGenderFemale () +{ + if (NSVoiceGenderFemale_) + return NSVoiceGenderFemale_; + + return NSVoiceGenderFemale_ = new NSString(bindings.NSVoiceGenderFemale); +} + +NSString NSSpeechStatusProperty () +{ + if (NSSpeechStatusProperty_) + return NSSpeechStatusProperty_; + + return NSSpeechStatusProperty_ = new NSString(bindings.NSSpeechStatusProperty); +} + +NSString NSSpeechErrorsProperty () +{ + if (NSSpeechErrorsProperty_) + return NSSpeechErrorsProperty_; + + return NSSpeechErrorsProperty_ = new NSString(bindings.NSSpeechErrorsProperty); +} + +NSString NSSpeechInputModeProperty () +{ + if (NSSpeechInputModeProperty_) + return NSSpeechInputModeProperty_; + + return NSSpeechInputModeProperty_ = new NSString(bindings.NSSpeechInputModeProperty); +} + +NSString NSSpeechCharacterModeProperty () +{ + if (NSSpeechCharacterModeProperty_) + return NSSpeechCharacterModeProperty_; + + return NSSpeechCharacterModeProperty_ = new NSString(bindings.NSSpeechCharacterModeProperty); +} + +NSString NSSpeechNumberModeProperty () +{ + if (NSSpeechNumberModeProperty_) + return NSSpeechNumberModeProperty_; + + return NSSpeechNumberModeProperty_ = new NSString(bindings.NSSpeechNumberModeProperty); +} + +NSString NSSpeechRateProperty () +{ + if (NSSpeechRateProperty_) + return NSSpeechRateProperty_; + + return NSSpeechRateProperty_ = new NSString(bindings.NSSpeechRateProperty); +} + +NSString NSSpeechPitchBaseProperty () +{ + if (NSSpeechPitchBaseProperty_) + return NSSpeechPitchBaseProperty_; + + return NSSpeechPitchBaseProperty_ = new NSString(bindings.NSSpeechPitchBaseProperty); +} + +NSString NSSpeechPitchModProperty () +{ + if (NSSpeechPitchModProperty_) + return NSSpeechPitchModProperty_; + + return NSSpeechPitchModProperty_ = new NSString(bindings.NSSpeechPitchModProperty); +} + +NSString NSSpeechVolumeProperty () +{ + if (NSSpeechVolumeProperty_) + return NSSpeechVolumeProperty_; + + return NSSpeechVolumeProperty_ = new NSString(bindings.NSSpeechVolumeProperty); +} + +NSString NSSpeechSynthesizerInfoProperty () +{ + if (NSSpeechSynthesizerInfoProperty_) + return NSSpeechSynthesizerInfoProperty_; + + return NSSpeechSynthesizerInfoProperty_ = new NSString(bindings.NSSpeechSynthesizerInfoProperty); +} + +NSString NSSpeechRecentSyncProperty () +{ + if (NSSpeechRecentSyncProperty_) + return NSSpeechRecentSyncProperty_; + + return NSSpeechRecentSyncProperty_ = new NSString(bindings.NSSpeechRecentSyncProperty); +} + +NSString NSSpeechPhonemeSymbolsProperty () +{ + if (NSSpeechPhonemeSymbolsProperty_) + return NSSpeechPhonemeSymbolsProperty_; + + return NSSpeechPhonemeSymbolsProperty_ = new NSString(bindings.NSSpeechPhonemeSymbolsProperty); +} + +NSString NSSpeechCurrentVoiceProperty () +{ + if (NSSpeechCurrentVoiceProperty_) + return NSSpeechCurrentVoiceProperty_; + + return NSSpeechCurrentVoiceProperty_ = new NSString(bindings.NSSpeechCurrentVoiceProperty); +} + +NSString NSSpeechCommandDelimiterProperty () +{ + if (NSSpeechCommandDelimiterProperty_) + return NSSpeechCommandDelimiterProperty_; + + return NSSpeechCommandDelimiterProperty_ = new NSString(bindings.NSSpeechCommandDelimiterProperty); +} + +NSString NSSpeechResetProperty () +{ + if (NSSpeechResetProperty_) + return NSSpeechResetProperty_; + + return NSSpeechResetProperty_ = new NSString(bindings.NSSpeechResetProperty); +} + +NSString NSSpeechOutputToFileURLProperty () +{ + if (NSSpeechOutputToFileURLProperty_) + return NSSpeechOutputToFileURLProperty_; + + return NSSpeechOutputToFileURLProperty_ = new NSString(bindings.NSSpeechOutputToFileURLProperty); +} + +NSString NSSpeechModeText () +{ + if (NSSpeechModeText_) + return NSSpeechModeText_; + + return NSSpeechModeText_ = new NSString(bindings.NSSpeechModeText); +} + +NSString NSSpeechModePhoneme () +{ + if (NSSpeechModePhoneme_) + return NSSpeechModePhoneme_; + + return NSSpeechModePhoneme_ = new NSString(bindings.NSSpeechModePhoneme); +} + +NSString NSSpeechModeNormal () +{ + if (NSSpeechModeNormal_) + return NSSpeechModeNormal_; + + return NSSpeechModeNormal_ = new NSString(bindings.NSSpeechModeNormal); +} + +NSString NSSpeechModeLiteral () +{ + if (NSSpeechModeLiteral_) + return NSSpeechModeLiteral_; + + return NSSpeechModeLiteral_ = new NSString(bindings.NSSpeechModeLiteral); +} + +NSString NSSpeechStatusOutputBusy () +{ + if (NSSpeechStatusOutputBusy_) + return NSSpeechStatusOutputBusy_; + + return NSSpeechStatusOutputBusy_ = new NSString(bindings.NSSpeechStatusOutputBusy); +} + +NSString NSSpeechStatusOutputPaused () +{ + if (NSSpeechStatusOutputPaused_) + return NSSpeechStatusOutputPaused_; + + return NSSpeechStatusOutputPaused_ = new NSString(bindings.NSSpeechStatusOutputPaused); +} + +NSString NSSpeechStatusNumberOfCharactersLeft () +{ + if (NSSpeechStatusNumberOfCharactersLeft_) + return NSSpeechStatusNumberOfCharactersLeft_; + + return NSSpeechStatusNumberOfCharactersLeft_ = new NSString(bindings.NSSpeechStatusNumberOfCharactersLeft); +} + +NSString NSSpeechStatusPhonemeCode () +{ + if (NSSpeechStatusPhonemeCode_) + return NSSpeechStatusPhonemeCode_; + + return NSSpeechStatusPhonemeCode_ = new NSString(bindings.NSSpeechStatusPhonemeCode); +} + +NSString NSSpeechErrorCount () +{ + if (NSSpeechErrorCount_) + return NSSpeechErrorCount_; + + return NSSpeechErrorCount_ = new NSString(bindings.NSSpeechErrorCount); +} + +NSString NSSpeechErrorOldestCode () +{ + if (NSSpeechErrorOldestCode_) + return NSSpeechErrorOldestCode_; + + return NSSpeechErrorOldestCode_ = new NSString(bindings.NSSpeechErrorOldestCode); +} + +NSString NSSpeechErrorOldestCharacterOffset () +{ + if (NSSpeechErrorOldestCharacterOffset_) + return NSSpeechErrorOldestCharacterOffset_; + + return NSSpeechErrorOldestCharacterOffset_ = new NSString(bindings.NSSpeechErrorOldestCharacterOffset); +} + +NSString NSSpeechErrorNewestCode () +{ + if (NSSpeechErrorNewestCode_) + return NSSpeechErrorNewestCode_; + + return NSSpeechErrorNewestCode_ = new NSString(bindings.NSSpeechErrorNewestCode); +} + +NSString NSSpeechErrorNewestCharacterOffset () +{ + if (NSSpeechErrorNewestCharacterOffset_) + return NSSpeechErrorNewestCharacterOffset_; + + return NSSpeechErrorNewestCharacterOffset_ = new NSString(bindings.NSSpeechErrorNewestCharacterOffset); +} + +NSString NSSpeechSynthesizerInfoIdentifier () +{ + if (NSSpeechSynthesizerInfoIdentifier_) + return NSSpeechSynthesizerInfoIdentifier_; + + return NSSpeechSynthesizerInfoIdentifier_ = new NSString(bindings.NSSpeechSynthesizerInfoIdentifier); +} + +NSString NSSpeechSynthesizerInfoVersion () +{ + if (NSSpeechSynthesizerInfoVersion_) + return NSSpeechSynthesizerInfoVersion_; + + return NSSpeechSynthesizerInfoVersion_ = new NSString(bindings.NSSpeechSynthesizerInfoVersion); +} + +NSString NSSpeechPhonemeInfoOpcode () +{ + if (NSSpeechPhonemeInfoOpcode_) + return NSSpeechPhonemeInfoOpcode_; + + return NSSpeechPhonemeInfoOpcode_ = new NSString(bindings.NSSpeechPhonemeInfoOpcode); +} + +NSString NSSpeechPhonemeInfoSymbol () +{ + if (NSSpeechPhonemeInfoSymbol_) + return NSSpeechPhonemeInfoSymbol_; + + return NSSpeechPhonemeInfoSymbol_ = new NSString(bindings.NSSpeechPhonemeInfoSymbol); +} + +NSString NSSpeechPhonemeInfoExample () +{ + if (NSSpeechPhonemeInfoExample_) + return NSSpeechPhonemeInfoExample_; + + return NSSpeechPhonemeInfoExample_ = new NSString(bindings.NSSpeechPhonemeInfoExample); +} + +NSString NSSpeechPhonemeInfoHiliteStart () +{ + if (NSSpeechPhonemeInfoHiliteStart_) + return NSSpeechPhonemeInfoHiliteStart_; + + return NSSpeechPhonemeInfoHiliteStart_ = new NSString(bindings.NSSpeechPhonemeInfoHiliteStart); +} + +NSString NSSpeechPhonemeInfoHiliteEnd () +{ + if (NSSpeechPhonemeInfoHiliteEnd_) + return NSSpeechPhonemeInfoHiliteEnd_; + + return NSSpeechPhonemeInfoHiliteEnd_ = new NSString(bindings.NSSpeechPhonemeInfoHiliteEnd); +} + +NSString NSSpeechCommandPrefix () +{ + if (NSSpeechCommandPrefix_) + return NSSpeechCommandPrefix_; + + return NSSpeechCommandPrefix_ = new NSString(bindings.NSSpeechCommandPrefix); +} + +NSString NSSpeechCommandSuffix () +{ + if (NSSpeechCommandSuffix_) + return NSSpeechCommandSuffix_; + + return NSSpeechCommandSuffix_ = new NSString(bindings.NSSpeechCommandSuffix); +} + +NSString NSSpeechDictionaryLocaleIdentifier () +{ + if (NSSpeechDictionaryLocaleIdentifier_) + return NSSpeechDictionaryLocaleIdentifier_; + + return NSSpeechDictionaryLocaleIdentifier_ = new NSString(bindings.NSSpeechDictionaryLocaleIdentifier); +} + +NSString NSSpeechDictionaryModificationDate () +{ + if (NSSpeechDictionaryModificationDate_) + return NSSpeechDictionaryModificationDate_; + + return NSSpeechDictionaryModificationDate_ = new NSString(bindings.NSSpeechDictionaryModificationDate); +} + +NSString NSSpeechDictionaryPronunciations () +{ + if (NSSpeechDictionaryPronunciations_) + return NSSpeechDictionaryPronunciations_; + + return NSSpeechDictionaryPronunciations_ = new NSString(bindings.NSSpeechDictionaryPronunciations); +} + +NSString NSSpeechDictionaryAbbreviations () +{ + if (NSSpeechDictionaryAbbreviations_) + return NSSpeechDictionaryAbbreviations_; + + return NSSpeechDictionaryAbbreviations_ = new NSString(bindings.NSSpeechDictionaryAbbreviations); +} + +NSString NSSpeechDictionaryEntrySpelling () +{ + if (NSSpeechDictionaryEntrySpelling_) + return NSSpeechDictionaryEntrySpelling_; + + return NSSpeechDictionaryEntrySpelling_ = new NSString(bindings.NSSpeechDictionaryEntrySpelling); +} + +NSString NSSpeechDictionaryEntryPhonemes () +{ + if (NSSpeechDictionaryEntryPhonemes_) + return NSSpeechDictionaryEntryPhonemes_; + + return NSSpeechDictionaryEntryPhonemes_ = new NSString(bindings.NSSpeechDictionaryEntryPhonemes); +} + +enum +{ + NSSpeechImmediateBoundary = 0, + NSSpeechWordBoundary, + NSSpeechSentenceBoundary +} + +class NSSpeechSynthesizer : NSObject +{ + mixin (ObjcWrap); + + NSSpeechSynthesizer initWithVoice (NSString voice) + { + id result = invokeObjcSelf!(id, "initWithVoice:", NSString)(voice); + return result is this.objcObject ? this : (result !is null ? new NSSpeechSynthesizer(result) : null); + } + + this (NSString voice) + { + super(NSSpeechSynthesizer.alloc.initWithVoice(voice).objcObject); + } + + bool startSpeakingString (NSString string) + { + return invokeObjcSelf!(bool, "startSpeakingString:", NSString)(string); + } + + bool startSpeakingString (NSString string, NSURL url) + { + return invokeObjcSelf!(bool, "startSpeakingString:toURL:", NSString, NSURL)(string, url); + } + + bool isSpeaking () + { + return invokeObjcSelf!(bool, "isSpeaking"); + } + + void stopSpeaking () + { + return invokeObjcSelf!(void, "stopSpeaking"); + } + + void stopSpeakingAtBoundary (uint boundary) + { + return invokeObjcSelf!(void, "stopSpeakingAtBoundary:", uint)(boundary); + } + + void pauseSpeakingAtBoundary (uint boundary) + { + return invokeObjcSelf!(void, "pauseSpeakingAtBoundary:", uint)(boundary); + } + + void continueSpeaking () + { + return invokeObjcSelf!(void, "continueSpeaking"); + } + + Object delegate_ () + { + return invokeObjcSelf!(Object, "delegate"); + } + + void setDelegate (Object anObject) + { + return invokeObjcSelf!(void, "setDelegate:", Object)(anObject); + } + + NSString voice () + { + return invokeObjcSelf!(NSString, "voice"); + } + + bool setVoice (NSString voice) + { + return invokeObjcSelf!(bool, "setVoice:", NSString)(voice); + } + + float rate () + { + return invokeObjcSelf!(float, "rate"); + } + + void setRate (float rate) + { + return invokeObjcSelf!(void, "setRate:", float)(rate); + } + + float volume () + { + return invokeObjcSelf!(float, "volume"); + } + + void setVolume (float volume) + { + return invokeObjcSelf!(void, "setVolume:", float)(volume); + } + + bool usesFeedbackWindow () + { + return invokeObjcSelf!(bool, "usesFeedbackWindow"); + } + + void setUsesFeedbackWindow (bool flag) + { + return invokeObjcSelf!(void, "setUsesFeedbackWindow:", bool)(flag); + } + + void addSpeechDictionary (NSDictionary speechDictionary) + { + return invokeObjcSelf!(void, "addSpeechDictionary:", NSDictionary)(speechDictionary); + } + + NSString phonemesFromText (NSString text) + { + return invokeObjcSelf!(NSString, "phonemesFromText:", NSString)(text); + } + + Object objectForProperty (NSString property, out NSError outError) + { + id error; + + Object result = invokeObjcSelf!(Object, "objectForProperty:error:", NSString, id*)(property, &error); + + if (error) + outError = new NSError(error); + + return result; + } + + bool setObject (Object object, NSString property, ref NSError outError) + { + id error; + + bool result = invokeObjcSelf!(bool, "setObject:forProperty:error:", Object, NSString, id*)(object, property, &error); + + if (error) + outError = new NSError(error); + + return result; + } + + static bool isAnyApplicationSpeaking () + { + return invokeObjcSelfClass!(bool, "isAnyApplicationSpeaking"); + } + + static NSString defaultVoice () + { + return invokeObjcSelfClass!(NSString, "defaultVoice"); + } + + static NSArray availableVoices () + { + return invokeObjcSelfClass!(NSArray, "availableVoices"); + } + + static NSDictionary attributesForVoice (NSString voice) + { + return invokeObjcSelfClass!(NSDictionary, "attributesForVoice:", NSString)(voice); + } +} + +const TNSSpeechSynthesizerDelegate = ` + + void speechSynthesizer (NSSpeechSynthesizer sender, bool finishedSpeaking) + { + return invokeObjcSelf!(void, "speechSynthesizer:didFinishSpeaking:", NSSpeechSynthesizer, bool)(sender, finishedSpeaking); + } + + void speechSynthesizer (NSSpeechSynthesizer sender, NSRange characterRange, NSString string) + { + return invokeObjcSelf!(void, "speechSynthesizer:willSpeakWord:ofString:", NSSpeechSynthesizer, NSRange, NSString)(sender, characterRange, string); + } + + void speechSynthesizer (NSSpeechSynthesizer sender, short phonemeOpcode) + { + return invokeObjcSelf!(void, "speechSynthesizer:willSpeakPhoneme:", NSSpeechSynthesizer, short)(sender, phonemeOpcode); + } + + void speechSynthesizer (NSSpeechSynthesizer sender, NSUInteger characterIndex, NSString string, NSString message) + { + return invokeObjcSelf!(void, "speechSynthesizer:didEncounterErrorAtIndex:ofString:message:", NSSpeechSynthesizer, NSUInteger, NSString, NSString)(sender, characterIndex, string, message); + } + + void speechSynthesizer (NSSpeechSynthesizer sender, NSString message) + { + return invokeObjcSelf!(void, "speechSynthesizer:didEncounterSyncMessage:", NSSpeechSynthesizer, NSString)(sender, message); + } + + //mixin ObjcBindMethod!(speechSynthesizer, "speechSynthesizer:didFinishSpeaking:"); + //mixin ObjcBindMethod!(speechSynthesizer, "speechSynthesizer:willSpeakWord:ofString:"); + //mixin ObjcBindMethod!(speechSynthesizer, "speechSynthesizer:willSpeakPhoneme:"); + //mixin ObjcBindMethod!(speechSynthesizer, "speechSynthesizer:didEncounterErrorAtIndex:ofString:message:"); + //mixin ObjcBindMethod!(speechSynthesizer, "speechSynthesizer:didEncounterSyncMessage:"); + +`; +