Skip to content

Commit 3756523

Browse files
feat: Adding slider for playback speed based on tests
Tested some settings and examples and it looks like the tempo is the best way of fast forwarding. Following the rule that tempo +50 == 2x playback speed. You can fast forward with rate but it makes you sound like the chipmunks. You can kind of fix it at lower rates by lowering the pitch but even at 2x speeds its an obvious distortion pitch aside. You can also fast forward with beats per minute but it almost seems time dependant on the length of the TTS and I didn't want to research an equation. The effect on TTS, when set close to correctly, sounds no different to me than changing the tempo. closes #69
1 parent 7bdad5d commit 3756523

File tree

3 files changed

+102
-10
lines changed

3 files changed

+102
-10
lines changed

src/TwitchStreamingTools/ViewModels/Pages/ChatViewModel.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ from user in _selectedTwitchChatNames
169169
OutputDevice = Configuration.GetDefaultAudioDevice(),
170170
TtsOn = true,
171171
TtsVoice = Configuration.GetDefaultTtsVoice(),
172-
TtsVolume = 100
172+
TtsVolume = 50
173173
}).ToList();
174174

175175
_configuration.WriteConfiguration();
@@ -194,7 +194,7 @@ from user in _selectedTwitchChatNames
194194
OutputDevice = Configuration.GetDefaultAudioDevice(),
195195
TtsOn = true,
196196
TtsVoice = Configuration.GetDefaultTtsVoice(),
197-
TtsVolume = 100
197+
TtsVolume = 50
198198
}).ToList();
199199

200200
_configuration.WriteConfiguration();
@@ -267,6 +267,10 @@ private void PopulateChatHistory() {
267267
/// Connects to the twitch chats in the configuration file.
268268
/// </summary>
269269
private void InitializeTwitchChatConnections() {
270+
if (Design.IsDesignMode) {
271+
return;
272+
}
273+
270274
foreach (TwitchChatConfiguration channel in _configuration.TwitchChats ?? []) {
271275
if (string.IsNullOrWhiteSpace(channel.TwitchChannel)) {
272276
continue;

src/TwitchStreamingTools/ViewModels/Pages/SettingsView/SettingsViewModel.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Collections.ObjectModel;
34
using System.Linq;
5+
using System.Reactive;
46
using System.Speech.Synthesis;
57

68
using ReactiveUI;
@@ -59,6 +61,16 @@ public class SettingsViewModel : PageViewModelBase {
5961
/// </summary>
6062
private string? _selectedTtsVoice;
6163

64+
/// <summary>
65+
/// True if the advanced Text-to-Speech (TTS) settings are displayed.
66+
/// </summary>
67+
private bool _showAdvancedTts;
68+
69+
/// <summary>
70+
/// The speed (as a multiplicative).
71+
/// </summary>
72+
private double _speed;
73+
6274
/// <summary>
6375
/// Change sound tempo by n percents (-95 to +5000 %)
6476
/// </summary>
@@ -98,6 +110,16 @@ public SettingsViewModel(IConfiguration configuration, TtsPhoneticWordsViewModel
98110
_ttsPhoneticWordsViewModel = ttsPhoneticWordsViewModel;
99111
_ttsSkipUsernamesViewModel = ttsSkipUsernamesViewModel;
100112
_configuration.SoundStretchArgs ??= new SoundStretchArgs();
113+
_tempo = _configuration.SoundStretchArgs.Tempo ?? 0;
114+
_pitch = _configuration.SoundStretchArgs.Pitch ?? 0;
115+
_rate = _configuration.SoundStretchArgs.Rate ?? 0;
116+
_bpm = _configuration.SoundStretchArgs.Bpm ?? 0;
117+
_quick = _configuration.SoundStretchArgs.Quick;
118+
_antiAliasingOff = _configuration.SoundStretchArgs.AntiAliasingOff;
119+
_turnOnSpeech = _configuration.SoundStretchArgs.TurnOnSpeech;
120+
_speed = (Tempo / 50.0) + 1.0;
121+
122+
ToggleAdvancedTtsCommand = ReactiveCommand.Create(() => ShowAdvancedTts = !ShowAdvancedTts);
101123

102124
// Get the list of output devices and set the default to either what we have in the configuration or the system
103125
// default whichever is more appropriate.
@@ -305,4 +327,36 @@ public bool TurnOnSpeech {
305327
}
306328
}
307329
}
330+
331+
/// <summary>
332+
/// True if we are displaying the advanced TTS settings, false otherwise.
333+
/// </summary>
334+
public bool ShowAdvancedTts {
335+
get => _showAdvancedTts;
336+
set => this.RaiseAndSetIfChanged(ref _showAdvancedTts, value);
337+
}
338+
339+
/// <summary>
340+
/// Called when the show advanced settings is clicked.
341+
/// </summary>
342+
public ReactiveCommand<Unit, bool> ToggleAdvancedTtsCommand { protected set; get; }
343+
344+
/// <summary>
345+
/// The speed to play the TTS
346+
/// </summary>
347+
public double Speed {
348+
get => _speed;
349+
set {
350+
this.RaiseAndSetIfChanged(ref _speed, value);
351+
352+
// In terms of tempo, 50 is 100% faster (2x speed). Scaling that equation linearly, we get:
353+
double tempo = (value - 1.0) * 50;
354+
355+
if (_configuration.SoundStretchArgs != null) {
356+
Tempo = (int)Math.Round(tempo);
357+
}
358+
359+
_configuration.WriteConfiguration();
360+
}
361+
}
308362
}

src/TwitchStreamingTools/Views/Pages/SettingsView/SettingsView.axaml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<RowDefinition Height="Auto" />
2020
<RowDefinition Height="Auto" />
2121
<RowDefinition Height="Auto" />
22+
<RowDefinition Height="Auto" />
2223
<RowDefinition />
2324
</Grid.RowDefinitions>
2425
<Grid.ColumnDefinitions>
@@ -74,17 +75,50 @@
7475
IsSnapToTickEnabled="True"
7576
Value="{Binding TtsVolume}" />
7677
</Grid>
77-
78-
7978
<Label Grid.Row="3"
8079
Grid.Column="0"
8180
HorizontalAlignment="Right"
8281
VerticalAlignment="Top"
83-
Margin="0 5 0 0">
84-
Advanced TTS Playback:
82+
Margin="0 12 0 0">
83+
TTS Playback Speed:
8584
</Label>
8685
<Grid Grid.Row="3"
8786
Grid.Column="1">
87+
<Grid.ColumnDefinitions>
88+
<ColumnDefinition Width="Auto" />
89+
<ColumnDefinition Width="*" />
90+
</Grid.ColumnDefinitions>
91+
<TextBlock Grid.Column="0"
92+
VerticalAlignment="Center"
93+
HorizontalAlignment="Center"
94+
Text="{Binding #Speed.Value, StringFormat={}{0:F2}x}"
95+
Margin="0 0 10 0" />
96+
<Slider Grid.Column="1"
97+
x:Name="Speed"
98+
TickFrequency="0.1"
99+
SmallChange="0.1"
100+
LargeChange="1.0"
101+
IsSnapToTickEnabled="True"
102+
Minimum="-0.5"
103+
Maximum="3"
104+
Value="{Binding Speed}" />
105+
</Grid>
106+
<Label Grid.Row="4"
107+
Grid.Column="0"
108+
HorizontalAlignment="Right"
109+
VerticalAlignment="Top"
110+
Margin="0 5 0 0">
111+
Advanced TTS Playback:
112+
</Label>
113+
<Button Grid.Row="4"
114+
Grid.Column="1"
115+
IsVisible="{Binding !ShowAdvancedTts}"
116+
Command="{Binding ToggleAdvancedTtsCommand}">
117+
Show Options
118+
</Button>
119+
<Grid Grid.Row="4"
120+
Grid.Column="1"
121+
IsVisible="{Binding ShowAdvancedTts}">
88122
<Grid>
89123
<Grid.ColumnDefinitions>
90124
<ColumnDefinition Width="Auto" />
@@ -150,25 +184,25 @@
150184
IsChecked="{Binding TurnOnSpeech}" />
151185
</Grid>
152186
</Grid>
153-
<Label Grid.Row="4"
187+
<Label Grid.Row="5"
154188
Grid.Column="0"
155189
HorizontalAlignment="Right"
156190
VerticalAlignment="Top"
157191
Margin="0 5 0 0">
158192
Skip User TTS:
159193
</Label>
160-
<Grid Grid.Row="4"
194+
<Grid Grid.Row="5"
161195
Grid.Column="1">
162196
<settingsView:TtsSkipUsernamesControl Margin="0,0,5,0" DataContext="{Binding TtsSkipUsernamesViewModel}" />
163197
</Grid>
164-
<Label Grid.Row="5"
198+
<Label Grid.Row="6"
165199
Grid.Column="0"
166200
HorizontalAlignment="Right"
167201
VerticalAlignment="Top"
168202
Margin="0 5 0 0">
169203
Phonetic Spellings:
170204
</Label>
171-
<Grid Grid.Row="5"
205+
<Grid Grid.Row="6"
172206
Grid.Column="1">
173207
<settingsView:TtsPhoneticWordsControl Margin="0,0,5,0" DataContext="{Binding TtsPhoneticWordsViewModel}" />
174208
</Grid>

0 commit comments

Comments
 (0)