public VoiceroidEngine() { Program.Logger.Info("VOICEROID init started..."); process = GetOrCreateVoiceroidProcess(); app = new WindowsAppFriend(process); try { // Timeout = 60 sec for (var i = 0; i < 1200; i++) { var window = app.FromZTop(); WinApi.ShowWindow(window.Handle, WinApi.SwMinimize); var tree = window.GetFromTypeFullName("AI.Talk.Editor.TextEditView") .FirstOrDefault() ?.LogicalTree(); if (tree == null) { Thread.Sleep(50); continue; } var text = tree.ByType <TextBox>().Single(); var play = tree.ByBinding("PlayCommand").Single(); var stop = tree.ByBinding("StopCommand").Single(); // var move = tree.ByBinding("MoveToBeginningCommand").Single(); talkTextBox = new WPFTextBox(text); playButton = new WPFButtonBase(play); stopButton = new WPFButtonBase(stop); moveButton = new WPFButtonBase(tree[15]); // moveButton = new WPFButtonBase(move); Program.Logger.Info("VOICEROID ready!"); Task.Run(ConsumeAsync); return; } } catch (Exception exception) { Program.Logger.Error(exception); throw new ApplicationException("VOICEROID init failed."); } throw new TimeoutException("VOICEROID init timed out."); }