Skip to content

Commit 9c1af21

Browse files
Add volume setting
1 parent 89e4f4e commit 9c1af21

File tree

16 files changed

+100
-26
lines changed

16 files changed

+100
-26
lines changed

src/TrackerCouncil.Smz3.Abstractions/TrackerCouncil.Smz3.Abstractions.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@
1111
<ProjectReference Include="..\TrackerCouncil.Smz3.Shared\TrackerCouncil.Smz3.Shared.csproj" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<PackageReference Include="PySpeechServiceClient" Version="0.0.35" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<Folder Include="Speech\" />
20+
</ItemGroup>
21+
1422
</Project>

src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public class GeneralOptions : INotifyPropertyChanged
4949
[Range(0.0, 1.0)]
5050
public float TrackerConfidenceSassThreshold { get; set; } = 0.92f;
5151

52+
[Range(0, 100)]
53+
public int TextToSpeechVolume { get; set; } = 100;
54+
5255
public byte[] TrackerBGColor { get; set; } = [0xFF, 0x21, 0x21, 0x21];
5356

5457
public bool TrackerShadows { get; set; } = true;
@@ -256,6 +259,7 @@ public bool Validate()
256259
MinimumRecognitionConfidence = TrackerRecognitionThreshold,
257260
MinimumExecutionConfidence = TrackerConfidenceThreshold,
258261
MinimumSassConfidence = TrackerConfidenceSassThreshold,
262+
TextToSpeechVolume = TextToSpeechVolume,
259263
HintsEnabled = TrackerHintsEnabled,
260264
SpoilersEnabled = TrackerSpoilersEnabled,
261265
UserName = TwitchChannel,

src/TrackerCouncil.Smz3.Data/Options/TrackerOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public record TrackerOptions
3434
/// </summary>
3535
public float MinimumSassConfidence { get; set; } = 0.92f;
3636

37+
/// <summary>
38+
/// Gets or sets the volume of the text to speech engine, with 0
39+
/// being silent and 100 being the default max valume.
40+
/// </summary>
41+
public int TextToSpeechVolume { get; set; } = 100;
42+
3743
/// <summary>
3844
/// Gets or sets a value indicating whether Tracker can give hints when
3945
/// asked about an item or location.

