diff --git a/src/TMSpeech.Core/ConfigTypes.cs b/src/TMSpeech.Core/ConfigTypes.cs index 556144b..76a7fa4 100644 --- a/src/TMSpeech.Core/ConfigTypes.cs +++ b/src/TMSpeech.Core/ConfigTypes.cs @@ -8,14 +8,16 @@ public static class GeneralConfigTypes public const string LaunchOnStartup = "general.LaunchOnStartup"; public const string StartOnLaunch = "general.StartOnLaunch"; public const string AutoUpdate = "general.AutoUpdate"; + public const string ResultLogPath = "general.ResultLogPath"; private static Dictionary _defaultConfig => new() { { Language, "zh-cn" }, { LaunchOnStartup, false }, - { StartOnLaunch, false }, - { AutoUpdate, true } + { StartOnLaunch, true }, + { AutoUpdate, true }, + { ResultLogPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TMSpeechLogs") } }; public static Dictionary DefaultConfig => _defaultConfig; diff --git a/src/TMSpeech.Core/JobManager.cs b/src/TMSpeech.Core/JobManager.cs index 13663ce..d3c3a61 100644 --- a/src/TMSpeech.Core/JobManager.cs +++ b/src/TMSpeech.Core/JobManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using TMSpeech.Core.Plugins; @@ -65,6 +66,7 @@ internal JobManagerImpl() private IRecognizer? _recognizer; private HashSet _sensitiveWords; private bool _disableInThisSentence = false; + private string logFile; private void InitAudioSource() { @@ -111,6 +113,12 @@ private void InitRecognizer() private void OnRecognizerOnSentenceDone(object? sender, SpeechEventArgs args) { + // Save the sentense to log + if (logFile != null && logFile.Length > 0) + { + File.AppendAllText(logFile, string.Format("{0:T}: {1}\n", DateTime.Now, args.Text.Text)); + } + _disableInThisSentence = false; OnSentenceDone(args); } @@ -167,6 +175,16 @@ private void StartRecognize() return; } + var logPath = ConfigManagerFactory.Instance.Get(GeneralConfigTypes.ResultLogPath).Trim(); + if (logPath.Length > 0) + { + Directory.CreateDirectory(logPath); + logFile = Path.Combine(logPath, string.Format("{0:yy-MM-dd-HH-mm-ss}.txt", DateTime.Now)); + } else + { + logFile = ""; + } + if (Status == JobStatus.Stopped) RunningSeconds = 0; Status = JobStatus.Running; diff --git a/src/TMSpeech.GUI/App.axaml.cs b/src/TMSpeech.GUI/App.axaml.cs index 200649d..20369ec 100644 --- a/src/TMSpeech.GUI/App.axaml.cs +++ b/src/TMSpeech.GUI/App.axaml.cs @@ -1,9 +1,13 @@ using System; using System.Linq; +using System.Reactive.Concurrency; +using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.Threading; +using ReactiveUI; using TMSpeech.Core; using TMSpeech.GUI.ViewModels; using TMSpeech.GUI.Views; @@ -49,6 +53,12 @@ public override void OnFrameworkInitializationCompleted() if (!Design.IsDesignMode) { Core.Plugins.PluginManagerFactory.GetInstance().LoadPlugins(); + + // Run recognizer if config is set. + if (ConfigManagerFactory.Instance.Get(GeneralConfigTypes.StartOnLaunch)) + { + Dispatcher.UIThread.Post(() => { _mainWindow.ViewModel.PlayCommand.Execute(); }); + } } } } \ No newline at end of file diff --git a/src/TMSpeech.GUI/ViewModels/ConfigViewModel.cs b/src/TMSpeech.GUI/ViewModels/ConfigViewModel.cs index 25414c8..3cc9b72 100644 --- a/src/TMSpeech.GUI/ViewModels/ConfigViewModel.cs +++ b/src/TMSpeech.GUI/ViewModels/ConfigViewModel.cs @@ -157,6 +157,10 @@ public class GeneralSectionConfigViewModel : SectionConfigViewModelBase //[ConfigJsonValue] //public string UserDir { get; set; } = "D:\\TMSpeech"; + [Reactive] + [ConfigJsonValue] + public string ResultLogPath { get; set; } + [Reactive] [ConfigJsonValue] public bool LaunchOnStartup { get; set; } diff --git a/src/TMSpeech.GUI/Views/ConfigWindow.axaml b/src/TMSpeech.GUI/Views/ConfigWindow.axaml index 092c36a..bd8a7f5 100644 --- a/src/TMSpeech.GUI/Views/ConfigWindow.axaml +++ b/src/TMSpeech.GUI/Views/ConfigWindow.axaml @@ -38,15 +38,15 @@ - + 通用 - - - + + @@ -58,13 +58,16 @@ --> - - + + - - + + + + +