diff --git a/src/Speech/Controller/VOICEPEAKEnumerator.cs b/src/Speech/Controller/VOICEPEAKEnumerator.cs index d9bf66d..c75cda7 100644 --- a/src/Speech/Controller/VOICEPEAKEnumerator.cs +++ b/src/Speech/Controller/VOICEPEAKEnumerator.cs @@ -1,9 +1,11 @@ using Microsoft.Win32; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -25,6 +27,10 @@ public VOICEPEAKEnumerator() private string[] ExecuteVoicepeak(string args) { + if (string.IsNullOrEmpty(path)) + { + return new string[0]; + } ProcessStartInfo psInfo = new ProcessStartInfo(); psInfo.FileName = path; @@ -33,15 +39,29 @@ private string[] ExecuteVoicepeak(string args) psInfo.RedirectStandardOutput = true; psInfo.Arguments = args; - using (Process p = Process.Start(psInfo)) + try { - // Voicepeakは非同期実行されるのでプロセス終了後に標準出力を取り出す - p.WaitForExit(10); + using (Process p = Process.Start(psInfo)) + { + // Voicepeakは非同期実行されるのでプロセス終了後に標準出力を取り出す + p.WaitForExit(10); - // 行の整形 - string[] stdout = p.StandardOutput.ReadToEnd().Split('\n'); - string[] output = stdout.Where(x => x.Trim().Length > 0).Select(x => x.Trim()).ToArray(); - return output; + // 行の整形 + string[] stdout = p.StandardOutput.ReadToEnd().Split('\n'); + string[] output = stdout.Where(x => x.Trim().Length > 0).Select(x => x.Trim()).ToArray(); + return output; + } + } + catch (Win32Exception e) + { + int error = Marshal.GetLastWin32Error(); + switch (error) + { + case 2: + // ERROR_FILE_NOT_FOUND + return new string[0]; + } + throw e; } }