Skip to content

Commit 8f038d6

Browse files
Fix tracker sprite not updating
1 parent a3a1859 commit 8f038d6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/TrackerCouncil.Smz3.Tracking/Services/PyTextToSpeechCommunicator.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Concurrent;
3+
using System.Collections.Generic;
24
using System.IO;
35
using System.Threading.Tasks;
46
using PySpeechServiceClient;
@@ -17,6 +19,7 @@ internal class PyTextToSpeechCommunicator : ICommunicator
1719
private bool _isEnabled;
1820
private bool _isSpeaking;
1921
private int volume;
22+
private ConcurrentDictionary<string, SpeechRequest> _pendingRequests = [];
2023

2124
public PyTextToSpeechCommunicator(IPySpeechService pySpeechService, TrackerOptionsAccessor trackerOptionsAccessor)
2225
{
@@ -42,13 +45,15 @@ public PyTextToSpeechCommunicator(IPySpeechService pySpeechService, TrackerOptio
4245

4346
_pySpeechService.SpeakCommandResponded += (_, args) =>
4447
{
48+
_pendingRequests.TryGetValue(args.Response.FullMessage, out var request);
49+
4550
if (args.Response.IsStartOfChunk)
4651
{
47-
VisemeReached?.Invoke(this, new SpeakingUpdatedEventArgs(true, null));
52+
VisemeReached?.Invoke(this, new SpeakingUpdatedEventArgs(true, request));
4853
}
4954
else if (args.Response.IsEndOfChunk)
5055
{
51-
VisemeReached?.Invoke(this, new SpeakingUpdatedEventArgs(false, null));
56+
VisemeReached?.Invoke(this, new SpeakingUpdatedEventArgs(false, request));
5257
}
5358

5459
if (args.Response.IsStartOfMessage)
@@ -60,6 +65,12 @@ public PyTextToSpeechCommunicator(IPySpeechService pySpeechService, TrackerOptio
6065
{
6166
SpeakCompleted?.Invoke(this, new SpeakCompletedEventArgs(TimeSpan.FromSeconds(3)));
6267

68+
if (request != null)
69+
{
70+
_pendingRequests.TryRemove(
71+
new KeyValuePair<string, SpeechRequest>(args.Response.FullMessage, request));
72+
}
73+
6374
if (!args.Response.HasAnotherRequest)
6475
{
6576
_isSpeaking = false;
@@ -109,6 +120,8 @@ public void Say(SpeechRequest request)
109120
{
110121
if (!_isEnabled || !_pySpeechService.IsSpeechEnabled) return;
111122

123+
_pendingRequests.TryAdd(request.Text, request);
124+
112125
if (request.Wait)
113126
{
114127
_pySpeechService.Speak(request.Text, GetSpeechSettings());

0 commit comments

Comments
 (0)