From aa39afd795becff30c12a7be069be857c947ac7a Mon Sep 17 00:00:00 2001 From: Citizen Date: Sun, 5 May 2024 18:18:21 +0200 Subject: [PATCH] Logical improvements made for movements --- src/BasicTTS/Form1.cs | 2 +- src/BasicTTS/FormMainHelpers.cs | 109 ++++++++++++++++++++++++---- src/BasicTTS/MoveHelpers.cs | 125 ++++++++++++++------------------ 3 files changed, 149 insertions(+), 87 deletions(-) diff --git a/src/BasicTTS/Form1.cs b/src/BasicTTS/Form1.cs index 5870482..3db701c 100644 --- a/src/BasicTTS/Form1.cs +++ b/src/BasicTTS/Form1.cs @@ -34,7 +34,7 @@ private async void button1_Click(object sender, EventArgs e) string textfilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\input.txt"; //string text = File.ReadAllText(textfilePath); var tasks = new List>() { - ()=> MoveHelpers.MoveMouth(this.pictureBox, this.pictBoxEyes) + ()=> MoveHelpers.GenerateFacialExpressionsBasedOnText(this.pictureBox, this.pictBoxEyes) }; var runningTasks = new List(); diff --git a/src/BasicTTS/FormMainHelpers.cs b/src/BasicTTS/FormMainHelpers.cs index 0aa4b87..58dec0c 100644 --- a/src/BasicTTS/FormMainHelpers.cs +++ b/src/BasicTTS/FormMainHelpers.cs @@ -55,7 +55,7 @@ public static Bitmap GetBlinkImage(char vowel) case "normal": return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesBlinkWorried.png"); case "angry": - return new Bitmap(@"C: \Users\Rajah\Pictures\SpEyes\EyesBlinkAngry.png"); + return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesBlinkAngry.png"); default: return new Bitmap(@"C:\Users\Rajah\Pictures\SpMouths\L.png"); ; } @@ -64,7 +64,7 @@ public static Bitmap GetBlinkImage(char vowel) public static Bitmap GetRandomAngryEyeMoveImage(char vowel) { var rnd = new Random(); - var cse = rnd.Next(0, 19); + var cse = rnd.Next(0, 100); switch (cse) { @@ -84,29 +84,110 @@ public static Bitmap GetRandomAngryEyeMoveImage(char vowel) return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); case 7: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); - case 8: + case 8: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 9: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 10: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 11: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 12: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 13: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 14: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 15: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 16: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 17: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 18: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 19: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 20: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 21: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 22: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 23: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 24: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 25: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 26: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 27: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 28: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 29: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 30: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 31: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 32: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 33: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 34: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 35: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 36: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 37: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 38: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 39: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 40: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 41: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 42: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 43: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 44: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 45: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 46: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 47: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 48: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 49: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 50: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 51: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 52: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 53: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 54: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 55: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 56: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 57: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 58: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 59: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 60: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 61: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 62: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 63: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 64: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 65: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 66: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 67: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 68: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 69: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 70: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 71: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 72: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 73: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 74: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 75: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 76: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 77: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 78: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 79: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 80: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 81: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 82: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 83: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 84: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 85: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 86: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + case 87: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); + + case 88: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesLeftAngry.png"); - case 9: + case 89: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesLeftAngry.png"); - case 10: + case 90: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesLeftAngry.png"); - case 11: + case 91: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); - case 12: + case 92: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); - case 13: + case 93: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); - case 14: + case 94: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesUpAngry.png"); - case 15: + case 95: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesUpAngry.png"); - case 16: + case 96: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesUpAngry.png"); - case 17: + case 97: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); - case 18: + case 98: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); - case 19: + case 99: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesRightAngry.png"); default: return new Bitmap(@"C:\Users\Rajah\Pictures\SpEyes\EyesAngryNormal.png"); diff --git a/src/BasicTTS/MoveHelpers.cs b/src/BasicTTS/MoveHelpers.cs index ebaae1c..fcb68ad 100644 --- a/src/BasicTTS/MoveHelpers.cs +++ b/src/BasicTTS/MoveHelpers.cs @@ -1,22 +1,43 @@ using System; +using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using System.Timers; namespace BasicTTS { public static class MoveHelpers { - - public static async Task MoveMouth( PictureBox pictureBoxApplicableMouth, PictureBox pictureBoxApplicableEyes) + private static char character = ' '; + private static PictureBox _pictureBoxApplicableMouth; + private static PictureBox _pictureBoxApplicableEyes; + public static async Task GenerateFacialExpressionsBasedOnText( PictureBox pictureBoxApplicableMouth, PictureBox pictureBoxApplicableEyes) { + //_pictureBoxApplicableMouth = pictureBoxApplicableMouth; + //_pictureBoxApplicableEyes = pictureBoxApplicableEyes; + ////var timer1 = new System.Timers.Timer(2000); // Timer 1 ticks every 2 seconds + //var timerMoveEyes = new System.Timers.Timer(3000); // Timer 2 ticks every 3 seconds + //var timerBlink = new System.Timers.Timer(5000); + + ////timer1.Elapsed += (sender, e) => TimerElapsed(e.SignalTime, "Timer 1"); + //timerMoveEyes.Elapsed += (sender, e) => TimerElapsed(e.SignalTime, "timerMoveEyes"); + //timerBlink.Elapsed += (sender, e) => TimerElapsed(e.SignalTime, "timerBlink"); + + + //// Start the timers + + //timerMoveEyes.Start(); + //timerBlink.Start(); + string textfilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\input.txt"; string outputVideoFilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\output.mp4"; double ScaleFactor = 0.3; var tmr = new System.Windows.Forms.Timer(); - + var timer = new System.Windows.Forms.Timer(); + timer.Start(); string text = File.ReadAllText(textfilePath); //BlinkeEyes(pictureBoxApplicableEyes); // Split the text into words @@ -28,16 +49,33 @@ public static async Task MoveMouth( PictureBox pictureBoxApplicableMouth, Pictur // Iterate through each character in the word foreach (char c in word) { - MouthMove(pictureBoxApplicableMouth, c); + + MouthMove(pictureBoxApplicableMouth, c); EyesBlink(pictureBoxApplicableEyes, c); - RandomlyMoveAngryEyes(pictureBoxApplicableEyes, c); + RandomlyMoveAngryEyes(pictureBoxApplicableEyes, c); + //character = c; + } // Adjust the delay to simulate the speed of human speech for words - Task.Delay(100); // Adjust this delay to simulate human speaking speed for words + Thread.Sleep(2); // Adjust this delay to simulate human speaking speed for words } - + //timerMoveEyes.Stop(); + //timerBlink.Stop(); } + //static void TimerElapsed(DateTime signalTime, string timerName) + //{ + // switch (timerName) + // { + // case "timerMoveEyes": + // RandomlyMoveAngryEyes(_pictureBoxApplicableEyes, character); + // break; + // case "timerBlink": + // EyesBlink(_pictureBoxApplicableEyes, character); + // break; + // } + //} + private static async Task MouthMove(PictureBox pictureBoxApplicableMouth, char c) { // Check if the character is a vowel @@ -45,88 +83,31 @@ private static async Task MouthMove(PictureBox pictureBoxApplicableMouth, char c pictureBoxApplicableMouth.Image = bitmap; pictureBoxApplicableMouth.Refresh(); // Adjust the delay to simulate the speed of human speech for characters - Task.Delay(20); + Thread.Sleep(1); } - public static async Task BlinkEyes(PictureBox pictureBoxApplicable) - { - string textfilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\input.txt"; - string outputVideoFilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\output.mp4"; - - double ScaleFactor = 0.3; - var tmr = new System.Windows.Forms.Timer(); - - string text = File.ReadAllText(textfilePath); - - // 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) - { - EyesBlink(pictureBoxApplicable, c); - // Adjust the delay to simulate the speed of human speech for characters - - } - } - - } private static async Task EyesBlink(PictureBox pictureBoxApplicable, char c) { - bool blinkAngry = true; - if ((c == '!' && c != '.') || (c != '!')) blinkAngry = true; - if (c == '.') blinkAngry = false; - if (blinkAngry) - { - // Check if the character is a vowel - var bitmap = FormMainHelpers.GetBlinkImage('!'); - pictureBoxApplicable.Image = bitmap; - pictureBoxApplicable.Refresh(); - Task.Delay(1500); - } - else - { - var bitmap = FormMainHelpers.GetBlinkImage('.'); - pictureBoxApplicable.Image = bitmap; - pictureBoxApplicable.Refresh(); - Task.Delay(1500); - } - } - - public static async Task MoveAngryEyesRandomly( PictureBox pictureBoxApplicable) - { - string textfilePath = @"C:\Users\Rajah\Documents\Test Data\TextScripts\input.txt"; - var tmr = new System.Windows.Forms.Timer(); - string text = File.ReadAllText(textfilePath); - - // Split the text into words - string[] words = text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); - - // Iterate through each word - foreach (string word in words) + if (c == 'o') { - // Iterate through each character in the word - foreach (char c in word) - { - RandomlyMoveAngryEyes(pictureBoxApplicable, c); - } + var bitmap = FormMainHelpers.GetBlinkImage('!'); + Thread.Sleep(2); } } + private static async Task RandomlyMoveAngryEyes(PictureBox pictureBoxApplicable, char c) { // Check if the character is a vowel + var bitmap = FormMainHelpers.GetRandomAngryEyeMoveImage(c); pictureBoxApplicable.Image = bitmap; pictureBoxApplicable.Refresh(); - Task.Delay(300); + Thread.Sleep(50); } public static async Task MoveWorriedEyesRandomly( PictureBox pictureBoxApplicable) @@ -150,7 +131,7 @@ public static async Task MoveWorriedEyesRandomly( PictureBox pictureBoxApplicabl pictureBoxApplicable.Image = bitmap; pictureBoxApplicable.Refresh(); - Task.Delay(300); + Task.Delay(1800); } }