-
Notifications
You must be signed in to change notification settings - Fork 4
/
Piper.cs
53 lines (47 loc) · 1.33 KB
/
Piper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.IO;
using System.Threading.Tasks;
namespace Abuksigun.Piper
{
public sealed unsafe class Piper : IDisposable
{
PiperLib.PiperConfig* config;
public PiperLib.PiperConfig* Config => config;
Piper(PiperLib.PiperConfig* config)
{
this.config = config;
}
~Piper()
{
Dispose();
}
public void Dispose()
{
if (config != null)
{
PiperLib.terminatePiper(config);
PiperLib.destroy_PiperConfig(config);
config = null;
}
}
public static Task<Piper> LoadPiper(string fullEspeakDataPath)
{
if (!Directory.Exists(fullEspeakDataPath))
throw new DirectoryNotFoundException("Espeak data directory not found");
return Task.Run(() =>
{
var piperConfig = PiperLib.create_PiperConfig(fullEspeakDataPath);
try
{
PiperLib.initializePiper(piperConfig);
return Task.FromResult(new Piper(piperConfig));
}
catch
{
PiperLib.destroy_PiperConfig(piperConfig);
throw;
}
});
}
}
}