public async Task <bool> RemoveSelectedEntries() { try { await _soundpad.RemoveSelectedEntries(true); return(true); } catch { return(false); } }
private async Task Play(string text) { Log.Debug($"Playing: {text}"); PlaySoundpadButton.IsEnabled = false; await SemaphoreSlim.WaitAsync(); try { var uniqueId = Guid.NewGuid().ToString().Replace("-", "").Clip(10); // Sanitize Filename var fileName = Regex.Replace(text.Clip(20), @"[^0-9A-Za-z ,]", "_", RegexOptions.Compiled); fileName = $"{fileName}_{uniqueId}.{Model.SelectedProvider.FileExtension}"; var filePath = Path.Combine(GetSavePath(), fileName); var stream = await Model.SelectedProvider.SynthesizeTextToStreamAsync(Model.SelectedVoice, text); using (var fileStream = File.Create(filePath)) { if (stream.CanSeek) { stream.Seek(0, SeekOrigin.Begin); } stream.CopyTo(fileStream); } var countResult = await _soundpad.GetSoundFileCount(); int count; await _soundpad.AddSound(filePath); while (true) { var result = await _soundpad.GetSoundFileCount(); if (result.Value != countResult.Value) { count = (int)result.Value; break; } } await _soundpad.PlaySound(count, Settings.Default.PlayRenderLine, Settings.Default.PlayCaptureLine); while (true) { var status = await _soundpad.GetPlayStatus(); if (status.Value == PlayStatus.Playing) { break; } } if (DeleteFromSoundpadCheckbox.IsChecked.HasValue && DeleteFromSoundpadCheckbox.IsChecked.Value) { await _soundpad.DoSelectIndex(count + 1); await Task.Delay(100); await _soundpad.RemoveSelectedEntries(); } } catch (Exception e) { Log.Error("Cannot play sound", e); SentrySdk.CaptureException(e); MessageBox.Show("There was an error during playback", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { SemaphoreSlim.Release(); PlaySoundpadButton.IsEnabled = true; } }