From 96252528b4b8dc6c1a8db6b0ef58d5ebaf5ff936 Mon Sep 17 00:00:00 2001 From: claude-bot Date: Fri, 1 May 2026 21:04:05 +0900 Subject: [PATCH] Fix Windows Media TTS async wait --- src/services/windows-media-tts.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/services/windows-media-tts.ts b/src/services/windows-media-tts.ts index 85fc010..496ef8a 100644 --- a/src/services/windows-media-tts.ts +++ b/src/services/windows-media-tts.ts @@ -25,12 +25,16 @@ function windowsMediaPreamble(): string { "Add-Type -AssemblyName System.Runtime.WindowsRuntime;", "$null = [Windows.Media.SpeechSynthesis.SpeechSynthesizer, Windows.Media.SpeechSynthesis, ContentType=WindowsRuntime];", "$null = [Windows.Storage.Streams.DataReader, Windows.Storage.Streams, ContentType=WindowsRuntime];", + "$null = [Windows.Foundation.AsyncStatus, Windows.Foundation, ContentType=WindowsRuntime];", "function Await-WinRt($operation) {", - " $method = [System.WindowsRuntimeSystemExtensions].GetMethods() | Where-Object { $_.Name -eq 'AsTask' -and $_.IsGenericMethod -and $_.GetParameters().Count -eq 1 } | Select-Object -First 1;", - " if (-not $method) { throw 'System.WindowsRuntimeSystemExtensions.AsTask 를 찾지 못했습니다.' }", - " $resultType = $operation.GetType().GenericTypeArguments[0];", - " $task = $method.MakeGenericMethod($resultType).Invoke($null, @($operation));", - " return $task.GetAwaiter().GetResult();", + " while ($operation.Status -eq [Windows.Foundation.AsyncStatus]::Started) { Start-Sleep -Milliseconds 10 }", + " if ($operation.Status -eq [Windows.Foundation.AsyncStatus]::Completed) { return $operation.GetResults() }", + " if ($operation.Status -eq [Windows.Foundation.AsyncStatus]::Canceled) { throw 'WinRT async operation canceled.' }", + " if ($operation.Status -eq [Windows.Foundation.AsyncStatus]::Error) {", + " if ($operation.ErrorCode) { throw $operation.ErrorCode }", + " throw 'WinRT async operation failed.'", + " }", + " throw ('Unexpected WinRT async status: ' + [string]$operation.Status)", "}", ].join(" "); }