Skip to content

Commit

Permalink
2.1.2
Browse files Browse the repository at this point in the history
+ Update giao diện, thêm thanh thông tin số lượng ký tự đã nhập.
+ Sửa lỗi out khi nhập ký tự "...."
+ Sửa lỗi out khi nhập trên 2000 ký tự.
  • Loading branch information
phatjkk committed Sep 5, 2021
1 parent b622d03 commit ee424fc
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 47 deletions.
11 changes: 6 additions & 5 deletions SpeakIt!/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SpeakIt_"
mc:Ignorable="d"
Title="SpeakIt!" Height="348.092" Width="563" WindowStartupLocation="CenterScreen" Icon="icons8-year-of-dragon-100.png" Background="#FF0C1014" ResizeMode="NoResize" Visibility="Visible" WindowStyle="None" LostTouchCapture="Grid_MouseLeftButtonDown">
Title="DragonSpeak" Height="358.092" Width="563" WindowStartupLocation="CenterScreen" Icon="icons8-year-of-dragon-100.png" Background="#FF2C2C54" ResizeMode="NoResize" Visibility="Visible" WindowStyle="None" LostTouchCapture="Grid_MouseLeftButtonDown">
<Grid x:Name="_back">
<Grid.RowDefinitions>
<RowDefinition/>
Expand All @@ -31,24 +31,23 @@
</ComboBox>
<Button x:Name="_stop" Content="Dừng" HorizontalAlignment="Left" Height="24" Margin="408,324,0,0" VerticalAlignment="Top" Width="137" Click="_stop_Click" Foreground="White" Background="#FFC0392B" FontSize="12" FontFamily="Segoe UI Semibold" BorderBrush="#FFC0392B" />

<TextBox Margin="8,39,0.2,82" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" x:Name="_text" Foreground="White" FontFamily="Segoe UI Semibold" Text="Nhập văn bản ở đây." BorderBrush="#FFFAFAFA">
<TextBox Margin="8,54,0,124" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" x:Name="_text" Foreground="White" Text="Nhập văn bản ở đây." BorderBrush="#FFFAFAFA">
<TextBox.CaretBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF64B3F4"/>
<GradientStop Color="#FFC2E59C" Offset="1"/>
</LinearGradientBrush>
</TextBox.CaretBrush>
</TextBox>
<Label Content="DragonSpeak 2.0" HorizontalAlignment="Left" Height="23" Margin="233,0,0,0" VerticalAlignment="Top" Width="110" FontFamily="Segoe UI Black" Background="Transparent">
<Label Content="DragonSpeak 2.1.2" HorizontalAlignment="Left" Height="31" Margin="204,10,0,0" VerticalAlignment="Top" Width="155" FontFamily="Segoe UI Black" Background="Transparent" FontSize="16">
<Label.Foreground>
<RadialGradientBrush GradientOrigin="0.5,0.5">
<GradientStop Color="#FFF64F59" Offset="0"/>
<GradientStop Color="#FFEE6E76" Offset="0"/>
<GradientStop Color="#FF12C2E9" Offset="1"/>
<GradientStop Color="#FFC471ED" Offset="0.498"/>
</RadialGradientBrush>
</Label.Foreground>
</Label>
<Image HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="20" OpacityMask="Black" Source="icons8-year-of-dragon-100.png" Margin="8,3,0,0"/>
<Button x:Name="_close" ToolTip="Close" Content="" HorizontalAlignment="Left" Height="14" Margin="538,6,0,0" VerticalAlignment="Top" Width="15" Background="#FFE74C3C" BorderBrush="#FFE74C3C" Click="Button_Click"/>
<Button x:Name="_minimize" ToolTip="Minimize" Content="" HorizontalAlignment="Left" Height="14" Margin="518,6,0,0" VerticalAlignment="Top" Width="15" Background="#FFF1C40F" BorderBrush="#FFF1C40F" Click="_minimize_Click"/>
<Button x:Name="_info" ToolTip="Buy me a coffee :D" Content="" HorizontalAlignment="Left" Height="14" Margin="500,6,0,0" VerticalAlignment="Top" Width="14" Background="#FF2ECC71" BorderBrush="#FF2ECC71" Click="_info_Click"/>
Expand All @@ -57,6 +56,8 @@
<Button x:Name="_download" Content="Download" HorizontalAlignment="Left" Height="24" Margin="408,298,0,0" VerticalAlignment="Top" Width="137" FontSize="12" Click="_download_Click"/>
<Label x:Name="_tientring" Content="Chưa khởi động." HorizontalAlignment="Left" Margin="65,321,0,0" VerticalAlignment="Top" Height="27" Foreground="White" FontFamily="Segoe UI Semibold" Width="325"/>
<Label Content="Status :" HorizontalAlignment="Left" Margin="8,321,0,0" VerticalAlignment="Top" Height="27" Foreground="White" FontFamily="Segoe UI Semibold"/>
<Label Content="Status :" HorizontalAlignment="Left" Margin="8,321,0,0" VerticalAlignment="Top" Height="27" Foreground="White" FontFamily="Segoe UI Semibold"/>
<Label x:Name="_kytu" Content="Ký tự đã nhập: 0" HorizontalAlignment="Left" Margin="225,239,0,0" VerticalAlignment="Top" Height="27" Foreground="White" Background="#FF444444" RenderTransformOrigin="0.796,0.519"/>

