public MainViewModel(Options options) { _synthesizer = new SpeechSynthesizer(); _synthesizer.StateChanged += (_, __) => State.Value = _synthesizer.State; Voices = new List <InstalledVoice>(_synthesizer.GetInstalledVoices()); SelectedVoice.Value = Voices.First(); Document = new TextDocumentViewModel(); if (File.Exists(options.InputPath)) { Document.Open(options.InputPath); } SelectedExport.Subscribe(OnExportChanged); var exportToFilePath = ""; if (!String.IsNullOrWhiteSpace(options.OutputPath)) { exportToFilePath = options.OutputPath; } else if (!String.IsNullOrWhiteSpace(options.InputPath)) { exportToFilePath = options.InputPath + ".wav"; } Exports = new ObservableCollection <IExport> { new ExportToDefaultAudioDeviceViewModel(), new ExportToFileViewModel { FilePath = { Value = exportToFilePath } }, }; foreach (var export in Exports) { export.SpeechSynthesizer.Value = _synthesizer; } if (!String.IsNullOrWhiteSpace(options.OutputPath)) { SelectedExport.Value = Exports[1]; } else { SelectedExport.Value = Exports[0]; } SpeakCommand = new RelayCommand(Speak); StopSpeakingCommand = new RelayCommand(StopSpeaking); PauseSpeakingCommand = new RelayCommand(PauseSpeaking); SelectedVoice.Subscribe(voice => _synthesizer.SelectVoice(voice.VoiceInfo.Name)); }
public SettingsViewModel() { if (SelectedVoice == null || !SelectedVoice.StartsWith(selectedLanguageCode)) { SelectedVoice = Voices[0]; } else { EventSystem.Subscribe <OnlineVoicesLoaded>(OnOnlineVoicesLoaded); } EventSystem.Subscribe <AudioUpdated>(OnAudioUpdated); }