Skip to content

Commit

Permalink
redesign gui, add file dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed May 21, 2022
1 parent 757b2a1 commit 014798c
Show file tree
Hide file tree
Showing 15 changed files with 386 additions and 88 deletions.
8 changes: 4 additions & 4 deletions TranscripterLib/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ open STTClient

module Transcripter =
let deleteIfExists filePath =
if File.Exists(filePath) then
File.Delete(filePath)
if File.Exists filePath then
File.Delete filePath

let public transcribe (inputPath: string) =
let tempAudioOutputPath = FileSystem.GetTempFileName()

if FFMpeg.ExtractAudio(inputPath, tempAudioOutputPath) then
let modelFile = Path.Combine(Environment.CurrentDirectory, @"model\english_huge_1.0.0_model.tflite")

if File.Exists(modelFile) then
if File.Exists modelFile then
let client = new STT(modelFile)

let tempAudioFile = File.ReadAllBytes(tempAudioOutputPath)
let buffer = WaveBuffer(tempAudioFile)
let buffer = WaveBuffer tempAudioFile
let bufferSize = Convert.ToUInt32(buffer.MaxSize / 2)

let result = client.SpeechToTextWithMetadata(buffer, bufferSize, 1u)
Expand Down
6 changes: 5 additions & 1 deletion TranscripterUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Resources>
<FontFamily x:Key="OpenSans">avares://TranscripterUI/Assets/Fonts/OpenSans/OpenSans-Regular.ttf</FontFamily>
</Application.Resources>

<Application.Styles>
<FluentTheme Mode="Dark"/>

<StyleInclude Source="avares://TranscripterUI/BoxIcons.axaml"/>
<StyleInclude Source="avares://TranscripterUI/ButtonStyles.axaml"/>
</Application.Styles>
</Application>
88 changes: 88 additions & 0 deletions TranscripterUI/Assets/Fonts/OpenSans/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)

