Skip to content

Commit df4a7c9

Browse files
committed
テキストファイルの読み上げについて細かなバグ修正した
1 parent 7428242 commit df4a7c9

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

source/CeVIOAIProxy/CeVIOAIProxy.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
<AssemblyOriginatorKeyFile>CeVIOAIProxy.pfx</AssemblyOriginatorKeyFile>
1212
<Authors>anoyetta</Authors>
1313
<Copyright>(c) 2021 anoyetta</Copyright>
14-
<AssemblyVersion>1.3.0.0</AssemblyVersion>
14+
<AssemblyVersion>1.3.0.1</AssemblyVersion>
1515
<PackageIcon>share.ico</PackageIcon>
1616
<PackageIconUrl />
1717
<PackageProjectUrl>https://github.com/anoyetta/CeVIOAIProxy</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/anoyetta/CeVIOAIProxy.git</RepositoryUrl>
1919
<RepositoryType>GitHub</RepositoryType>
20-
<Version>1.3.0.0</Version>
20+
<Version>1.3.0.1</Version>
2121
<StartupObject>CeVIOAIProxy.App</StartupObject>
2222
<FileVersion>1.3.0.0</FileVersion>
2323
</PropertyGroup>

source/CeVIOAIProxy/MainViewModel.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using CeVIO.Talk.RemoteService2;
2-
using CeVIOAIProxy.Servers;
3-
using Microsoft.Win32;
4-
using Prism.Commands;
5-
using Prism.Mvvm;
61
using System.Collections.ObjectModel;
72
using System.IO;
83
using System.Linq;
94
using System.Net.Sockets;
105
using System.Text;
116
using System.Threading.Tasks;
7+
using CeVIO.Talk.RemoteService2;
8+
using CeVIOAIProxy.Servers;
9+
using Microsoft.Win32;
10+
using Prism.Commands;
11+
using Prism.Mvvm;
1212

1313
namespace CeVIOAIProxy
1414
{
@@ -72,6 +72,11 @@ public async void OnLoaded()
7272
CommentTextFileSubscriber.Current?.Start();
7373
}
7474
};
75+
76+
if (this.Config.IsEnabledTextPolling)
77+
{
78+
CommentTextFileSubscriber.Current?.Start();
79+
}
7580
}
7681

7782
private void SetCurrentComponents()

source/CeVIOAIProxy/Servers/CommentTextFileSubscriber.cs

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Text;
4+
using System.Threading.Tasks;
45

56
namespace CeVIOAIProxy.Servers
67
{
@@ -47,10 +48,9 @@ public void Start()
4748
this.watcher.Path = Path.GetDirectoryName(Config.Instance.CommentTextFilePath);
4849
this.watcher.Filter = Path.GetFileName(Config.Instance.CommentTextFilePath);
4950
this.watcher.IncludeSubdirectories = false;
50-
this.watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite;
51+
this.watcher.NotifyFilter = NotifyFilters.LastWrite;
5152
this.watcher.InternalBufferSize = 64 * 1024;
5253

53-
this.watcher.Created += this.Watcher_Created;
5454
this.watcher.Changed += this.Watcher_Changed;
5555

5656
this.watcher.EnableRaisingEvents = true;
@@ -70,8 +70,13 @@ public void Stop()
7070
}
7171
}
7272

73-
private async void Watcher_Created(object sender, FileSystemEventArgs e)
73+
private string lastComment = string.Empty;
74+
private DateTime lastCommentTimestamp = DateTime.MinValue;
75+
76+
private async void Watcher_Changed(object sender, FileSystemEventArgs e)
7477
{
78+
var comment = string.Empty;
79+
7580
lock (this)
7681
{
7782
if (!Config.Instance.IsEnabledTextPolling)
@@ -83,28 +88,46 @@ private async void Watcher_Created(object sender, FileSystemEventArgs e)
8388
{
8489
return;
8590
}
91+
8692
}
8793

88-
var comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
89-
await CeVIO.SpeakAsync(comment);
90-
}
94+
var interval = 10;
95+
var timeout = 1000;
9196

92-
private async void Watcher_Changed(object sender, FileSystemEventArgs e)
93-
{
94-
lock (this)
97+
for (int i = 0; i < (timeout / interval); i++)
9598
{
96-
if (!Config.Instance.IsEnabledTextPolling)
99+
try
97100
{
98-
return;
101+
comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
102+
break;
103+
}
104+
catch (IOException)
105+
{
106+
await Task.Delay(TimeSpan.FromMilliseconds(interval));
99107
}
108+
}
100109

101-
if (this.watcher == null)
110+
if (string.IsNullOrEmpty(comment))
111+
{
112+
return;
113+
}
114+
115+
lock (this)
116+
{
117+
var now = DateTime.Now;
118+
119+
if ((now - this.lastCommentTimestamp) < TimeSpan.FromSeconds(1))
102120
{
103-
return;
121+
if (this.lastComment.Equals(comment))
122+
{
123+
return;
124+
}
104125
}
126+
127+
this.lastComment = comment;
128+
this.lastCommentTimestamp = now;
105129
}
106130

107-
var comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
108131
await CeVIO.SpeakAsync(comment);
109132
}
110133
}

0 commit comments

Comments
 (0)