ailia_voice  1.1.0.0
Public Member Functions | Protected Member Functions | List of all members
ailiaVoice.AiliaVoiceModel Class Reference
Inheritance diagram for ailiaVoice.AiliaVoiceModel:
Inheritance graph
[legend]
Collaboration diagram for ailiaVoice.AiliaVoiceModel:
Collaboration graph
[legend]

Public Member Functions

int GetEnvironmentId (bool is_gpu)
 Get the environmen id. More...
 
string GetEnvironmentName ()
 Get the environmen name. More...
 
bool Create (int env_id, int flag)
 Create a instance. More...
 
bool OpenDictionary (string dict_path, int dict_type)
 
bool OpenModel (string encoder, string decoder1, string decoder2, string wave, string ssl, int model_type, int cleaner_type)
 
virtual void Close ()
 Destroys instance. More...
 
virtual void Dispose ()
 Release resources. More...
 
string G2P (string utf8, int g2p_type)
 Get features. More...
 
bool SetReference (AudioClip ref_audio, string ref_text)
 Set reference audio. More...
 
bool Inference (string feature)
 Perform inference. More...
 
AudioClip GetAudioClip ()
 Get audio clip. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Member Function Documentation

◆ Close()

virtual void ailiaVoice.AiliaVoiceModel.Close ( )
inlinevirtual

Destroys instance.

Destroys and initializes the instance.

197  {
198  if (net != IntPtr.Zero){
199  AiliaVoice.ailiaVoiceDestroy(net);
200  net = IntPtr.Zero;
201  }
202  }

◆ Create()

bool ailiaVoice.AiliaVoiceModel.Create ( int  env_id,
int  flag 
)
inline

Create a instance.

Parameters
env_idEnvironment ID of ailia
flagOR of flags (AiliaVoice.AILIA_VOICE_FLAG_*)
Returns
If this function is successful, it returns true , or false otherwise.
99  {
100  if (net != null){
101  Close();
102  }
103 
104  AiliaVoice.AILIAVoiceApiCallback callback = AiliaVoice.GetCallback();
105 
106  int memory_mode = Ailia.AILIA_MEMORY_REDUCE_CONSTANT | Ailia.AILIA_MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER | Ailia.AILIA_MEMORY_REUSE_INTERSTAGE;
107  int status = AiliaVoice.ailiaVoiceCreate(ref net, env_id, Ailia.AILIA_MULTITHREAD_AUTO, memory_mode, flag, callback, AiliaVoice.AILIA_VOICE_API_CALLBACK_VERSION);
108  if (status != 0){
109  if (debug_log){
110  Debug.Log("ailiaVoiceCreate failed " + status);
111  }
112  return false;
113  }
114 
115  return true;
116  }

◆ Dispose() [1/2]

virtual void ailiaVoice.AiliaVoiceModel.Dispose ( )
inlinevirtual

Release resources.

212  {
213  Dispose(true);
214  }

◆ Dispose() [2/2]

virtual void ailiaVoice.AiliaVoiceModel.Dispose ( bool  disposing)
inlineprotectedvirtual
217  {
218  if (disposing){
219  // release managed resource
220  }
221  Close(); // release unmanaged resource
222  }

◆ G2P()

string ailiaVoice.AiliaVoiceModel.G2P ( string  utf8,
int  g2p_type 
)
inline

Get features.

Parameters
utf8Input string
g2p_typeG2P type
Returns
If this function is successful, it returns string , or empty string otherwise.
247  {
248  byte[] text = System.Text.Encoding.UTF8.GetBytes(utf8+"\u0000");
249  //Debug.Log(text[text.Length - 1]);
250  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
251  IntPtr input = handle.AddrOfPinnedObject();
252  int status = AiliaVoice.ailiaVoiceGraphemeToPhoneme(net, input, g2p_type);
253  handle.Free();
254  if (status != 0){
255  if (debug_log){
256  Debug.Log("ailiaVoiceGraphemeToPhoneme faield " + status);
257  }
258  return "";
259  }
260  uint count = 0;
261  status = AiliaVoice.ailiaVoiceGetFeatureLength(net, ref count);
262  if (status != 0){
263  if (debug_log){
264  Debug.Log("ailiaVoiceGetFeatureLength faield " + status);
265  }
266  return "";
267  }
268  byte[] texts = new byte [count];
269  handle = GCHandle.Alloc(texts, GCHandleType.Pinned);
270  IntPtr output = handle.AddrOfPinnedObject();
271  status = AiliaVoice.ailiaVoiceGetFeatures(net, output, count);
272  handle.Free();
273  if (status != 0){
274  if (debug_log){
275  Debug.Log("ailiaVoiceGetFeatures faield " + status);
276  }
277  return "";
278  }
279  return System.Text.Encoding.UTF8.GetString(texts);
280  }

◆ GetAudioClip()

AudioClip ailiaVoice.AiliaVoiceModel.GetAudioClip ( )
inline

Get audio clip.

Returns
If this function is successful, it returns AudioClip , or null otherwise.
386  {
387  AudioClip audioClip = AudioClip.Create(audio_clip_name, audio_data.Length, (int)channels, (int)sampling_rate, false);
388  audioClip.SetData(audio_data, 0);
389  return audioClip;
390  }

◆ GetEnvironmentId()

int ailiaVoice.AiliaVoiceModel.GetEnvironmentId ( bool  is_gpu)
inline

Get the environmen id.

Parameters
is_gpuWhether to use GPU
Returns
env_id
44  {
45  int env_id = Ailia.AILIA_ENVIRONMENT_ID_AUTO;
46  if (is_gpu) { // GPU
47  int count = 0;
48  Ailia.ailiaGetEnvironmentCount(ref count);
49  for (int i = 0; i < count; i++){
50  IntPtr env_ptr = IntPtr.Zero;
51  Ailia.ailiaGetEnvironment(ref env_ptr, (uint)i, Ailia.AILIA_ENVIRONMENT_VERSION);
52  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
53 
54  if (env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_MPS || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_CUDA || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_VULKAN){
55  env_id = env.id;
56  env_name = Marshal.PtrToStringAnsi(env.name);
57  }
58  }
59  } else {
60  env_name = "cpu";
61  }
62  return env_id;
63  }

◆ GetEnvironmentName()

string ailiaVoice.AiliaVoiceModel.GetEnvironmentName ( )
inline

Get the environmen name.

Returns
env_name
76  {
77  return env_name;
78  }

◆ Inference()

bool ailiaVoice.AiliaVoiceModel.Inference ( string  feature)
inline

Perform inference.

Parameters
featureInput feature string
Returns
If this function is successful, it returns true , or false otherwise.
336  {
337  byte[] text = System.Text.Encoding.UTF8.GetBytes(feature);
338  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
339  IntPtr input = handle.AddrOfPinnedObject();
340  int status = AiliaVoice.ailiaVoiceInference(net, input);
341  handle.Free();
342  if (status != 0){
343  if (debug_log){
344  Debug.Log("ailiaVoiceInference faield " + status);
345  }
346  return false;
347  }
348  status = AiliaVoice.ailiaVoiceGetWaveInfo(net, ref samples, ref channels, ref sampling_rate);
349  if (status != 0){
350  if (debug_log){
351  Debug.Log("ailiaVoiceGetWaveInfo faield " + status);
352  }
353  return false;
354  }
355 
356  uint count = samples * channels;
357  audio_data = new float [count];
358  handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
359  IntPtr output = handle.AddrOfPinnedObject();
360  status = AiliaVoice.ailiaVoiceGetWave(net, output, count * sizeof(float));
361  handle.Free();
362  if (status != 0){
363  if (debug_log){
364  Debug.Log("ailiaVoiceGetWave faield " + status);
365  }
366  return false;
367  }
368 
369  audio_clip_name = feature;
370 
371  return true;
372  }

◆ OpenDictionary()

bool ailiaVoice.AiliaVoiceModel.OpenDictionary ( string  dict_path,
int  dict_type 
)
inline
Parameters
netA network instance pointer
dictionary_pathThe path name to the dictionary folder
dictionary_typeAILIA_VOICE_DICTIONARY_TYPE_*
Returns
If this function is successful, it returns true , or false otherwise.
133  {
134  int status = AiliaVoice.ailiaVoiceOpenDictionaryFile(net, dict_path, dict_type);
135  if (status != 0){
136  if (debug_log){
137  Debug.Log("ailiaVoiceOpenDictionaryFile faield " + status);
138  }
139  return false;
140  }
141  return true;
142  }

◆ OpenModel()

bool ailiaVoice.AiliaVoiceModel.OpenModel ( string  encoder,
string  decoder1,
string  decoder2,
string  wave,
string  ssl,
int  model_type,
int  cleaner_type 
)
inline
Parameters
netA network instance pointer
encoderThe path name to the onnx file
decoder1The path name to the onnx file
decoder2The path name to the onnx file
waveThe path name to the onnx file
sslThe path name to the onnx file
model_typeAILIA_VOICE_MODEL_TYPE_*
cleaner_typeAILIA_VOICE_CLEANER_TYPE_*
Returns
If this function is successful, it returns true , or false otherwise.
169  {
170  AiliaLicense.CheckAndDownloadLicense();
171 
172  int status = AiliaVoice.ailiaVoiceOpenModelFile(net, encoder, decoder1, decoder2, wave, ssl, model_type, cleaner_type);
173  if (status != 0){
174  if (debug_log){
175  Debug.Log("ailiaVoiceOpenModelFile faield " + status);
176  }
177  return false;
178  }
179  return true;
180  }

◆ SetReference()

bool ailiaVoice.AiliaVoiceModel.SetReference ( AudioClip  ref_audio,
string  ref_text 
)
inline

Set reference audio.

Parameters
ref_audioReference audio
ref_textReference text
Returns
If this function is successful, it returns AudioClip , or null otherwise.
298  {
299  float[] audio_data = new float[ref_audio.samples * ref_audio.channels];
300  ref_audio.GetData(audio_data, 0);
301 
302  GCHandle audio_handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
303  IntPtr audio_input = audio_handle.AddrOfPinnedObject();
304 
305  byte[] text = System.Text.Encoding.UTF8.GetBytes(ref_text);
306  GCHandle text_handle = GCHandle.Alloc(text, GCHandleType.Pinned);
307  IntPtr text_input = text_handle.AddrOfPinnedObject();
308  int status = AiliaVoice.ailiaVoiceSetReference(net, audio_input, (uint)(ref_audio.samples * ref_audio.channels * 4), (uint)(ref_audio.channels), (uint)(ref_audio.frequency), text_input);
309  text_handle.Free();
310  audio_handle.Free();
311 
312  if (status != 0){
313  if (debug_log){
314  Debug.Log("ailiaVoiceSetReference faield " + status);
315  }
316  return false;
317  }
318 
319  return true;
320  }

The documentation for this class was generated from the following file:
ailiaVoice.AiliaVoiceModel.Dispose
virtual void Dispose()
Release resources.
Definition: AiliaVoiceModel.cs:211
ailiaVoice.AiliaVoiceModel.Close
virtual void Close()
Destroys instance.
Definition: AiliaVoiceModel.cs:196