def _initTts(self, voice=None): self.tts=comtypes.client.CreateObject(self.COM_CLASS) if voice: # #749: It seems that SAPI 5 doesn't reset the audio parameters when the voice is changed, # but only when the audio output is changed. # Therefore, set the voice before setting the audio output. # Otherwise, we will get poor speech quality in some cases. self.tts.voice = voice outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True) if outputDeviceID>=0: self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID]
def _initTts(self, voice=None): self.tts=comtypes.client.CreateObject(self.COM_CLASS) if voice: # #749: It seems that SAPI 5 doesn't reset the audio parameters when the voice is changed, # but only when the audio output is changed. # Therefore, set the voice before setting the audio output. # Otherwise, we will get poor speech quality in some cases. self.tts.voice = voice outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True) if outputDeviceID>=0: self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID] from comInterfaces.SpeechLib import ISpAudio try: self.ttsAudioStream=self.tts.audioOutputStream.QueryInterface(ISpAudio) except COMError: log.debugWarning("SAPI5 voice does not support ISPAudio") self.ttsAudioStream=None
def _initTts(self, voice=None): self.tts=comtypes.client.CreateObject(self.COM_CLASS) if voice: # #749: It seems that SAPI 5 doesn't reset the audio parameters when the voice is changed, # but only when the audio output is changed. # Therefore, set the voice before setting the audio output. # Otherwise, we will get poor speech quality in some cases. self.tts.voice = voice outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True) if outputDeviceID>=0: self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID] self._eventsConnection = comtypes.client.GetEvents(self.tts, SapiSink(weakref.ref(self))) self.tts.EventInterests = constants.SVEBookmark | constants.SVEEndInputStream from comInterfaces.SpeechLib import ISpAudio try: self.ttsAudioStream=self.tts.audioOutputStream.QueryInterface(ISpAudio) except COMError: log.debugWarning("SAPI5 voice does not support ISPAudio") self.ttsAudioStream=None
def _set_voice(self,val): try: val=GUID(val) except: val=self._enginesList[0].gModeID mode=None for mode in self._enginesList: if mode.gModeID==val: break if mode is None: raise ValueError("no such mode: %s"%val) self._currentMode=mode self._ttsAudio=CoCreateInstance(CLSID_MMAudioDest,IAudioMultiMediaDevice) self._ttsAudio.DeviceNumSet(nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True)) self._ttsCentral=POINTER(ITTSCentralW)() self._ttsEngines.Select(self._currentMode.gModeID,byref(self._ttsCentral),self._ttsAudio) self._ttsAttrs=self._ttsCentral.QueryInterface(ITTSAttributes) #Find out rate limits hasRate=bool(mode.dwFeatures&TTSFEATURE_SPEED) if hasRate: try: oldVal=DWORD() self._ttsAttrs.SpeedGet(byref(oldVal)) self._ttsAttrs.SpeedSet(TTSATTR_MINSPEED) newVal=DWORD() self._ttsAttrs.SpeedGet(byref(newVal)) self._minRate=newVal.value self._ttsAttrs.SpeedSet(TTSATTR_MAXSPEED) self._ttsAttrs.SpeedGet(byref(newVal)) # ViaVoice (and perhaps other synths) doesn't seem to like the speed being set to maximum. self._maxRate=newVal.value-1 self._ttsAttrs.SpeedSet(oldVal.value) if self._maxRate<=self._minRate: hasRate=False except COMError: hasRate=False if hasRate: if not self.isSupported('rate'): self.supportedSettings.insert(1,SynthDriver.RateSetting()) else: if self.isSupported("rate"): self.removeSetting("rate") #Find out pitch limits hasPitch=bool(mode.dwFeatures&TTSFEATURE_PITCH) if hasPitch: try: oldVal=WORD() self._ttsAttrs.PitchGet(byref(oldVal)) self._ttsAttrs.PitchSet(TTSATTR_MINPITCH) newVal=WORD() self._ttsAttrs.PitchGet(byref(newVal)) self._minPitch=newVal.value self._ttsAttrs.PitchSet(TTSATTR_MAXPITCH) self._ttsAttrs.PitchGet(byref(newVal)) self._maxPitch=newVal.value self._ttsAttrs.PitchSet(oldVal.value) if self._maxPitch<=self._minPitch: hasPitch=False except COMError: hasPitch=False if hasPitch: if not self.isSupported('pitch'): self.supportedSettings.insert(2,SynthDriver.PitchSetting()) else: if self.isSupported('pitch'): self.removeSetting('pitch') #Find volume limits hasVolume=bool(mode.dwFeatures&TTSFEATURE_VOLUME) if hasVolume: try: oldVal=DWORD() self._ttsAttrs.VolumeGet(byref(oldVal)) self._ttsAttrs.VolumeSet(TTSATTR_MINVOLUME) newVal=DWORD() self._ttsAttrs.VolumeGet(byref(newVal)) self._minVolume=newVal.value self._ttsAttrs.VolumeSet(TTSATTR_MAXVOLUME) self._ttsAttrs.VolumeGet(byref(newVal)) self._maxVolume=newVal.value self._ttsAttrs.VolumeSet(oldVal.value) if self._maxVolume<=self._minVolume: hasVolume=False except COMError: hasVolume=False if hasVolume: if not self.isSupported('volume'): self.supportedSettings.insert(3,SynthDriver.VolumeSetting()) else: if self.isSupported('volume'): self.removeSetting('volume')
def _initTts(self): self.tts=comtypes.client.CreateObject(COM_CLASS) outputDeviceID=nvwave.outputDeviceNameToID(config.conf["speech"]["outputDevice"], True) if outputDeviceID>=0: self.tts.audioOutput=self.tts.getAudioOutputs()[outputDeviceID]