This sample adapts PyWinRT's text-to-speech example to generated dynwinrt bindings. It demonstrates:
- native Python
asyncioover a WinRT asynchronous operation; - structural interface typing that passes
SpeechSynthesisStreamdirectly whereIRandomAccessStreamis required; - a typed
MediaPlayer.MediaEndedcallback; and - deterministic COM/WinRT cleanup.
- Windows 10 or 11 with a Windows SDK installed;
dynwinrtinstalled in the selected Python interpreter; anddynwinrt-codegenonPATH, or passed togenerate.ps1with-Codegen.
Generate the bindings:
.\generate.ps1 -Codegen ..\..\..\target\release\dynwinrt-codegen.exePlay synthesized speech:
.\run.ps1 -Python C:\path\to\python.exe -Text "Hello from dynwinrt."For non-interactive validation, synthesize the stream without playing it:
.\run.ps1 -Python C:\path\to\python.exe -Smoke