Skip to content

Commit

Permalink
Logical improvements made for movements
Browse files Browse the repository at this point in the history
  • Loading branch information
AccidentalCitizen committed May 5, 2024
1 parent 81d601c commit aa39afd
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/BasicTTS/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Func<Task>>() {
()=> MoveHelpers.MoveMouth(this.pictureBox, this.pictBoxEyes)
()=> MoveHelpers.GenerateFacialExpressionsBasedOnText(this.pictureBox, this.pictBoxEyes)
};

var runningTasks = new List<Task>();
Expand Down
109 changes: 95 additions & 14 deletions src/BasicTTS/FormMainHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"); ;
}
Expand All @@ -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)
{
Expand All @@ -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");
Expand Down
125 changes: 53 additions & 72 deletions src/BasicTTS/MoveHelpers.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,105 +49,65 @@ 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
var bitmap = FormMainHelpers.GetMouthImage(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)
Expand All @@ -150,7 +131,7 @@ public static async Task MoveWorriedEyesRandomly( PictureBox pictureBoxApplicabl
pictureBoxApplicable.Image = bitmap;
pictureBoxApplicable.Refresh();

Task.Delay(300);
Task.Delay(1800);
}
}

Expand Down

0 comments on commit aa39afd

Please sign in to comment.