Skip to content

Commit 013b57d

Browse files
committed
Narrate history
1 parent 3620d0e commit 013b57d

File tree

8 files changed

+168
-6
lines changed

8 files changed

+168
-6
lines changed

DemoApp/App.xaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,23 @@
8383
</Style>
8484

8585

86-
86+
<Style x:Key="AudioDropZoneStyle" TargetType="{x:Type Border}">
87+
<Setter Property="AllowDrop" Value="False"/>
88+
<Setter Property="BorderBrush" Value="Transparent"/>
89+
<Setter Property="BorderThickness" Value="1"/>
90+
<Style.Triggers>
91+
<MultiDataTrigger>
92+
<MultiDataTrigger.Conditions>
93+
<Condition Binding="{Binding IsDragDrop, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="True" />
94+
<Condition Binding="{Binding DragDropType, RelativeSource={RelativeSource AncestorType=CommonControls:ViewControl}}" Value="Audio" />
95+
</MultiDataTrigger.Conditions>
96+
<MultiDataTrigger.Setters>
97+
<Setter Property="AllowDrop" Value="True"/>
98+
<Setter Property="BorderBrush" Value="{StaticResource AccentColour2}"/>
99+
</MultiDataTrigger.Setters>
100+
</MultiDataTrigger>
101+
</Style.Triggers>
102+
</Style>
87103

88104

89105
<Style x:Key="ToggleButtonBasic" TargetType="{x:Type ToggleButton}">

DemoApp/Common/MediaType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
public enum MediaType
44
{
55
Image = 0,
6-
Video = 1
6+
Video = 1,
7+
Audio = 2
78
}
89
}

DemoApp/Common/NarrateItem.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace DemoApp.Common
4+
{
5+
public class NarrateItem : HistoryItem
6+
{
7+
public string Model { get; init; }
8+
public string Voice { get; init; }
9+
public int Seed { get; init; }
10+
public float Speed { get; init; }
11+
public int Steps { get; init; }
12+
public int Channels { get; init; }
13+
public int SampleRate { get; init; }
14+
public TimeSpan Duration { get; init; }
15+
public string InputText { get; init; }
16+
}
17+
}

DemoApp/Controls/HistoryControl.xaml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,89 @@
339339
</Grid>
340340
</DataTemplate>
341341

