Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Pronounce word is now hightlighted #5

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions TextToSpeech.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextToSpeech", "TextToSpeec
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextToSpeechTests", "TextToSpeechTests\TextToSpeechTests.csproj", "{21624325-69E3-4686-98D6-25C73DF4AFCD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextToSpeechLogger", "TextToSpeechLogger\TextToSpeechLogger.csproj", "{4A8D01C8-2832-4C37-9B4B-1E94A177201C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{21624325-69E3-4686-98D6-25C73DF4AFCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{21624325-69E3-4686-98D6-25C73DF4AFCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{21624325-69E3-4686-98D6-25C73DF4AFCD}.Release|Any CPU.Build.0 = Release|Any CPU
{4A8D01C8-2832-4C37-9B4B-1E94A177201C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A8D01C8-2832-4C37-9B4B-1E94A177201C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A8D01C8-2832-4C37-9B4B-1E94A177201C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A8D01C8-2832-4C37-9B4B-1E94A177201C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
55 changes: 32 additions & 23 deletions TextToSpeech/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
using GemBox.Pdf;
using TextToSpeech.Interfaces;
using TextToSpeech.Implementations;
using TextToSpeech.Utilites;
using TextToSpeechLogger;
using static System.Net.Mime.MediaTypeNames;

namespace TextToSpeech
{
Expand All @@ -27,15 +28,9 @@ public Form1()

private void button1_Click(object sender, EventArgs e)
{
CheckVoiceandText();
string voice = cmbVoice.Text;
int selected = cmbVoice.SelectedIndex;
string theText = txtSpechText.Text;
if (voice == "Select Voice" || selected == 0)
{
MessageBox.Show("Please Select a Voice");
return;
}

Speak(theText, voice);
}

Expand Down Expand Up @@ -139,24 +134,17 @@ private void GetPdfFile(string filePath)

private void BtnPronounce_Click(object sender, EventArgs e)
{
CheckVoiceandText(true);
string voice = cmbVoice.Text;

if (voice == "Select Voice")
{
MessageBox.Show("Select a Voice");
return;
}

if (txtSpechText.Text.Trim() == "")
{
MessageBox.Show("Type some text");
return;
}

if (txtSpechText.SelectionLength > 0)
{
string sel = txtSpechText.SelectedText;
Speak(sel, voice);
string selectedText = txtSpechText.SelectedText;
int selectionStart = txtSpechText.SelectionStart;
int selectionLength = txtSpechText.SelectionLength;
txtSpechText.Focus();
txtSpechText.Select(selectionStart, selectionLength);
Speak(selectedText, voice);
Logger.LogSpeechText(selectedText);
}
}

Expand All @@ -172,5 +160,26 @@ public void LoadVoices()
cmbVoice.Items.Add(voice.VoiceInfo.Name);
}
}

private void CheckVoiceandText(bool ishighLighted = false)
{
if (cmbVoice.Text == "Select Voice" || cmbVoice.SelectedIndex == 0)
{
MessageBox.Show("Please Select a Voice");
return;
}

if (txtSpechText.Text.Trim() == "")
{
MessageBox.Show("Please Enter Some Text");
return;
}

if(ishighLighted && txtSpechText.SelectionLength == 0)
{
MessageBox.Show("Please Highlight Some Text");
return;
}
}
}
}
8 changes: 7 additions & 1 deletion TextToSpeech/TextToSpeech.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<Compile Include="Interfaces\ISpeechSynthesizer.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilites\Logger.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -105,6 +104,13 @@
</ItemGroup>
<ItemGroup>
<Folder Include="images\" />
<Folder Include="Utilites\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TextToSpeechLogger\TextToSpeechLogger.csproj">
<Project>{4a8d01c8-2832-4c37-9b4b-1e94a177201c}</Project>
<Name>TextToSpeechLogger</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\GemBox.Pdf.17.0.1015\build\netstandard2.0\GemBox.Pdf.targets" Condition="Exists('..\packages\GemBox.Pdf.17.0.1015\build\netstandard2.0\GemBox.Pdf.targets')" />
Expand Down
2 changes: 1 addition & 1 deletion TextToSpeech/bin/Debug/Log.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20/08/2024 18:28:24: This is an automated test.
28/08/2024 15:29:54: This is an automated test.
Binary file modified TextToSpeech/bin/Debug/TextToSpeech.exe
Binary file not shown.
Binary file modified TextToSpeech/bin/Debug/TextToSpeech.pdb
Binary file not shown.
Binary file added TextToSpeech/bin/Debug/TextToSpeechLogger.dll
Binary file not shown.
Binary file added TextToSpeech/bin/Debug/TextToSpeechLogger.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8984dd822dad2eb788577095ca4adc1ffbe8206b172558ec16a14fdaa6d6b6b6
3fcaf3182b7fc5796ac4503536d1fe3248ee20b1282d4c76d5208f5e8daf0eda
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\obj\Debug\TextToSpeech.exe
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\obj\Debug\TextToSpeech.pdb
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\obj\Debug\TextToSpeech.Form1.resources
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\bin\Debug\App.config
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\bin\Debug\TextToSpeechLogger.dll
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeech\bin\Debug\TextToSpeechLogger.pdb
Binary file modified TextToSpeech/obj/Debug/TextToSpeech.exe
Binary file not shown.
Binary file modified TextToSpeech/obj/Debug/TextToSpeech.pdb
Binary file not shown.
12 changes: 7 additions & 5 deletions TextToSpeech/Utilites/Logger.cs → TextToSpeechLogger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
using System.Text;
using System.Threading.Tasks;

namespace TextToSpeech.Utilites
namespace TextToSpeechLogger
{
public static class Logger
{
public static void LogSpeechText(string text)
public static void LogSpeechText(string text, string logFilePath = null)
{
string currentDirectory = Directory.GetCurrentDirectory();
string logFilePath = Path.Combine(currentDirectory, "Log.txt");
if (logFilePath == null)
{
logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log.txt");
}

// Overwrite the log file every time this method is called
using (StreamWriter sw = new StreamWriter(logFilePath, false))
{
sw.WriteLine($"{DateTime.Now}: {text}");
sw.Flush();
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions TextToSpeechLogger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TextToSpeechLogger")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("TextToSpeechLogger")]
[assembly: AssemblyCopyright("Copyright © HP 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4a8d01c8-2832-4c37-9b4b-1e94a177201c")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
48 changes: 48 additions & 0 deletions TextToSpeechLogger/TextToSpeechLogger.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4A8D01C8-2832-4C37-9B4B-1E94A177201C}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TextToSpeechLogger</RootNamespace>
<AssemblyName>TextToSpeechLogger</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Logger.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
35a8d14fbd4d3c489f80ee8b0f1ffcfb17374a8de80ed92fca3d71d6d3077d90
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\bin\Debug\TextToSpeechLogger.dll
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\bin\Debug\TextToSpeechLogger.pdb
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\obj\Debug\TextToSpeechLogger.csproj.AssemblyReference.cache
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\obj\Debug\TextToSpeechLogger.csproj.CoreCompileInputs.cache
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\obj\Debug\TextToSpeechLogger.dll
C:\Users\oyetu\source\repos\Text2speeech\TextToSpeechLogger\obj\Debug\TextToSpeechLogger.pdb
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion TextToSpeechTests/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void TestCleanup()
public void Should_SpeakSentence_WhenButtonIsClicked(string param)
{
//Arrange
string logFile = Path.Combine(baseDirectory, "bin\\Debug\\Log.txt");
session.FindElementByAccessibilityId("cmbVoice").Click();

session.FindElementByName("Microsoft Zira Desktop").Click();
Expand All @@ -51,7 +52,6 @@ public void Should_SpeakSentence_WhenButtonIsClicked(string param)
session.FindElementByAccessibilityId("BtnSpeech").Click();

//Assert
string logFile = Path.Combine(baseDirectory, "bin\\Debug\\Log.txt");
string logContent = File.ReadAllText(logFile);
Assert.IsTrue(logContent.Contains(param));
}
Expand Down
Binary file modified TextToSpeechTests/bin/Debug/TextToSpeechTests.dll
Binary file not shown.
Binary file modified TextToSpeechTests/bin/Debug/TextToSpeechTests.pdb
Binary file not shown.
Binary file not shown.
Binary file modified TextToSpeechTests/obj/Debug/TextToSpeechTests.dll
Binary file not shown.
Binary file modified TextToSpeechTests/obj/Debug/TextToSpeechTests.pdb
Binary file not shown.
Loading