mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
SpeechEnhancer -> SPXConverter
This commit is contained in:
parent
98f1dbe7a2
commit
8c80e79720
2 changed files with 14 additions and 109 deletions
|
@ -17,14 +17,21 @@ using UnityEngine;
|
|||
|
||||
namespace OpenTS2
|
||||
{
|
||||
public class SpeechEnhancer
|
||||
public class SPXConverter
|
||||
{
|
||||
[MenuItem("OpenTS2/Other/Improve Speech Using Tasks")]
|
||||
private static void EnhanceSpeechTasks()
|
||||
[MenuItem("OpenTS2/Experiments/Convert all SPX to WAV")]
|
||||
private static void ConvertSPX()
|
||||
{
|
||||
var baseGameOnly = false;
|
||||
var compressed = false;
|
||||
if (!EditorUtility.DisplayDialog("SPX to WAV", "This operation will convert ALL SPX resources to WAV. This will take a while and use a lot of resources. Proceed?", "Yes", "No"))
|
||||
return;
|
||||
baseGameOnly = EditorUtility.DisplayDialog("SPX to WAV", "Which products do you want to convert?", "Base-Game only", "All products");
|
||||
compressed = EditorUtility.DisplayDialog("SPX to WAV", "Do you want to compress the resulting packages?", "Yes", "No");
|
||||
Core.CoreInitialized = false;
|
||||
Core.InitializeCore();
|
||||
EPManager.Instance.InstalledProducts = (int)ProductFlags.BaseGame;
|
||||
if (baseGameOnly)
|
||||
EPManager.Instance.InstalledProducts = (int)ProductFlags.BaseGame;
|
||||
var epManager = EPManager.Instance;
|
||||
var products = epManager.GetInstalledProducts();
|
||||
var contentManager = ContentManager.Instance;
|
||||
|
@ -72,7 +79,7 @@ namespace OpenTS2
|
|||
{
|
||||
Debug.Log($"Starting work on {package}");
|
||||
var newPackage = new DBPFFile();
|
||||
newPackage.FilePath = Path.Combine("Enhanced Speech", package);
|
||||
newPackage.FilePath = Path.Combine("SPX to WAV", package);
|
||||
var entriesToDoForThisPackage = new List<DBPFEntry>();
|
||||
foreach (var spx in speechResources)
|
||||
{
|
||||
|
@ -102,7 +109,7 @@ namespace OpenTS2
|
|||
{
|
||||
var spxFile = new SPXFile(entry.GetBytes());
|
||||
if (spxFile != null && spxFile.DecompressedData != null && spxFile.DecompressedData.Length > 0)
|
||||
newPackage.Changes.Set(spxFile.DecompressedData, entry.TGI, false);
|
||||
newPackage.Changes.Set(spxFile.DecompressedData, entry.TGI, compressed);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -125,109 +132,7 @@ namespace OpenTS2
|
|||
}
|
||||
}, TaskScheduler.Default);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
|
||||
[MenuItem("OpenTS2/Other/Improve Speech")]
|
||||
private static void EnhanceSpeech()
|
||||
{
|
||||
Core.CoreInitialized = false;
|
||||
Core.InitializeCore();
|
||||
EPManager.Instance.InstalledProducts = (int)ProductFlags.BaseGame;
|
||||
var epManager = EPManager.Instance;
|
||||
var products = epManager.GetInstalledProducts();
|
||||
var contentManager = ContentManager.Instance;
|
||||
|
||||
foreach(var product in products)
|
||||
{
|
||||
var packages = Filesystem.GetPackagesInDirectory(Path.Combine(Filesystem.GetDataPathForProduct(product), "Res/Sound"));
|
||||
contentManager.AddPackages(packages);
|
||||
}
|
||||
|
||||
var audioResources = contentManager.ResourceMap.Where(x => x.Key.TypeID == TypeIDs.AUDIO);
|
||||
var speechResources = new List<DBPFEntry>();
|
||||
var speechPackages = new HashSet<string>();
|
||||
Debug.Log($"Found {audioResources.Count()} Audio Resources.");
|
||||
Debug.Log($"Looking for speech resources...");
|
||||
|
||||
new Thread(() =>
|
||||
{
|
||||
foreach (var audioResource in audioResources)
|
||||
{
|
||||
try
|
||||
{
|
||||
var audioData = audioResource.Value.GetBytes();
|
||||
var magic = Encoding.UTF8.GetString(audioData, 0, 2);
|
||||
if (magic == "SP")
|
||||
{
|
||||
speechResources.Add(audioResource.Value);
|
||||
var packageFileName = Path.GetFileName(audioResource.Value.Package.FilePath);
|
||||
speechPackages.Add(packageFileName);
|
||||
}
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
|
||||
Debug.Log($"Found {speechResources.Count} SPX audio resources, in {speechPackages.Count} packages.");
|
||||
var packagesStr = "Packages:";
|
||||
foreach(var package in speechPackages)
|
||||
{
|
||||
packagesStr += $"\n{package}";
|
||||
}
|
||||
Debug.Log(packagesStr);
|
||||
|
||||
GC.Collect();
|
||||
foreach(var package in speechPackages)
|
||||
{
|
||||
Debug.Log($"Starting work on {package}");
|
||||
var newPackage = new DBPFFile();
|
||||
newPackage.FilePath = Path.Combine("Enhanced Speech", package);
|
||||
var entriesToDoForThisPackage = new List<DBPFEntry>();
|
||||
foreach (var spx in speechResources)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (spx.Package == null) continue;
|
||||
if (Path.GetFileName(spx.Package.FilePath) != package) continue;
|
||||
entriesToDoForThisPackage.Add(spx);
|
||||
//var asset = spx.GetAsset<WAVAudioAsset>();
|
||||
//newPackage.Changes.Set(asset.GetWAVData(), asset.TGI, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
Debug.Log($"Will convert {entriesToDoForThisPackage.Count} Entries");
|
||||
var centry = 0;
|
||||
foreach(var entry in entriesToDoForThisPackage)
|
||||
{
|
||||
centry += 1;
|
||||
if (centry % 500 == 0)
|
||||
Debug.Log($"Progress: {centry}/{entriesToDoForThisPackage.Count}");
|
||||
try
|
||||
{
|
||||
var spxFile = new SPXFile(entry.GetBytes());
|
||||
if (spxFile != null && spxFile.DecompressedData != null && spxFile.DecompressedData.Length > 0)
|
||||
newPackage.Changes.Set(spxFile.DecompressedData, entry.TGI, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
Debug.Log("Writing to disk...");
|
||||
newPackage.WriteToFile();
|
||||
Debug.Log($"Completed {package}!");
|
||||
GC.Collect();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
Debug.Log("All SPX has been converted to WAV! Resulting packages have been written to the SPX to WAV folder.");
|
||||
}).Start();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue