Upload files to "Managers"
This commit is contained in:
1 parent
a3289ddec7
commit
1765940692
4 files changed
+188
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GorillaCaptions.Managers;
|
||||
|
||||
public class SynthesizerManager : MonoBehaviour
|
||||
{
|
||||
public static SynthesizerManager instance { get; private set; }
|
||||
public static string voskPath;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
string resourcePath = "GorillaCaptions.Resources.QuickVosk.exe";
|
||||
voskPath = Path.Combine(Path.GetTempPath(), "QuickVosk.exe");
|
||||
|
||||
if (File.Exists(voskPath))
|
||||
File.Delete(voskPath);
|
||||
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
|
||||
using FileStream fs = new(voskPath, FileMode.Create, FileAccess.Write);
|
||||
stream.CopyTo(fs);
|
||||
}
|
||||
|
||||
public async Task<string> SynthesizeAudio(string audioPath)
|
||||
{
|
||||
ProcessStartInfo psi = new()
|
||||
{
|
||||
FileName = voskPath,
|
||||
Arguments = audioPath,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using Process proc = new() { StartInfo = psi };
|
||||
|
||||
string output = await Task.Run(() =>
|
||||
{
|
||||
proc.Start();
|
||||
string outStr = proc.StandardOutput.ReadToEnd();
|
||||
proc.WaitForExit();
|
||||
return outStr;
|
||||
});
|
||||
|
||||
string[] lines = output.Split("\n");
|
||||
string finalText = lines[lines.Length - 2];
|
||||
|
||||
if (finalText.Length <= 1)
|
||||
return null;
|
||||
|
||||
finalText = char.ToUpper(finalText[0]) + finalText.Substring(1);
|
||||
|
||||
return finalText;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user