private static Task NotifySoundAsync( string notice, NoticeDevices device, bool isSync = false, float?volume = null, double?delay = null) => Task.Run(async() => { if (delay.HasValue && delay.Value > 0) { await Task.Delay(TimeSpan.FromSeconds(delay.Value)); } NotifySound(notice, device, isSync, volume); });
private static void NotifySound( string notice, NoticeDevices device, bool isSync = false, float?volume = null) { if (string.IsNullOrEmpty(notice)) { return; } if (TimelineSettings.Instance.IsMute) { return; } if (volume.HasValue && volume <= 0) { return; } lock (NoticeLocker) { if (lastNotice == notice) { if ((DateTime.Now - lastNoticeTimestamp).TotalSeconds <= 0.1) { return; } } lastNotice = notice; lastNoticeTimestamp = DateTime.Now; } var isWave = notice.EndsWith(".wav", StringComparison.OrdinalIgnoreCase) || notice.EndsWith(".wave", StringComparison.OrdinalIgnoreCase) || notice.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase); if (isWave) { if (!File.Exists(notice)) { notice = Path.Combine( SoundController.Instance.WaveDirectory, notice); } } else { notice = TTSDictionary.Instance.ReplaceWordsTTS(notice); } switch (device) { case NoticeDevices.Both: if (PlayBridge.Instance.IsAvailable) { PlayBridge.Instance.Play(notice, isSync, volume); break; } if (isWave) { ActGlobals.oFormActMain.PlaySound(notice); } else { ActGlobals.oFormActMain.TTS(notice); } break; case NoticeDevices.Main: PlayBridge.Instance.PlayMain(notice, isSync, volume); break; case NoticeDevices.Sub: PlayBridge.Instance.PlaySub(notice, isSync, volume); break; } #if DEBUG System.Diagnostics.Debug.WriteLine($"{DateTime.Now:HH:mm:ss.fff} notify={notice}"); #endif }