Skip to content

Commit

Permalink
テキストファイルの読み上げについて細かなバグ修正した
Browse files Browse the repository at this point in the history
  • Loading branch information
anoyetta committed Nov 12, 2021
1 parent 7428242 commit df4a7c9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
4 changes: 2 additions & 2 deletions source/CeVIOAIProxy/CeVIOAIProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
<AssemblyOriginatorKeyFile>CeVIOAIProxy.pfx</AssemblyOriginatorKeyFile>
<Authors>anoyetta</Authors>
<Copyright>(c) 2021 anoyetta</Copyright>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<AssemblyVersion>1.3.0.1</AssemblyVersion>
<PackageIcon>share.ico</PackageIcon>
<PackageIconUrl />
<PackageProjectUrl>https://github.com/anoyetta/CeVIOAIProxy</PackageProjectUrl>
<RepositoryUrl>https://github.com/anoyetta/CeVIOAIProxy.git</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Version>1.3.0.0</Version>
<Version>1.3.0.1</Version>
<StartupObject>CeVIOAIProxy.App</StartupObject>
<FileVersion>1.3.0.0</FileVersion>
</PropertyGroup>
Expand Down
15 changes: 10 additions & 5 deletions source/CeVIOAIProxy/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using CeVIO.Talk.RemoteService2;
using CeVIOAIProxy.Servers;
using Microsoft.Win32;
using Prism.Commands;
using Prism.Mvvm;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using CeVIO.Talk.RemoteService2;
using CeVIOAIProxy.Servers;
using Microsoft.Win32;
using Prism.Commands;
using Prism.Mvvm;

namespace CeVIOAIProxy
{
Expand Down Expand Up @@ -72,6 +72,11 @@ public async void OnLoaded()
CommentTextFileSubscriber.Current?.Start();
}
};

if (this.Config.IsEnabledTextPolling)
{
CommentTextFileSubscriber.Current?.Start();
}
}

private void SetCurrentComponents()
Expand Down
51 changes: 37 additions & 14 deletions source/CeVIOAIProxy/Servers/CommentTextFileSubscriber.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;

namespace CeVIOAIProxy.Servers
{
Expand Down Expand Up @@ -47,10 +48,9 @@ public void Start()
this.watcher.Path = Path.GetDirectoryName(Config.Instance.CommentTextFilePath);
this.watcher.Filter = Path.GetFileName(Config.Instance.CommentTextFilePath);
this.watcher.IncludeSubdirectories = false;
this.watcher.NotifyFilter = NotifyFilters.CreationTime | NotifyFilters.LastWrite;
this.watcher.NotifyFilter = NotifyFilters.LastWrite;
this.watcher.InternalBufferSize = 64 * 1024;

this.watcher.Created += this.Watcher_Created;
this.watcher.Changed += this.Watcher_Changed;

this.watcher.EnableRaisingEvents = true;
Expand All @@ -70,8 +70,13 @@ public void Stop()
}
}

private async void Watcher_Created(object sender, FileSystemEventArgs e)
private string lastComment = string.Empty;
private DateTime lastCommentTimestamp = DateTime.MinValue;

private async void Watcher_Changed(object sender, FileSystemEventArgs e)
{
var comment = string.Empty;

lock (this)
{
if (!Config.Instance.IsEnabledTextPolling)
Expand All @@ -83,28 +88,46 @@ private async void Watcher_Created(object sender, FileSystemEventArgs e)
{
return;
}

}

var comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
await CeVIO.SpeakAsync(comment);
}
var interval = 10;
var timeout = 1000;

private async void Watcher_Changed(object sender, FileSystemEventArgs e)
{
lock (this)
for (int i = 0; i < (timeout / interval); i++)
{
if (!Config.Instance.IsEnabledTextPolling)
try
{
return;
comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
break;
}
catch (IOException)
{
await Task.Delay(TimeSpan.FromMilliseconds(interval));
}
}

if (this.watcher == null)
if (string.IsNullOrEmpty(comment))
{
return;
}

lock (this)
{
var now = DateTime.Now;

if ((now - this.lastCommentTimestamp) < TimeSpan.FromSeconds(1))
{
return;
if (this.lastComment.Equals(comment))
{
return;
}
}

this.lastComment = comment;
this.lastCommentTimestamp = now;
}

var comment = File.ReadAllText(e.FullPath, new UTF8Encoding(false));
await CeVIO.SpeakAsync(comment);
}
}
Expand Down

0 comments on commit df4a7c9

Please sign in to comment.