-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
efb4756
commit 562c241
Showing
17 changed files
with
1,137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Emgu.CV" Version="4.8.1.5350" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Drawing; | ||
using Emgu.CV; | ||
using Emgu.CV.Structure; | ||
|
||
|
||
namespace TextToSpeechWithMouthImages | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
// Path to the text file | ||
string filePath = "path/to/your/text/file.txt"; | ||
|
||
// Initialize video writer | ||
VideoWriter writer = new VideoWriter("output.mp4", VideoWriter.Fourcc('X', 'V', 'I', 'D'), 10, new Size(800, 600), true); | ||
|
||
// Load mouth images for vowels | ||
Bitmap mouthA = new Bitmap("mouth_a.bmp"); | ||
Bitmap mouthE = new Bitmap("mouth_e.bmp"); | ||
Bitmap mouthI = new Bitmap("mouth_i.bmp"); | ||
Bitmap mouthO = new Bitmap("mouth_o.bmp"); | ||
Bitmap mouthU = new Bitmap("mouth_u.bmp"); | ||
Bitmap mouth6 = new Bitmap("mouth_6.bmp"); // New mouth image between words | ||
|
||
// Start recording images | ||
ImageDisplay imageDisplay = new ImageDisplay(writer); | ||
Thread imageDisplayThread = new Thread(imageDisplay.StartRecording); | ||
imageDisplayThread.Start(); | ||
|
||
// Read the text from the file | ||
string text = File.ReadAllText(filePath); | ||
|
||
// Split the text into words | ||
string[] words = text.Split(new char[] { ' ', ' ', ' ', ' ' }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
// Iterate through each word | ||
foreach (string word in words) | ||
{ | ||
// Iterate through each character in the word | ||
foreach (char c in word) | ||
{ | ||
// Check if the character is a vowel | ||
if ("AEIOUaeiou".Contains(c)) | ||
{ | ||
// Get the corresponding mouth image for the vowel | ||
Bitmap mouthImage = GetMouthImage(c); | ||
|
||
// Scale the mouth image | ||
Bitmap scaledMouthImage = new Bitmap((int)(mouthImage.Width * ScaleFactor), (int)(mouthImage.Height * ScaleFactor)); | ||
using (Graphics g = Graphics.FromImage(scaledMouthImage)) | ||
{ | ||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | ||
g.DrawImage(mouthImage, 0, 0, scaledMouthImage.Width, scaledMouthImage.Height); | ||
} | ||
|
||
// Convert the Bitmap to Image<Bgr, byte> | ||
Image<Bgr, byte> emguImage = new Image<Bgr, byte>(scaledMouthImage); | ||
|
||
// Add the frame to the video writer | ||
writer.WriteFrame(emguImage.Mat); | ||
} | ||
|
||
// Adjust the delay to simulate the speed of human speech for characters | ||
Thread.Sleep(100); | ||
} | ||
|
||
// Display mouth image 6 between words | ||
Bitmap scaledMouth6 = new Bitmap((int)(mouth6.Width * ScaleFactor), (int)(mouth6.Height * ScaleFactor)); | ||
using (Graphics g = Graphics.FromImage(scaledMouth6)) | ||
{ | ||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | ||
g.DrawImage(mouth6, 0, 0, scaledMouth6.Width, scaledMouth6.Height); | ||
} | ||
Image<Bgr, byte> emguImage6 = new Image<Bgr, byte>(scaledMouth6); | ||
writer.WriteFrame(emguImage6.Mat); | ||
|
||
// Adjust the delay to simulate the speed of human speech for words | ||
Thread.Sleep(1000); // Adjust this delay to simulate human speaking speed for words | ||
} | ||
|
||
// Stop recording images | ||
imageDisplay.StopRecording(); | ||
imageDisplayThread.Join(); | ||
|
||
// Release the video writer | ||
writer.Dispose(); | ||
} | ||
|
||
// Method to get the mouth image for a vowel | ||
static Bitmap GetMouthImage(char vowel) | ||
{ | ||
switch (vowel) | ||
{ | ||
case 'A': | ||
case 'a': | ||
return new Bitmap("mouth_a.bmp"); | ||
case 'E': | ||
case 'e': | ||
return new Bitmap("mouth_e.bmp"); | ||
case 'I': | ||
case 'i': | ||
return new Bitmap("mouth_i.bmp"); | ||
case 'O': | ||
case 'o': | ||
return new Bitmap("mouth_o.bmp"); | ||
case 'U': | ||
case 'u': | ||
return new Bitmap("mouth_u.bmp"); | ||
default: | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
|
||
public class ImageDisplay | ||
{ | ||
private VideoWriter writer; | ||
private string outputFilePath; | ||
|
||
public ImageDisplay(string outputFilePath) | ||
{ | ||
this.outputFilePath = outputFilePath; | ||
} | ||
|
||
public void StartRecording() | ||
{ | ||
writer = new VideoWriter(outputFilePath, VideoWriter.Fourcc('X', 'V', 'I', 'D'), 10, new Size(800, 600), true); | ||
|
||
// Start threads for displaying images at specified intervals | ||
Thread displayThread1 = new Thread(DisplayImage1); | ||
Thread displayThread2 = new Thread(DisplayImage2); | ||
Thread displayThread3 = new Thread(DisplayImage3); | ||
Thread displayThread4 = new Thread(DisplayImage4); | ||
|
||
displayThread1.Start(); | ||
displayThread2.Start(); | ||
displayThread3.Start(); | ||
displayThread4.Start(); | ||
} | ||
|
||
public void StopRecording() | ||
{ | ||
// Release the video writer | ||
writer.Dispose(); | ||
} | ||
|
||
private void DisplayImage1() | ||
{ | ||
// Display the image every 2 seconds | ||
while (true) | ||
{ | ||
Bitmap image = new Bitmap("image1.bmp"); | ||
AddFrameToVideo(image); | ||
Thread.Sleep(2000); | ||
} | ||
} | ||
|
||
private void DisplayImage2() | ||
{ | ||
// Display random images every 5 seconds | ||
Random random = new Random(); | ||
string[] imageFiles = { "image2.bmp", "image3.bmp", "image4.bmp", "image5.bmp", "image6.bmp" }; | ||
|
||
while (true) | ||
{ | ||
string randomImageFile = imageFiles[random.Next(imageFiles.Length)]; | ||
Bitmap image = new Bitmap(randomImageFile); | ||
AddFrameToVideo(image); | ||
Thread.Sleep(5000); | ||
} | ||
} | ||
|
||
private void DisplayImage3() | ||
{ | ||
// Display an image whenever '!' appears in the text for 5 seconds | ||
while (true) | ||
{ | ||
if (CheckTextForCharacter('!')) | ||
{ | ||
Bitmap image = new Bitmap("image3.bmp"); | ||
AddFrameToVideo(image); | ||
Thread.Sleep(5000); | ||
} | ||
else | ||
{ | ||
Thread.Sleep(1000); // Check every second | ||
} | ||
} | ||
} | ||
|
||
private void DisplayImage4() | ||
{ | ||
// Custom logic for displaying images | ||
// Add your own requirements here | ||
} | ||
|
||
private bool CheckTextForCharacter(char character) | ||
{ | ||
// Custom logic to check if the given character appears in the text | ||
// Add your own requirements here | ||
return true; // For demonstration purposes, always return true | ||
} | ||
|
||
private void AddFrameToVideo(Bitmap image) | ||
{ | ||
// Convert the Bitmap to Image<Bgr, byte> | ||
Image<Bgr, byte> emguImage = new Image<Bgr, byte>(image); | ||
|
||
// Add the frame to the video writer | ||
writer.WriteFrame(emguImage.Mat); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?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>{26F4EDC1-05BA-41FE-BE71-71DB0E3C5C8D}</ProjectGuid> | ||
<OutputType>WinExe</OutputType> | ||
<RootNamespace>AI.TTS.Visual</RootNamespace> | ||
<AssemblyName>AI.TTS.Visual</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<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' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Emgu.CV, Version=4.8.1.5350, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Emgu.CV.4.8.1.5350\lib\netstandard2.0\Emgu.CV.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ComponentModel.Composition" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Drawing.Primitives.4.3.0\lib\net45\System.Drawing.Primitives.dll</HintPath> | ||
<Private>True</Private> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Numerics" /> | ||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime, Version=4.1.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Runtime.4.3.1\lib\net462\System.Runtime.dll</HintPath> | ||
<Private>True</Private> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath> | ||
<Private>True</Private> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System.Text.Encodings.Web, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Text.Json, Version=7.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Text.Json.7.0.3\lib\net462\System.Text.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Deployment" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ImageDisplay.cs" /> | ||
<Compile Include="FormMain.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="FormMain.Designer.cs"> | ||
<DependentUpon>FormMain.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<EmbeddedResource Include="FormMain.resx"> | ||
<DependentUpon>FormMain.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
<SubType>Designer</SubType> | ||
</EmbeddedResource> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<None Include="packages.config" /> | ||
<None Include="Properties\Settings.settings"> | ||
<Generator>SettingsSingleFileGenerator</Generator> | ||
<LastGenOutput>Settings.Designer.cs</LastGenOutput> | ||
</None> | ||
<Compile Include="Properties\Settings.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DependentUpon>Settings.settings</DependentUpon> | ||
<DesignTimeSharedInput>True</DesignTimeSharedInput> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> | ||
</startup> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | ||
</dependentAssembly> | ||
<dependentAssembly> | ||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-7.0.0.3" newVersion="7.0.0.3" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |
Oops, something went wrong.