Skip to content

Commit

Permalink
speaking defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed Nov 5, 2024
1 parent ece10cb commit 5829b8e
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 34 deletions.
4 changes: 2 additions & 2 deletions v2/GeneratorVideo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
using var v = new VideoData(file);
var res=await v.Analyze();
Console.WriteLine($"analysis successfull {res} , steps : {v.NrSteps()}");
Console.WriteLine(await v.Execute());
Console.ReadLine();
Console.WriteLine(await v.ExecuteToDetermineDuration());
//Console.ReadLine();
}
catch (Exception ex)
{
Expand Down
5 changes: 4 additions & 1 deletion v2/GeneratorVideo/StartProjectVSCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ internal record StartProjectVSCode(string text, string value) : newStep(text, va
public override void Dispose()
{
}

public override void InitDefaults()
{
this.SpeakTest = "I am launching now the project " + value;
}
public override async Task Execute()
{
InputSimulator inputSimulator = new InputSimulator();
Expand Down
5 changes: 4 additions & 1 deletion v2/GeneratorVideo/StartTourVSCode.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
namespace GeneratorVideo;
internal record StartTourVSCode(string text, string value) : newStep(text,value)
{

public override void InitDefaults()
{
this.SpeakTest = "I am now going to show you the more relevant codes ";
}
public override async Task Execute()
{
ArgumentNullException.ThrowIfNullOrWhiteSpace(base.OriginalFileNameFromWhereTheStepIsComing);
Expand Down
31 changes: 29 additions & 2 deletions v2/GeneratorVideo/Step.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
namespace GeneratorVideo;
using System.Media;
using Windows.Media.SpeechSynthesis;

namespace GeneratorVideo;

public class Step
{
public string typeStep { get; set; } = string.Empty;
public string arg { get; set; } = string.Empty;
public long DurationSeconds { get; set; } = 0;
public string SpeakTest { get; set; }=string.Empty;
}
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
internal abstract record newStep(string typeScript, string arg):IParsable<newStep>, IDisposable
Expand All @@ -12,8 +17,30 @@ internal abstract record newStep(string typeScript, string arg):IParsable<newSte
public const string esc = "\u001B";
public int Number { get; internal set; }
public abstract Task Execute();

public abstract void InitDefaults();
public string Description => this.GetType().Name + " " + typeScript + " " + arg;

public long DurationSeconds { get; set; }
public string SpeakTest { get; internal set; } = string.Empty;
internal async Task Talk(bool speak)
{
if (!speak)
{
return;
}
if(string.IsNullOrWhiteSpace(SpeakTest))
return;
using SpeechSynthesizer synth = new();

var stream = await synth.SynthesizeTextToStreamAsync(SpeakTest);


using var audioStream = stream.AsStreamForRead();

var player = new SoundPlayer(audioStream);
player.PlaySync();

}
public static newStep Parse(string s, IFormatProvider? provider)
{
if(TryParse(s,provider, out var value))
Expand Down
7 changes: 6 additions & 1 deletion v2/GeneratorVideo/StepBrowser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace GeneratorVideo;

[System.Runtime.Versioning.SupportedOSPlatform("windows")]
internal record StepBrowser(string text, string value) : newStep(text,value)
{
{

//[DllImport("User32.dll")]
//public static extern IntPtr GetDC(IntPtr hwnd);
//[DllImport("User32.dll")]
Expand All @@ -22,6 +23,10 @@ public override void Dispose()
}

}
public override void InitDefaults()
{
this.SpeakTest = "I am launching browser with "+ value ;
}

public override async Task Execute()
{
Expand Down
14 changes: 10 additions & 4 deletions v2/GeneratorVideo/StepExecuteProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ public override void Dispose()
}

}
public override Task Execute()
string program = "", args = "";
public override void InitDefaults()
{
string program = "", args = "";

var whereExe = value.IndexOf(".exe");
if (whereExe > 0)
{
program = value.Substring(0, whereExe+4);
args = value.Substring(whereExe + 1+4);
program = value.Substring(0, whereExe + 4);
args = value.Substring(whereExe + 1 + 4);
}
else
{
Expand All @@ -30,6 +31,11 @@ public override Task Execute()
program = data[0];
args = string.Join(' ', data.Where((_, i) => i > 0).ToArray());
}

this.SpeakTest = "I am starting " + program;
}
public override Task Execute()
{
Console.WriteLine($"start program {program} with args {args}");
process=Process.Start(program, args);
return Task.CompletedTask;
Expand Down
5 changes: 5 additions & 0 deletions v2/GeneratorVideo/StepHide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ public override void Dispose()
{
}

public override void InitDefaults()
{
this.SpeakTest = "";
}

public override Task Execute()
{
return Task.CompletedTask;
Expand Down
20 changes: 4 additions & 16 deletions v2/GeneratorVideo/StepText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,14 @@
namespace GeneratorVideo;
internal record StepText(string text, string value) : newStep(text, value)
{
public override void Dispose()
public override void InitDefaults()
{
this.SpeakTest = value;
}
private async Task Talk(bool speak)
public override void Dispose()
{
if(!speak)
{
return;
}
using SpeechSynthesizer synth = new();

var stream = await synth.SynthesizeTextToStreamAsync(value);


using var audioStream = stream.AsStreamForRead();

var player = new SoundPlayer(audioStream);
player.PlaySync();

}

public override async Task Execute()
{
await Task.Delay(1000);
Expand Down
4 changes: 4 additions & 0 deletions v2/GeneratorVideo/StepWait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public override async Task Execute()
public override void Dispose()
{
}
public override void InitDefaults()
{
this.SpeakTest = "";
}
}
16 changes: 10 additions & 6 deletions v2/GeneratorVideo/VideoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,32 @@ public async Task<bool> Analyze()

}
public int NrSteps() => vdata?.steps.Length ?? 0;
public async Task<bool> Execute()
public async Task<bool> ExecuteToDetermineDuration()
{
if (vdata == null) return false;
var execSteps=vdata.realSteps.OrderBy(it=>it.Number).ToArray();
var nr = execSteps.Length;
InputSimulator inputSimulator = new InputSimulator();

long Duration = 0;
for (var iStep=0;iStep<nr;iStep++) {
try
{
var step = execSteps[iStep];
Console.WriteLine($"executing {step.GetType().Name} {step.Number} /{nr}");// + "=>" + step.value);
//if (step.Number < 12) continue;
var now = DateTime.Now; //
await step.Execute();
if(iStep <= nr - 1)
var DurationSeconds = DateTime.Now.Subtract(now).TotalSeconds;
step.DurationSeconds= (long)DurationSeconds;
Duration += step.DurationSeconds;
if (iStep <= nr - 1)
{
Console.WriteLine("========>next step" + execSteps[iStep + 1].Description);
Console.WriteLine("========>next step " + execSteps[iStep + 1].Description);
}
else
{
Console.WriteLine("no next step");
}
Console.ReadLine();
//Console.ReadLine();
await Task.Delay(2000);

}
Expand All @@ -59,6 +62,7 @@ public async Task<bool> Execute()
return false;
}
}
Console.WriteLine($"Duration Seconds={Duration}");
return true;
}
public void Dispose()
Expand Down
4 changes: 3 additions & 1 deletion v2/GeneratorVideo/VideoJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ internal class VideoJson
var step = data.steps[i];
var newStep= GeneratorVideo.newStep.Parse("step_"+ i + "_"+step.typeStep + GeneratorVideo.newStep.esc + step.arg, null);
newStep.OriginalFileNameFromWhereTheStepIsComing = fileName;

newStep.DurationSeconds = step.DurationSeconds;
newStep.SpeakTest = step.SpeakTest;
newStep.Number = (i+1);
steps.Add(newStep);
}
data.realSteps= steps.ToArray();
Expand Down

0 comments on commit 5829b8e

Please sign in to comment.