-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font
creation efforts of academic and linguistic communities, and to
provide a free and open framework in which fonts may be shared and
improved in partnership with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply to
any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software
components as distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to,
deleting, or substituting -- in part or in whole -- any of the
components of the Original Version, by changing formats or by porting
the Font Software to a new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed,
modify, redistribute, and sell modified and unmodified copies of the
Font Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components, in
Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the
corresponding Copyright Holder. This restriction only applies to the
primary font name as presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created using
the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.
2 changes: 1 addition & 1 deletion TranscripterUI/BoxIcons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@
<GeometryDrawing x:Key="BoxIcons.RegularPlay" Brush="#ff2c2f33" Geometry="M2.441E-007,0 L2.441E-007,16 L13.33,8 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlayCircle" Brush="#ff2c2f33" Geometry="M8,-1.465E-007 C3.589,-1.465E-007 -3.433E-009,3.589 -3.433E-009,8 C-3.433E-009,12.41 3.589,16 8,16 C12.41,16 16,12.41 16,8 C16,3.589 12.41,-1.465E-007 8,-1.465E-007 z M8,14.4 C4.471,14.4 1.6,11.53 1.6,8 C1.6,4.471 4.471,1.6 8,1.6 C11.53,1.6 14.4,4.471 14.4,8 C14.4,11.53 11.53,14.4 8,14.4 z M5.6,12 L12,8 L5.6,4 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlug" Brush="#ff2c2f33" Geometry="M1.874E-05,4.8 L1.6,4.8 L1.6,8.8 C1.6,10.56 3.035,12 4.8,12 L6.4,12 L6.4,16 L8,16 L8,12 L9.6,12 C11.36,12 12.8,10.56 12.8,8.8 L12.8,4.8 L14.4,4.8 L14.4,3.2 L-1.030E-008,3.2 L-1.030E-008,4.8 z M3.2,4.8 L11.2,4.8 L11.2,8.8 C11.2,9.682 10.48,10.4 9.6,10.4 L4.8,10.4 C3.918,10.4 3.2,9.682 3.2,8.8 L3.2,4.8 z M3.2,-1.465E-007 L4.8,-1.465E-007 L4.8,2.4 L3.2,2.4 z M9.6,-1.465E-007 L11.2,-1.465E-007 L11.2,2.4 L9.6,2.4 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlus" Brush="#ff2c2f33" Geometry="M16,6.857 L9.143,6.857 L9.143,-2.093E-007 L6.857,-2.093E-007 L6.857,6.857 L9.809E-009,6.857 L9.809E-009,9.143 L6.857,9.143 L6.857,16 L9.143,16 L9.143,9.143 L16,9.143 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlus" Brush="#ff99AAB5" Geometry="M16,6.857 L9.143,6.857 L9.143,-2.093E-007 L6.857,-2.093E-007 L6.857,6.857 L9.809E-009,6.857 L9.809E-009,9.143 L6.857,9.143 L6.857,16 L9.143,16 L9.143,9.143 L16,9.143 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlusCircle" Brush="#ff2c2f33" Geometry="M8.8,4 L7.2,4 L7.2,7.2 L4,7.2 L4,8.8 L7.2,8.8 L7.2,12 L8.8,12 L8.8,8.8 L12,8.8 L12,7.2 L8.8,7.2 z M8,-1.465E-007 C3.589,-1.465E-007 -3.433E-009,3.589 -3.433E-009,8 C-3.433E-009,12.41 3.589,16 8,16 C12.41,16 16,12.41 16,8 C16,3.589 12.41,-1.465E-007 8,-1.465E-007 z M8,14.4 C4.471,14.4 1.6,11.53 1.6,8 C1.6,4.471 4.471,1.6 8,1.6 C11.53,1.6 14.4,4.471 14.4,8 C14.4,11.53 11.53,14.4 8,14.4 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPlusMedical" Brush="#ff2c2f33" Geometry="M10.4,-9.155E-009 L5.6,-9.155E-009 L5.6,5.59 L-3.433E-009,5.59 L-3.433E-009,10.39 L5.6,10.39 L5.6,15.98 L10.4,15.98 L10.4,10.39 L16,10.39 L16,5.59 L10.4,5.59 z"/>
<GeometryDrawing x:Key="BoxIcons.RegularPodcast" Brush="#ff2c2f33" Geometry="M9.561,8 C9.561,8.884 8.845,9.6 7.961,9.6 C7.077,9.6 6.361,8.884 6.361,8 C6.361,7.116 7.077,6.4 7.961,6.4 C8.845,6.4 9.561,7.116 9.561,8 z M7.161,16 L8.761,16 L9.161,10.4 L6.761,10.4 L7.161,16 z M7.953,-1.465E-007 C3.555,0.0267 -3.319E-008,3.598 -3.319E-008,8 C-3.319E-008,11.7 2.519,14.82 5.937,15.73 L5.993,15.74 L5.873,14.05 C3.34,13.16 1.557,10.79 1.557,7.997 C1.557,4.462 4.422,1.597 7.957,1.597 C11.49,1.597 14.36,4.462 14.36,7.997 C14.36,10.79 12.57,13.16 10.09,14.03 L10.04,14.05 L9.921,15.74 C13.4,14.82 15.91,11.7 15.91,8 C15.91,3.595 12.35,0.02229 7.955,1.86E-05 L7.953,1.86E-05 z M10.61,6.088 C10.72,6.245 10.82,6.424 10.9,6.614 L10.9,6.632 C10.98,6.803 11.04,7.004 11.09,7.212 L11.09,7.232 C11.13,7.423 11.16,7.643 11.16,7.869 C11.16,7.87 11.16,7.871 11.16,7.872 L11.16,7.872 C11.16,7.873 11.16,7.874 11.16,7.875 C11.16,8.103 11.13,8.326 11.09,8.54 L11.09,8.52 C11.04,8.748 10.98,8.949 10.9,9.14 L10.9,9.12 C10.82,9.328 10.72,9.507 10.6,9.673 L10.61,9.664 C10.52,9.792 10.42,9.904 10.33,10.01 L10.33,10.01 L10.18,12.1 C10.36,12.02 10.51,11.94 10.66,11.85 L10.64,11.86 C11.16,11.51 11.6,11.08 11.94,10.58 L11.95,10.56 C12.11,10.33 12.26,10.07 12.38,9.789 L12.39,9.76 C12.51,9.503 12.6,9.2 12.67,8.887 L12.67,8.856 C12.72,8.591 12.75,8.285 12.75,7.973 C12.75,7.938 12.75,7.902 12.75,7.867 L12.75,7.872 C12.75,7.528 12.71,7.194 12.64,6.871 L12.65,6.904 C12.52,6.256 12.28,5.682 11.94,5.174 L11.95,5.192 C11.77,4.926 11.58,4.693 11.37,4.479 L11.37,4.48 C11.16,4.267 10.92,4.074 10.67,3.906 L10.66,3.896 C10.43,3.736 10.16,3.586 9.888,3.461 L9.857,3.448 C9.59,3.345 9.275,3.258 8.95,3.204 L8.921,3.2 C8.631,3.139 8.298,3.104 7.957,3.104 C7.616,3.104 7.283,3.139 6.961,3.205 L6.993,3.2 C6.65,3.271 6.347,3.37 6.061,3.499 L6.089,3.488 C5.782,3.619 5.519,3.766 5.274,3.938 L5.289,3.928 C5.022,4.106 4.789,4.299 4.577,4.512 L4.577,4.512 C4.35,4.718 4.145,4.941 3.962,5.18 L3.953,5.192 C3.621,5.681 3.372,6.255 3.239,6.872 L3.233,6.904 C3.182,7.172 3.152,7.48 3.152,7.795 C3.152,7.822 3.153,7.849 3.153,7.876 L3.153,7.872 C3.153,7.874 3.153,7.877 3.153,7.88 C3.153,8.22 3.188,8.551 3.254,8.871 L3.249,8.84 C3.32,9.184 3.416,9.487 3.541,9.775 L3.529,9.744 C3.66,10.05 3.807,10.31 3.978,10.56 L3.969,10.54 C4.323,11.06 4.753,11.49 5.248,11.83 L5.265,11.84 C5.393,11.92 5.545,12 5.703,12.08 L5.729,12.09 L5.553,10.01 C5.457,9.904 5.366,9.792 5.28,9.675 L5.273,9.664 C5.162,9.507 5.062,9.328 4.984,9.138 L4.977,9.12 C4.902,8.949 4.839,8.748 4.796,8.54 L4.793,8.52 C4.765,8.369 4.749,8.195 4.749,8.017 C4.749,7.966 4.751,7.915 4.753,7.865 L4.753,7.872 C4.753,7.861 4.753,7.847 4.753,7.834 C4.753,7.621 4.776,7.413 4.82,7.213 L4.817,7.232 C4.863,7.004 4.926,6.803 5.009,6.612 L5.001,6.632 C5.086,6.424 5.186,6.245 5.303,6.079 L5.297,6.088 C5.42,5.905 5.551,5.746 5.697,5.6 L5.697,5.6 C5.838,5.46 5.992,5.334 6.158,5.223 L6.169,5.216 C6.326,5.105 6.505,5.005 6.695,4.927 L6.713,4.92 C6.884,4.843 7.084,4.777 7.293,4.732 L7.313,4.728 C7.507,4.69 7.729,4.668 7.957,4.668 C8.185,4.668 8.407,4.69 8.623,4.732 L8.601,4.728 C8.83,4.777 9.03,4.843 9.221,4.928 L9.201,4.92 C9.599,5.079 9.938,5.31 10.22,5.599 L10.22,5.6 C10.36,5.744 10.49,5.904 10.6,6.077 L10.61,6.088 z"/>
Expand Down
33 changes: 33 additions & 0 deletions TranscripterUI/ButtonStyles.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<!-- Add Controls for Previewer Here -->
</Border>
</Design.PreviewWith>

