mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 21:48:58 +03:00
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Threading.Tasks;
|
|
using Content.Shared._White.TTS;
|
|
using Robust.Shared.ContentPack;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Server._White.TTS;
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
public sealed partial class TTSSystem
|
|
{
|
|
[Dependency] private readonly IResourceManager _resourceManager = default!;
|
|
|
|
private ResPath GetCacheId(TTSVoicePrototype voicePrototype, string cacheId)
|
|
{
|
|
var resPath = new ResPath($"voicecache/{voicePrototype.ID}/{cacheId}.ogg").ToRootedPath();
|
|
_resourceManager.UserData.CreateDir(resPath.Directory);
|
|
return resPath.ToRootedPath();
|
|
}
|
|
private async Task<byte[]?> GetFromCache(ResPath resPath)
|
|
{
|
|
if (!_resourceManager.UserData.Exists(resPath))
|
|
return null;
|
|
|
|
await using var reader = _resourceManager.UserData.OpenRead(resPath);
|
|
return reader.CopyToArray();
|
|
}
|
|
|
|
private async Task SaveVoiceCache(ResPath resPath, byte[] data)
|
|
{
|
|
await using var writer = _resourceManager.UserData.OpenWrite(resPath);
|
|
await writer.WriteAsync(data);
|
|
}
|
|
}
|