</Grid>
</Window>
76 changes: 61 additions & 15 deletions SpeakIt!/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,45 @@ public partial class MainWindow : Window
int[] arrGiongmini = {1, 2, 3,4 };
int filexong = -1;
Thread ThreadBackround;
Thread DocThread;
Thread DocThread, ThreadUpdateUI;
Process ffmpeg;
XuLyAmThanh MainXuLy;
public MainWindow()
{
InitializeComponent();
ThreadUpdateUI = new Thread(() => UpdateUI());
ThreadUpdateUI.IsBackground = true;
ThreadUpdateUI.Start();
}

private void UpdateUI()
{
string textPre = "";
while (true)
{
this.Dispatcher.Invoke(() =>
{
if (_text.Text != textPre)
{
_kytu.Content = "Ký tự đã nhập: " + _text.Text.Length.ToString();
textPre = _text.Text;
}
});
Thread.Sleep(200);
}
}
private void _run_Click(object sender, RoutedEventArgs e)
{
string text = _text.Text;
int gender = arrGiongmini[Array.IndexOf(arrGiong, _nguoidoc.Text)];
string speed = StringBetween(_tocdo.Text, "(", ")");
MainXuLy = new XuLyAmThanh(text, gender, speed);
MainXuLy.mainRun();
ThreadBackround = new Thread(() => Backround());
ThreadBackround.IsBackground = true;
ThreadBackround.Start();
}
private void _stop_Click(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -111,6 +135,7 @@ private void Backround()
this.Dispatcher.Invoke(() => {
_tientring.Content = MainXuLy.getProcessMes();
_process.Value = MainXuLy.getProcessNow();
});

Thread.Sleep(2000);
Expand Down Expand Up @@ -231,8 +256,9 @@ public void mainDown()
public void Down()
{
this.processMes = "Đang khởi động...";
DeleteAllFile(path + "\\audio");
//DeleteAllFile(path + "\\audio");
this.processNow = 0;
string fname;
if (text.Length > 2000)
{

Expand All @@ -246,11 +272,12 @@ public void Down()
int maxdown = outputTexts.Count;
for (int i = 0; i < maxdown; i++)
{
fname = DateTime.Now.ToString("yyMMddHHmmss");
this.processNow = (i + 1) * 100/ (maxdown + 1);
this.processMes = "Đang tải file -> " + "Audio " + i + ".mp3...";
this.processMes = "Đang tải file -> " + fname + ".mp3...";
Thread.Sleep(2000);
DownFileM3U8toMP3(linksOfM3u8.ElementAt(i),"Audio "+i+".mp3");
this.processMes = "Đã tải xong file -> " + "Audio " + i + ".mp3";
DownFileM3U8toMP3(linksOfM3u8.ElementAt(i), fname + ".mp3");
this.processMes = "Đã tải xong file -> " + fname + ".mp3";

}
this.processMes = "Done";
Expand All @@ -259,10 +286,11 @@ public void Down()
}
else
{
this.processMes = "Đang tải file -> Audio.mp3...";
DownFileM3U8toMP3(getTTS_URL(text), "Audio.mp3");
fname = DateTime.Now.ToString("yyMMddHHmmss");
this.processMes = "Đang tải file -> "+ fname + ".mp3...";
DownFileM3U8toMP3(getTTS_URL(text), fname + ".mp3");
this.processNow = 100;
this.processMes = "Đã tải xong file -> Audio.mp3";
this.processMes = "Đã tải xong file -> "+ fname + ".mp3";
MessageBox.Show("Đã tải xong\nVui lòng check thư mục audio");
}
}
Expand All @@ -282,9 +310,11 @@ private void DeleteAllFile(string folderPath)
}
public void Read()
{
this.processMes = "Đang khởi động...";
if (text.Length > 2000)
{
linksOfM3u8.Clear();

Thread getLink = new Thread(() => GetDataM3u8());
getLink.Start();
while (!(linksOfM3u8.Count > 0))
Expand All @@ -293,36 +323,52 @@ public void Read()
}
for (int i = 0; i < outputTexts.Count; i++)
{

this.processMes = "Đang chạy trình phát...";
PlayM3U8FromUrl(linksOfM3u8.ElementAt(i));
}

}
else
{
this.processMes = "Đang chạy trình phát...";
PlayM3U8FromUrl(getTTS_URL(text));
}
this.processMes = "Đã xong!";
}
public void GetDataM3u8()
{
int index = 0;
outputTexts = text.Split(new[] { ". " }, StringSplitOptions.None).OfType<string>().ToList();
while (text.Contains(".."))
{
text = text.Replace("..", ".");
}
outputTexts = text.Split(new[] { "." }, StringSplitOptions.None).OfType<string>().ToList();


string doanDuoi2000rollback = "";
string doanDuoi2000 = "";
while (index < outputTexts.Count)
{
if ((doanDuoi2000.Length + outputTexts.ElementAt(index).Length) <= 2000)
if ((doanDuoi2000.Length + outputTexts.ElementAt(index).Length) < 2000)
{
doanDuoi2000 += outputTexts.ElementAt(index);

doanDuoi2000 += outputTexts.ElementAt(index) + ".";
index += 1;
}
else
else if ((doanDuoi2000.Length + outputTexts.ElementAt(index).Length) > 2000)
{
final_input_cutted.Add(doanDuoi2000);
doanDuoi2000 = "";
}
}
final_input_cutted.Add(doanDuoi2000);
outputTexts = final_input_cutted;
if (doanDuoi2000.Length > 0)
{
final_input_cutted.Add(doanDuoi2000);
}
linksOfM3u8.Clear();
outputTexts.Clear();
outputTexts = final_input_cutted.ToList();

foreach (string itemText in final_input_cutted)
{
linksOfM3u8.Add(getTTS_URL(itemText));
Expand Down
7 changes: 7 additions & 0 deletions SpeakIt!/SpeakIt!.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>icons8-year-of-dragon-100.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="MaterialDesignColors, Version=2.0.0.2422, Culture=neutral, PublicKeyToken=df2a72020bd7962a, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignColors.2.0.0\lib\net452\MaterialDesignColors.dll</HintPath>
Expand Down Expand Up @@ -145,6 +149,9 @@
<ItemGroup>
<Resource Include="icons8-year-of-dragon-100.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="icons8-year-of-dragon-100.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets" Condition="Exists('..\packages\MaterialDesignThemes.4.0.0\build\MaterialDesignThemes.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Binary file modified SpeakIt!/bin/Debug/SpeakIt!.exe
Binary file not shown.
Binary file modified SpeakIt!/bin/Debug/SpeakIt!.pdb
Binary file not shown.
Binary file added SpeakIt!/icons8-year-of-dragon-100.ico
Binary file not shown.
Binary file modified SpeakIt!/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
Binary file not shown.
Binary file modified SpeakIt!/obj/Debug/MainWindow.baml
Binary file not shown.
33 changes: 22 additions & 11 deletions SpeakIt!/obj/Debug/MainWindow.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "9ACB410B269A1C33A8CBD4042A9C9F7A283E81C5D701C78033EDB682D89C001B"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "6DA5C74E41396F9D0AB3A8C8556159CD2FD29281FDD717E8C7E5D3B731065B43"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down Expand Up @@ -89,53 +89,61 @@ public partial class MainWindow : System.Windows.Window, System.Windows.Markup.I
#line hidden


#line 52 "..\..\MainWindow.xaml"
#line 51 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button _close;

#line default
#line hidden


#line 53 "..\..\MainWindow.xaml"
#line 52 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button _minimize;

#line default
#line hidden


#line 54 "..\..\MainWindow.xaml"
#line 53 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button _info;

#line default
#line hidden


#line 55 "..\..\MainWindow.xaml"
#line 54 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.ProgressBar _process;

#line default
#line hidden


#line 57 "..\..\MainWindow.xaml"
#line 56 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Button _download;

#line default
#line hidden


#line 58 "..\..\MainWindow.xaml"
#line 57 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Label _tientring;

#line default
#line hidden


#line 60 "..\..\MainWindow.xaml"
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
internal System.Windows.Controls.Label _kytu;

#line default
#line hidden

private bool _contentLoaded;

/// <summary>
Expand Down Expand Up @@ -207,7 +215,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 8:
this._close = ((System.Windows.Controls.Button)(target));

#line 52 "..\..\MainWindow.xaml"
#line 51 "..\..\MainWindow.xaml"
this._close.Click += new System.Windows.RoutedEventHandler(this.Button_Click);

#line default
Expand All @@ -216,7 +224,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 9:
this._minimize = ((System.Windows.Controls.Button)(target));

#line 53 "..\..\MainWindow.xaml"
#line 52 "..\..\MainWindow.xaml"
this._minimize.Click += new System.Windows.RoutedEventHandler(this._minimize_Click);

#line default
Expand All @@ -225,7 +233,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 10:
this._info = ((System.Windows.Controls.Button)(target));

#line 54 "..\..\MainWindow.xaml"
#line 53 "..\..\MainWindow.xaml"
this._info.Click += new System.Windows.RoutedEventHandler(this._info_Click);

#line default
Expand All @@ -237,7 +245,7 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 12:
this._download = ((System.Windows.Controls.Button)(target));

#line 57 "..\..\MainWindow.xaml"
#line 56 "..\..\MainWindow.xaml"
this._download.Click += new System.Windows.RoutedEventHandler(this._download_Click);

#line default
Expand All @@ -246,6 +254,9 @@ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object
case 13:
this._tientring = ((System.Windows.Controls.Label)(target));
return;
case 14:
this._kytu = ((System.Windows.Controls.Label)(target));
return;
}
this._contentLoaded = true;
}
Expand Down
Loading

0 comments on commit ee424fc

Please sign in to comment.