src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowTrackerOptions.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using DynamicForms.Library.Core;
34
using DynamicForms.Library.Core.Attributes;
45
using MSURandomizerLibrary;
@@ -12,36 +13,44 @@ namespace TrackerCouncil.Smz3.Data.ViewModels;
1213
[DynamicFormGroupBasic(DynamicFormLayout.TwoColumns, "Bottom")]
1314
public class OptionsWindowTrackerOptions
1415
{
15-
[DynamicFormFieldColorPicker(label: "Tracker background color:")]
16+
[DynamicFormFieldColorPicker(order: 0, label: "Tracker background color:")]
1617
public byte[] TrackerBGColor { get; set; } = [0xFF, 0x21, 0x21, 0x21];
1718

18-
[DynamicFormFieldCheckBox(checkBoxText: "Render shadows", alignment: DynamicFormAlignment.Right)]
19+
[DynamicFormFieldCheckBox(order: 1, checkBoxText: "Render shadows", alignment: DynamicFormAlignment.Right)]
1920
public bool TrackerShadows { get; set; } = true;
2021

21-
[DynamicFormFieldComboBox(label: "Tracker speech window image pack:",
22-
comboBoxOptionsProperty: nameof(TrackerSpeechImagePacks))]
22+
[DynamicFormFieldComboBox(order: 2, label: "Tracker speech window image pack:",
23+
comboBoxOptionsProperty: nameof(TrackerSpeechImagePacks), platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
2324
public string TrackerSpeechImagePack { get; set; } = "Default";
2425

25-
[DynamicFormFieldColorPicker(label: "Tracker speech window color:")]
26+
[DynamicFormFieldColorPicker(order: 3, label: "Tracker speech window color:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
2627
public byte[] TrackerSpeechBGColor { get; set; } = [0xFF, 0x48, 0x3D, 0x8B];
2728

28-
[DynamicFormFieldCheckBox(checkBoxText: "Enable speech bounce animation", alignment: DynamicFormAlignment.Right)]
29+
[DynamicFormFieldCheckBox(order: 4, checkBoxText: "Enable speech bounce animation", alignment: DynamicFormAlignment.Right, platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
2930
public bool TrackerSpeechEnableBounce { get; set; } = true;
3031

31-
[DynamicFormFieldSlider(minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker recognition threshold:")]
32+
[DynamicFormFieldSlider(order: 5, minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker recognition threshold:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
3233
public float TrackerRecognitionThreshold { get; set; }
3334

34-
[DynamicFormFieldSlider(minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker execution threshold:")]
35+
[DynamicFormFieldSlider(order: 6, minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker execution threshold:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
3536
public float TrackerConfidenceThreshold { get; set; }
3637

37-
[DynamicFormFieldSlider(minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker spoiler threshold:")]
38+
[DynamicFormFieldSlider(order: 7, minimumValue: 0, maximumValue:100, decimalPlaces:1, incrementAmount:.1, suffix:"%", label: "Tracker spoiler threshold:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
3839
public float TrackerConfidenceSassThreshold { get; set; }
3940

40-
[DynamicFormFieldComboBox(label: "Tracker voice frequency:")]
41+
[DynamicFormFieldSlider(order: 8, minimumValue: 0, maximumValue:100, decimalPlaces:0, incrementAmount:1, suffix:"%", label: "Text to speech volume:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
42+
public int TextToSpeechVolume { get; set; }
43+
44+
#pragma warning disable CS0067 // Event is never used
45+
[DynamicFormFieldButton(order: 9, buttonText: "Test Tracker Voice", alignment: DynamicFormAlignment.Right, platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
46+
public event EventHandler? TestTextToSpeechPressed;
47+
#pragma warning restore CS0067 // Event is never used
48+
49+
[DynamicFormFieldComboBox(label: "Tracker voice frequency:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
4150
public TrackerVoiceFrequency TrackerVoiceFrequency { get; set; }
4251

4352
[DynamicFormFieldComboBox(label: "Speech recognition mode:",
44-
comboBoxOptionsProperty: nameof(SpeechRecognitionTypes))]
53+
comboBoxOptionsProperty: nameof(SpeechRecognitionTypes), platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
4554
public string SpeechRecognitionMode { get; set; } = "";
4655

4756
[DynamicFormFieldComboBox(label: "Push-to-talk key:", platforms: DynamicFormPlatform.Windows)]
@@ -50,7 +59,7 @@ public class OptionsWindowTrackerOptions
5059
[DynamicFormFieldComboBox(label: "Push-to-talk device:", comboBoxOptionsProperty: nameof(AudioDevices), platforms: DynamicFormPlatform.Windows)]
5160
public string PushToTalkDevice { get; set; } = "";
5261

53-
[DynamicFormFieldNumericUpDown(minValue: 0, label: "Undo expiration time:")]
62+
[DynamicFormFieldNumericUpDown(minValue: 0, label: "Undo expiration time:", platforms: DynamicFormPlatform.Windows & DynamicFormPlatform.Linux)]
5463
public int UndoExpirationTime { get; set; } = 3;
5564

5665
[DynamicFormFieldFilePicker(FilePickerType.Folder, label: "Auto tracker scripts folder:", dialogText: "Select auto tracker scripts folder")]

src/TrackerCouncil.Smz3.Data/ViewModels/OptionsWindowViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public OptionsWindowViewModel(GeneralOptions options, Dictionary<string, string>
4848
TrackerOptions.TrackerRecognitionThreshold = options.TrackerRecognitionThreshold * 100;
4949
TrackerOptions.TrackerConfidenceThreshold = options.TrackerConfidenceThreshold * 100;
5050
TrackerOptions.TrackerConfidenceSassThreshold = options.TrackerConfidenceSassThreshold * 100;
51+
TrackerOptions.TextToSpeechVolume = options.TextToSpeechVolume;
5152
TrackerOptions.TrackerVoiceFrequency = options.TrackerVoiceFrequency;
5253
TrackerOptions.SpeechRecognitionMode = options.SpeechRecognitionMode.ToString();
5354
TrackerOptions.PushToTalkKey = options.PushToTalkKey;
@@ -110,6 +111,7 @@ public void UpdateOptions(GeneralOptions options)
110111
options.TrackerRecognitionThreshold = TrackerOptions.TrackerRecognitionThreshold / 100;
111112
options.TrackerConfidenceThreshold = TrackerOptions.TrackerConfidenceThreshold / 100;
112113
options.TrackerConfidenceSassThreshold = TrackerOptions.TrackerConfidenceSassThreshold / 100;
114+
options.TextToSpeechVolume = TrackerOptions.TextToSpeechVolume;
113115
options.TrackerVoiceFrequency = TrackerOptions.TrackerVoiceFrequency;
114116
options.SpeechRecognitionMode = speechRecognitionMode;
115117
options.PushToTalkKey = TrackerOptions.PushToTalkKey;

src/TrackerCouncil.Smz3.Tools/TrackerCouncil.Smz3.Tools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="NJsonSchema" Version="11.0.2" />
1212
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
1313
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21216.1" />
14-
<PackageReference Include="YamlDotNet" Version="16.1.3" />
14+
<PackageReference Include="YamlDotNet" Version="16.3.0" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Speech.Synthesis;
32

43
namespace TrackerCouncil.Smz3.Tracking.Services;
54

@@ -59,7 +58,13 @@ public void SlowDown() { }
5958
/// <summary>
6059
/// If the TTS is currently speaking
6160
/// </summary>
62-
public bool IsSpeaking { get; }
61+
public bool IsSpeaking { get; }
62+
63+
/// <summary>
64+
/// Updates the volume of the text to speech engine.
65+
/// </summary>
66+
/// <param name="volume">New volume between 0-100 with 0 being silent and 100 being the default max value.</param>
67+
public void UpdateVolume(int volume);
6368

6469
/// <summary>
6570
/// Event for when the communicator has started speaking

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Threading.Tasks;
34
using PySpeechServiceClient;
45
using PySpeechServiceClient.Models;
56
using TrackerCouncil.Smz3.Data.Options;
@@ -15,6 +16,7 @@ internal class PyTextToSpeechCommunicator : ICommunicator
1516
private double _rate = 1;
1617
private bool _isEnabled;
1718
private bool _isSpeaking;
19+
private int volume;
1820

1921
public PyTextToSpeechCommunicator(IPySpeechService pySpeechService, TrackerOptionsAccessor trackerOptionsAccessor)
2022
{
@@ -30,11 +32,12 @@ public PyTextToSpeechCommunicator(IPySpeechService pySpeechService, TrackerOptio
3032
_altVoice = maleDetails ?? femaleDetails;
3133
}
3234

33-
_ = _pySpeechService.SetSpeechSettingsAsync(new SpeechSettings());
35+
volume = trackerOptionsAccessor.Options?.TextToSpeechVolume ?? 100;
36+
_ = Initialize();
3437

3538
_pySpeechService.Initialized += (_, _) =>
3639
{
37-
_pySpeechService.SetSpeechSettingsAsync(GetSpeechSettings());
40+
_ = Initialize();
3841
};
3942

4043
_pySpeechService.SpeakCommandResponded += (_, args) =>
@@ -72,6 +75,12 @@ public void UseAlternateVoice()
7275
(_primaryVoice, _altVoice) = (_altVoice, _primaryVoice);
7376
}
7477

78+
private async Task Initialize()
79+
{
80+
await _pySpeechService.SetSpeechSettingsAsync(GetSpeechSettings());
81+
await _pySpeechService.SetVolumeAsync(volume / 100.0);
82+
}
83+
7584
private SpeechSettings GetSpeechSettings()
7685
{
7786
return new SpeechSettings
@@ -144,6 +153,12 @@ public void Abort()
144153

145154
public bool IsSpeaking => _isSpeaking;
146155

156+
public void UpdateVolume(int newVolume)
157+
{
158+
volume = newVolume;
159+
_ = _pySpeechService.SetVolumeAsync(newVolume / 100.0f);
160+
}
161+
147162
public event EventHandler? SpeakStarted;
148163
public event EventHandler<SpeakCompletedEventArgs>? SpeakCompleted;
149164
public event EventHandler<SpeakingUpdatedEventArgs>? VisemeReached;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Speech.Synthesis;
32

43
namespace TrackerCouncil.Smz3.Tracking.Services;
54

src/TrackerCouncil.Smz3.Tracking/Services/Speech/PySpeechRecognitionService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private async Task StartPySpeechRecognition()
8080
{
8181
try
8282
{
83-
await pySpeechService.StartSpeechRecognitionAsync(requiredConfidence: _minRequiredConfidence);
83+
await pySpeechService.StartSpeechRecognitionAsync(requiredConfidence: _minRequiredConfidence * 100);
8484
}
8585
catch (Exception)
8686
{

0 commit comments

Comments
 (0)