342+
343+
344+
<!--NarrateItem-->
345+
<DataTemplate DataType="{x:Type Common:NarrateItem}">
346+
<Grid x:Name="Root" Background="Transparent" >
347+
<DockPanel Height="150" Width="110" >
348+
<Grid DockPanel.Dock="Top">
349+
350+
<Grid Width="110" Height="110">
351+
<CommonControls:FontAwesome Icon="f001" IconStyle="Solid" Size="70" Color="{StaticResource DefaultForeground}" Opacity=".2" />
352+
</Grid>
353+
354+
<Button Width="30" Height="30"
355+
Style="{StaticResource TransparentButton}"
356+
HorizontalAlignment="Right"
357+
VerticalAlignment="Bottom"
358+
Visibility="{Binding IsMouseOver, ElementName=Root, Converter={StaticResource BooleanToHiddenConverter}}"
359+
Command="{Binding RemoveItemCommand, RelativeSource={RelativeSource AncestorType=Controls:HistoryControl}}"
360+
CommandParameter="{Binding}">
361+
<CommonControls:FontAwesome Icon="&#xe2b4;" IconStyle="Solid" Size="20" Color="{StaticResource DangerColour}" />
362+
</Button>
363+
</Grid>
364+
<StackPanel>
365+
<TextBlock TextAlignment="Center">
366+
<Run Text="{Binding Duration}" />
367+
</TextBlock>
368+
<TextBlock Text="{Binding Source}" TextAlignment="Center" />
369+
</StackPanel>
370+
</DockPanel>
371+
372+
373+
<!-- Popup card -->
374+
<Popup x:Name="CardPopup"
375+
Height="120"
376+
Width="242"
377+
VerticalOffset="16"
378+
HorizontalOffset="-5"
379+
Placement="Top"
380+
StaysOpen="True"
381+
PopupAnimation="Slide"
382+
AllowsTransparency="True" >
383+
<Border Background="#01000000" Margin="0,0,0,0">
384+
<Border Margin="0,0,0,18" Background="#80000000" BorderBrush="{StaticResource ContainerBorder}" BorderThickness="1,1,1,0" CornerRadius="6,6,0,0">
385+
<StackPanel Margin="6,4,6,6">
386+
<TextBlock Text="{Binding Source}" />
387+
<TextBlock Text="{Binding Model, StringFormat={}Model: {0}}" />
388+
<TextBlock Text="{Binding Voice, StringFormat={}Voice: {0}}" />
389+
<TextBlock Text="{Binding Seed, StringFormat={}Seed: {0}}" />
390+
<TextBlock Text="{Binding Speed, StringFormat={}Speed: {0}}" />
391+
<TextBlock Text="{Binding Steps, StringFormat={}Steps: {0}}" />
392+
<TextBlock Text="{Binding Channels, StringFormat={}Channels: {0}}" />
393+
<TextBlock Text="{Binding SampleRate, StringFormat={}SampleRate: {0}}" />
394+
<TextBlock Text="{Binding Duration, StringFormat={}Duration: {0}}" />
395+
<TextBlock Text="{Binding MediaPath}" />
396+
</StackPanel>
397+
</Border>
398+
</Border>
399+
</Popup>
400+
401+
<!-- Hover triggers -->
402+
<Grid.Triggers>
403+
<EventTrigger RoutedEvent="MouseEnter">
404+
<BeginStoryboard>
405+
<Storyboard>
406+
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="CardPopup" Storyboard.TargetProperty="IsOpen">
407+
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="True"/>
408+
</BooleanAnimationUsingKeyFrames>
409+
</Storyboard>
410+
</BeginStoryboard>
411+
</EventTrigger>
412+
<EventTrigger RoutedEvent="MouseLeave">
413+
<BeginStoryboard>
414+
<Storyboard>
415+
<BooleanAnimationUsingKeyFrames Storyboard.TargetName="CardPopup" Storyboard.TargetProperty="IsOpen">
416+
<DiscreteBooleanKeyFrame KeyTime="0:0:0" Value="False"/>
417+
</BooleanAnimationUsingKeyFrames>
418+
</Storyboard>
419+
</BeginStoryboard>
420+
</EventTrigger>
421+
</Grid.Triggers>
422+
</Grid>
423+
</DataTemplate>
424+
342425
</CommonControls:BaseControl.Resources>
343426

344427
<Grid DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:HistoryControl}}}">

DemoApp/Controls/HistoryControl.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ protected void ListBoxPreviewMouseMove(object sender, MouseEventArgs e)
180180
{
181181
MediaType.Image => DragDropType.Image,
182182
MediaType.Video => DragDropType.Video,
183+
MediaType.Audio => DragDropType.Audio,
183184
_ => throw new NotSupportedException()
184185
};
185186

DemoApp/Services/HistoryService.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using DemoApp;
2-
using DemoApp.Common;
1+
using DemoApp.Common;
32
using DemoApp.Views;
43
using System;
54
using System.Collections.ObjectModel;
65
using System.IO;
76
using System.Linq;
87
using System.Threading.Tasks;
8+
using TensorStack.Audio;
99
using TensorStack.Common.Common;
1010
using TensorStack.Image;
1111
using TensorStack.Video;
@@ -55,6 +55,8 @@ public async Task InitializeAsync()
5555
historyItem = await Json.LoadAsync<LayerImageItem>(historyFile.FullName);
5656
if (historyFile.Name.StartsWith("Diffusion_"))
5757
historyItem = await Json.LoadAsync<DiffusionItem>(historyFile.FullName);
58+
if (historyFile.Name.StartsWith("Narrate_"))
59+
historyItem = await Json.LoadAsync<NarrateItem>(historyFile.FullName);
5860
if (historyItem == null)
5961
continue;
6062

@@ -153,6 +155,23 @@ public async Task<VideoInputStream> AddAsync<T>(VideoInputStream videoStream, T
153155
}
154156

155157

