-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPiperLib.cs
133 lines (101 loc) · 4.77 KB
/
PiperLib.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Abuksigun.Piper
{
public unsafe static class PiperLib
{
private const string DllName = "piperlib"; // Replace with the actual name of your DLL
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct PiperConfig
{
//public string eSpeakDataPath;
//public bool useESpeak;
//public bool useTashkeel;
//public OptionalString tashkeelModelPath;
//public IntPtr tashkeelState; // Assuming tashkeel::State is represented as a pointer/handle
}
public struct OptionalString
{
//public bool hasValue;
//public string value;
}
[StructLayout(LayoutKind.Sequential)]
public struct SynthesisConfig
{
public struct OptionalLong
{
public bool hasValue;
public long value;
}
[StructLayout(LayoutKind.Sequential)]
public struct OptionalPhonemeSilenceSecondsMap
{
public bool hasValue;
public PhonemeSilenceSecondsMap* value;
}
public float noiseScale;
public float lengthScale;
public float noiseW;
public int sampleRate;
public int sampleWidth;
public int channels;
public OptionalLong speakerId;
public float sentenceSilenceSeconds;
public OptionalPhonemeSilenceSecondsMap phonemeSilenceSeconds;
}
[StructLayout(LayoutKind.Sequential)]
public struct PhonemeSilenceSecondsMap
{
public int phoneme;
public float silenceSeconds;
}
[StructLayout(LayoutKind.Sequential)]
public struct SynthesisResult
{
public double inferSeconds;
public double audioSeconds;
public double realTimeFactor;
}
[StructLayout(LayoutKind.Sequential)]
public struct Voice
{
//public IntPtr configRoot; // Handle for json
//public PhonemizeConfig phonemizeConfig;
//public SynthesisConfig synthesisConfig;
//public ModelConfig modelConfig;
//public ModelSession session;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void AudioCallback();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern PiperConfig* create_PiperConfig(string eSpeakDataPath);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void destroy_PiperConfig(PiperConfig* config);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern Voice* create_Voice();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void destroy_Voice(Voice* voice);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern SynthesisConfig getSynthesisConfig(Voice* voice);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern bool isSingleCodepoint(string s);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern char getCodepoint(string s);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr getVersion();
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void initializePiper(PiperConfig* config);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
public static extern void terminatePiper(PiperConfig* config);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void loadVoice(PiperConfig* config, string modelPath, string modelConfigPath, Voice* voice, Int64* speakerId);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void AudioCallbackDelegate(short* audioBuffer, int length);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void textToAudio(PiperConfig* config, Voice* voice, string text, SynthesisResult* result, AudioCallbackDelegate audioCallback);
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern void textToWavFile(PiperConfig* config, Voice* voice, string text, string audioFile, SynthesisResult* result);
}
}