pywinrt / python-winsdk

Python package with bindings for Windows SDK
https://python-winsdk.readthedocs.io
MIT License
74 stars 8 forks source link

Missing SpeechSynthesizer.get_all_voices #30

Closed n0h4rt closed 1 year ago

n0h4rt commented 1 year ago

As the title suggests, the SpeechSynthesizer does not have both the get_all_voices and get_default_voice methods. The last known working version was 1.0.0b6.

import winsdk.windows.media.speechsynthesis as wms

synthesizer = wms.SpeechSynthesizer()

voices = synthesizer.get_all_voices()  # raises AttributeError

default_voice = synthesizer.get_default_voice()  # raises AttributeError
dlech commented 1 year ago

Static properties were "fixed" in beta 8 to be class attributes instead of methods.

synthesizer.get_all_voices() should be replaced with SpeechSynthesizer.all_voices and synthesizer.get_default_voice() should be replaced with SpeechSynthesizer.default_voice.

n0h4rt commented 1 year ago

Same results.

AttributeError: 'SpeechSynthesizer' object has no attribute 'all_voices' AttributeError: 'SpeechSynthesizer' object has no attribute 'default_voice'

Here is the dir().

import winsdk.windows.media.speechsynthesis as wms

dir(wms.SpeechSynthesizer)
# ['__class__', '__delattr__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_assign_array_', '_from', 'close', 'options', 'synthesize_ssml_to_stream_async', 'synthesize_text_to_stream_async', 'try_set_default_voice_async', 'voice']
dlech commented 1 year ago

Static properties won't show up in dir() because they are defined in a meta class.

Which version of Python and winsdk are you using?

dlech commented 1 year ago

Did you actually write SpeechSynthesizer.all_voices and not synthesizer.all_voices?

>>> import winsdk.windows.media.speechsynthesis as wms
>>> [x.display_name for x in wms.SpeechSynthesizer.all_voices]
['Microsoft David', 'Microsoft Zira', 'Microsoft Mark']
n0h4rt commented 1 year ago

Which version of Python and winsdk are you using?

I'm using Python-3.10 and winsdk-1.0.0b8.

Did you actually write SpeechSynthesizer.all_voices and not synthesizer.all_voices?

I'm sorry, I didn't know that instantiated SpeechSynthesizer behaved differently than its constructor. I thought it was the same class.

[x.display_name for x in wms.SpeechSynthesizer.all_voices]

I just tested this and it works. You have my thanks :)