diff --git a/Config.cs b/Config.cs index e331381..be81533 100644 --- a/Config.cs +++ b/Config.cs @@ -4,4 +4,9 @@ public class Config { public string speech_service { get; set; } = "http://eligos.lan:5400"; public string sync_dropoff { get; set; } = "/home/adam/Sync/eligos documents/"; + public string VODropoff {get;set; } = "./Sounds/VO"; + public string titlecard_command {get;set; } = "echo"; + public string titlecards_dest {get; set; } = "./notes"; + public string note_command {get;set; } = "echo"; + public string notes_dest {get; set; } = "./notes"; } diff --git a/Program.cs b/Program.cs index c2f1693..fc96ee9 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Net; using System.Reflection.Metadata.Ecma335; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices.Marshalling; using System.Text; using System.Text.RegularExpressions; using System.Timers; @@ -22,56 +23,11 @@ namespace placeholdervo private static string workingDir = "./"; private static HttpClient hc; - private static ConcurrentQueue scriptFragmentFiles = new ConcurrentQueue(); private static ConcurrentQueue titleCardLines = new ConcurrentQueue(); + private static ConcurrentQueue noteLines = new ConcurrentQueue(); private static ConcurrentDictionary filePickups = new ConcurrentDictionary(); private static CancellationToken scriptFileCancellationToken; - //from when I cut it up into separate files - // private static async void ApiCalls() - // { - // var hc = new HttpClient(){ BaseAddress = new Uri(conf.speech_service)}; - // while(true) - // { - // while(!scriptFragmentFiles.IsEmpty) - // { - // string scriptFragment; - // scriptFragmentFiles.TryDequeue(out scriptFragment); - // if(scriptFragment == null) continue; - // Console.WriteLine(scriptFragment); - - // HttpContent fileStreamContent = new StreamContent(File.OpenRead(scriptFragment)); - // using (var formData = new MultipartFormDataContent()) - // { - // formData.Add(fileStreamContent, "file1", "file1"); - - // var response = await hc.PostAsync("/speak", formData); - // if (!response.IsSuccessStatusCode) - // { - // Console.Error.WriteLine($"{response.StatusCode} - {response.ReasonPhrase} - {await response.Content.ReadAsStringAsync()}"); - // } - // else - // { - // var resp = string.Join(", ", JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync())); - // Console.WriteLine($"success; {resp}."); - // if(resp != null) - // { - // scriptFragmentVoiceFiles[resp] = scriptFragment; - // Console.WriteLine("Ditching script fragment file."); - // File.Delete(scriptFragment); - // } - // } - // } - // System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); - // } - - // if(scriptFileCancellationToken.IsCancellationRequested && scriptFragmentFiles.IsEmpty) - // { - // return; - // } - // } - // } - ///mostly just to give myself the reminder about paths ///the *complete path* of the awaited file. you might want conf.sync_dropoff ///the *complete path* to move the file to. @@ -115,6 +71,22 @@ namespace placeholdervo } } + private static async void FFStuff() + { + var cardCount = 0; + foreach(var tcL in titleCardLines) + { + await Process.Start(conf.titlecard_command, tcL).WaitForExitAsync(); + File.Move("tc.png", Path.Combine(conf.titlecards_dest, $"tc{cardCount++}.png")); + } + + cardCount = 0; + foreach(var nL in noteLines) + { + await Process.Start(conf.titlecard_command, nL).WaitForExitAsync(); + File.Move("n0.png", Path.Combine(conf.notes_dest, $"note{cardCount++}.png")); + } + } public static async Task Main(string[] args) { conf = JsonConvert.DeserializeObject( @@ -123,6 +95,7 @@ namespace placeholdervo ?? new Config(); hc = new HttpClient(){ BaseAddress = new Uri(conf.speech_service)}; + var taskHeap = new List(); var scriptPath = args?.FirstOrDefault(); if(string.IsNullOrWhiteSpace(scriptPath)) @@ -143,10 +116,6 @@ namespace placeholdervo var cancelSource = new CancellationTokenSource(); scriptFileCancellationToken = cancelSource.Token; - // var apiCallThread = new Thread(new ThreadStart(webcall)); - // apiCallThread.Start(); - // var fileRetrieveThread = new Thread(new ThreadStart(filePickup)); - // fileRetrieveThread.Start(); var lines = File.ReadAllLines(scriptPath) .Append("\n").Append("\n"); @@ -176,7 +145,7 @@ namespace placeholdervo var scriptStripped = $"{scriptBasename}-primaryVO.txt"; File.WriteAllLines(scriptStripped, primaryVOLines); - Task.WaitAny(PrimaryVO(scriptStripped)); + taskHeap.Add(ttsVO(scriptStripped, Path.Combine(conf.VODropoff, $"primaryVO"))); var titleLevels = new List(){0}; var titleIncrementDepth = 0; @@ -205,7 +174,6 @@ namespace placeholdervo } Console.WriteLine($"title card: {TitleCardText}"); titlecardLines.Add(TitleCardText); - //TODO: tc command } else { @@ -245,7 +213,6 @@ namespace placeholdervo var parameterText = thisLine[(thisLine.IndexOf(']') + 1) ..].Trim(); if(directiveName == "note") { - //TODO: note command noteLines.Add(parameterText); Console.WriteLine($"on screen note: {parameterText}"); } @@ -258,35 +225,22 @@ namespace placeholdervo } if(altVOLines?.Count > 0) { - //TODO: alt va command with altVOLines - File.WriteAllLines($"{scriptBasename}-altVO.txt", altVOLines); + var altVOscript = $"{scriptBasename}-altVO.txt"; + File.WriteAllLines(altVOscript, altVOLines); + taskHeap.Add(ttsVO(altVOscript, Path.Combine(conf.VODropoff, $"altVO"))); } // execute them all - //Task.Run(OfflineStuff); - //Task.Run(ApiCalls); - var fpTask = Task.Run(filePickup); - - // cancelSource.Cancel(); - // Console.WriteLine("http client \"cancelled\"."); - // while(apiCallThread.ThreadState != System.Threading.ThreadState.Stopped) - // { - // Console.WriteLine("thread still running. waiting."); - // System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); - // } - // Console.WriteLine($"api call thread done ({apiCallThread.ThreadState})."); - - // while(fileRetrieveThread.ThreadState != System.Threading.ThreadState.Stopped) - // { - // Console.WriteLine("fileRetrieveThread still running. waiting."); - // System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5)); - // } - // Console.WriteLine($"fileRetrieveThread done ({fileRetrieveThread.ThreadState}). kbai"); + taskHeap.Add(Task.Run(FFStuff)); + taskHeap.Add(Task.Run(filePickup)); + cancelSource.Cancel(); + Task.WaitAll([.. taskHeap]); + Console.WriteLine("kbai"); } - private static async Task PrimaryVO(string scriptStripped) + private static async Task ttsVO(string scriptPath, string destPath) { - HttpContent fileStreamContent = new StreamContent(File.OpenRead(scriptStripped)); + HttpContent fileStreamContent = new StreamContent(File.OpenRead(scriptPath)); using (var formData = new MultipartFormDataContent()) { formData.Add(fileStreamContent, "file1", "file1"); @@ -298,8 +252,11 @@ namespace placeholdervo } else { - Console.WriteLine($"success; {await response.Content.ReadAsStringAsync()}."); - //TODO: add to queue to watch for? + var fname = await response.Content.ReadAsStringAsync(); + Console.WriteLine($"success; {fname}."); //"success" might be a strong word; it's successfully submitted. Its decided what filename it will, eventually, give it. + var ext = Path.GetExtension(fname); + Directory.CreateDirectory(conf.VODropoff); + awaitFile(Path.Combine(conf.sync_dropoff, fname), destPath + $".{ext}"); } } }