158+
/// <summary>
159+
/// Add new Audio to the history timeline
160+
/// </summary>
161+
/// <typeparam name="T"></typeparam>
162+
/// <param name="audio">The audio.</param>
163+
/// <param name="history">The history.</param>
164+
/// <returns>A Task&lt;AudioInput&gt; representing the asynchronous operation.</returns>
165+
public async Task<AudioInput> AddAsync<T>(AudioInput audio, T history) where T : HistoryItem
166+
{
167+
SetSavePath(history);
168+
await audio.SaveAsync(history.MediaPath);
169+
await Json.SaveAsync<T>(history, history.FilePath);
170+
_historyCollection.Add(history);
171+
return audio;
172+
}
173+
174+
156175
/// <summary>
157176
/// Gets the save path.
158177
/// </summary>
@@ -169,6 +188,8 @@ private void SetSavePath(HistoryItem history)
169188

170189
View.VideoUpscale => "Upscale",
171190
View.VideoExtractor => "Extractor",
191+
192+
View.AudioNarrate => "Narrate",
172193
_ => throw new NotImplementedException()
173194
};
174195

@@ -182,13 +203,16 @@ private void SetSavePath(HistoryItem history)
182203

183204
View.VideoUpscale => _settings.DirectoryHistory,
184205
View.VideoExtractor => _settings.DirectoryHistory,
206+
207+
View.AudioNarrate => _settings.DirectoryHistory,
185208
_ => throw new NotImplementedException()
186209
});
187210

188211
var extension = history.MediaType switch
189212
{
190213
MediaType.Image => "png",
191214
MediaType.Video => "mp4",
215+
MediaType.Audio => "wav",
192216
_ => throw new NotImplementedException()
193217
};
194218

@@ -212,5 +236,6 @@ public interface IHistoryService
212236

213237
Task<ImageInput> AddAsync<T>(ImageInput image, T history) where T : HistoryItem;
214238
Task<VideoInputStream> AddAsync<T>(VideoInputStream videoStream, T history) where T : HistoryItem;
239+
Task<AudioInput> AddAsync<T>(AudioInput audio, T history) where T : HistoryItem;
215240
}
216241
}

DemoApp/Views/AudioNarrateView.xaml.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private async Task ExecuteAsync()
9898
Progress.Indeterminate("Generating Results...");
9999
try
100100
{
101+
// Generate Result
101102
var result = await NarrateService.ExecuteAsync(new NarrateRequest
102103
{
103104
InputText = _inputText,
@@ -107,7 +108,23 @@ private async Task ExecuteAsync()
107108
VoiceStyle = _selectedVoice
108109
});
109110

110-
AudioResult = new AudioInput(result);
111+
// Save History
112+
var resultAudio = new AudioInput(result);
113+
AudioResult = await HistoryService.AddAsync(resultAudio, new NarrateItem
114+
{
115+
Source = View.AudioNarrate,
116+
MediaType = MediaType.Audio,
117+
Model = _currentPipeline.NarrateModel.Name,
118+
Voice = _selectedVoice,
119+
Seed = _seed,
120+
Speed = _speed,
121+
Steps = _steps,
122+
Channels = resultAudio.Channels,
123+
SampleRate = resultAudio.SampleRate,
124+
Duration = resultAudio.Duration,
125+
InputText = _inputText,
126+
Timestamp = DateTime.UtcNow
127+
});
111128

112129
Debug.WriteLine($"[{GetType().Name}] [ExecuteAsync] - Complete: {Stopwatch.GetElapsedTime(timestamp)}");
113130
}

DemoApp/Views/AudioTranscribeView.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
<!--Audio Input-->
5656
<StackPanel DockPanel.Dock="Top">
5757
<TextBlock Text="Audio Input" Style="{StaticResource FieldTextBlockStyle}" />
58-
<CommonControls:AudioElement Source="{Binding AudioInput, Mode=TwoWay}" Configuration="{Binding Settings}" IsReplayEnabled="False" />
58+
<Border Style="{StaticResource AudioDropZoneStyle}">
59+
<CommonControls:AudioElement Source="{Binding AudioInput, Mode=TwoWay}" Configuration="{Binding Settings}" IsReplayEnabled="False" />
60+
</Border>
5961
</StackPanel>
6062

6163
<!--Advanced-->

0 commit comments

Comments
 (0)