<!-- Add Styles Here -->
<Style Selector="Button.Icon /template/ ContentPresenter">
<Setter Property="Background" Value="transparent"/>
<Setter Property="Opacity" Value="0.5"/>
</Style>

<Style Selector="Button:pointerover.Icon /template/ ContentPresenter">
<Setter Property="Background" Value="transparent"/>
<Setter Property="Opacity" Value="1"/>
</Style>

<Style Selector="Button.Standard /template/ ContentPresenter">
<Setter Property="CornerRadius" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="#268bd2"/>
</Style>

<Style Selector="Button:pointerover.Standard /template/ ContentPresenter">
<Setter Property="CornerRadius" Value="5" />
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Background" Value="#1e6fa8"/>
</Style>
</Styles>
3 changes: 2 additions & 1 deletion TranscripterUI/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# TranscripterUI

The UI portion of the Transcripter program. The design is heavily inspired by balenaEtcher's UI.
The UI portion of the Transcripter program.

## Credits

- Font used is [Open Sans](https://github.com/googlefonts/opensans).
- In-application icons are BoxIcons, converted to a format for Avalonia in
[Avalonia.IconPacks](https://github.com/ahopper/Avalonia.IconPacks) which I used for [`BoxIcons.axaml`](./BoxIcons.axaml).
5 changes: 5 additions & 0 deletions TranscripterUI/TranscripterUI.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ViewModels\ViewModelBase.fs" />
<Compile Include="ViewModels\CurrentStepViewModel.fs" />
<Compile Include="ViewModels\MainWindowViewModel.fs" />
<Compile Include="Views\MainWindow.axaml.fs" />
<Compile Include="Views\CurrentStepView.axaml.fs" />
<Compile Include="ViewLocator.fs" />
<Compile Include="App.axaml.fs" />
<Compile Include="Program.fs" />
Expand All @@ -38,6 +40,9 @@
<ProjectReference Include="..\TranscripterLib\TranscripterLib.fsproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\ramblings\transcripter.md">
<Link>transcripter.md</Link>
</Content>
<Content Include="README.md" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion TranscripterUI/ViewLocator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ViewLocator() =
let name = data.GetType().FullName.Replace("ViewModel", "View")
let typ = Type.GetType(name)
if isNull typ then
upcast TextBlock(Text = sprintf "Not Found: %s" name)
upcast TextBlock(Text = $"Not Found: %s{name}")
else
downcast Activator.CreateInstance(typ)

Expand Down
94 changes: 94 additions & 0 deletions TranscripterUI/ViewModels/CurrentStepViewModel.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
namespace TranscripterUI.ViewModels

open TranscripterUI.ViewModels

type StepProgress =
| Completed
| InProgress
| Upcoming


type Step(num: int, text: string, isNotLast: bool, progress: StepProgress) =
[<Literal>]
let white = "#fff"

[<Literal>]
let backgroundGrey = "#2c2f33"

[<Literal>]
let accent = "#268bd2"

[<Literal>]
let veryLightGrey = "#686f78"

[<Literal>]
let lighterGrey = "#3f4449"

member val IsNotLast = if isNotLast then "False" else "True" with get
member val Position = num * 2 with get
member val SeparatorIndex = (num * 2) + 1 with get
member val Num = num + 1 with get
member val Text = text with get
member val ProgressState = progress with get, set

member this.NumberColour =
match this.ProgressState with
| StepProgress.Completed -> backgroundGrey
| StepProgress.InProgress -> white
| StepProgress.Upcoming -> white

member this.TextColour =
match this.ProgressState with
| StepProgress.Completed -> white
| StepProgress.InProgress -> accent
| StepProgress.Upcoming -> veryLightGrey

member this.BorderColour =
match this.ProgressState with
| StepProgress.Completed -> accent
| StepProgress.InProgress -> accent
| StepProgress.Upcoming -> veryLightGrey

member this.LineColour =
match this.ProgressState with
| StepProgress.Completed -> accent
| StepProgress.InProgress -> lighterGrey
| StepProgress.Upcoming -> lighterGrey

member this.InnerCircleColour =
match this.ProgressState with
| StepProgress.Completed -> accent
| StepProgress.InProgress -> backgroundGrey
| StepProgress.Upcoming -> lighterGrey

type CurrentStepViewModel(steps: List<string>) =
inherit ViewModelBase()

member val CurrentStep = 1 with get, set
member val Steps = [for index, text in (steps |> List.indexed) -> Step(index, text, (index + 1) = steps.Length, (if index = 0 then StepProgress.InProgress else StepProgress.Upcoming))] with get
member val NumberSteps = steps.Length with get, set

member this.Increment =
if this.CurrentStep < this.NumberSteps then
this.CurrentStep <- this.CurrentStep + 1

member this.SetStep(stepIndex: int) =
if stepIndex >= 0 && stepIndex < this.NumberSteps then
this.Steps
|> List.indexed
|> Seq.iter(fun (index, step) ->
if index < stepIndex then
step.ProgressState <- StepProgress.Completed
else if index = stepIndex then
step.ProgressState <- StepProgress.InProgress
else
step.ProgressState <- StepProgress.Upcoming
)
this.CurrentStep <- stepIndex

member this.Decrement =
if this.CurrentStep > 0 then
this.CurrentStep <- this.CurrentStep - 1



9 changes: 8 additions & 1 deletion TranscripterUI/ViewModels/MainWindowViewModel.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@

type MainWindowViewModel() =
inherit ViewModelBase()


member val CurrentSteps = CurrentStepViewModel([
"Select Files";
"Configuration"
"Go!"
]) with get


Loading

0 comments on commit 014798c

Please sign in to comment.