ailia_voice  1.3.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 SetUserDictionary (string dict_path, int dict_type)
 Set user dictionary file. More...
 
bool OpenDictionary (string dict_path, int dict_type)
 Set dictionary path. More...
 
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.

229  {
230  if (net != IntPtr.Zero){
231  AiliaVoice.ailiaVoiceDestroy(net);
232  net = IntPtr.Zero;
233  }
234  }

◆ 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.

244  {
245  Dispose(true);
246  }

◆ Dispose() [2/2]

virtual void ailiaVoice.AiliaVoiceModel.Dispose ( bool  disposing)
inlineprotectedvirtual
249  {
250  if (disposing){
251  // release managed resource
252  }
253  Close(); // release unmanaged resource
254  }

◆ 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.
279  {
280  byte[] text = System.Text.Encoding.UTF8.GetBytes(utf8+"\u0000");
281  //Debug.Log(text[text.Length - 1]);
282  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
283  IntPtr input = handle.AddrOfPinnedObject();
284  int status = AiliaVoice.ailiaVoiceGraphemeToPhoneme(net, input, g2p_type);
285  handle.Free();
286  if (status != 0){
287  if (debug_log){
288  Debug.Log("ailiaVoiceGraphemeToPhoneme faield " + status);
289  }
290  return "";
291  }
292  uint count = 0;
293  status = AiliaVoice.ailiaVoiceGetFeatureLength(net, ref count);
294  if (status != 0){
295  if (debug_log){
296  Debug.Log("ailiaVoiceGetFeatureLength faield " + status);
297  }
298  return "";
299  }
300  byte[] texts = new byte [count];
301  handle = GCHandle.Alloc(texts, GCHandleType.Pinned);
302  IntPtr output = handle.AddrOfPinnedObject();
303  status = AiliaVoice.ailiaVoiceGetFeatures(net, output, count);
304  handle.Free();
305  if (status != 0){
306  if (debug_log){
307  Debug.Log("ailiaVoiceGetFeatures faield " + status);
308  }
309  return "";
310  }
311  return System.Text.Encoding.UTF8.GetString(texts);
312  }

◆ GetAudioClip()

AudioClip ailiaVoice.AiliaVoiceModel.GetAudioClip ( )
inline

Get audio clip.

Returns
If this function is successful, it returns AudioClip , or null otherwise.
418  {
419  AudioClip audioClip = AudioClip.Create(audio_clip_name, audio_data.Length, (int)channels, (int)sampling_rate, false);
420  audioClip.SetData(audio_data, 0);
421  return audioClip;
422  }

◆ 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.
368  {
369  byte[] text = System.Text.Encoding.UTF8.GetBytes(feature);
370  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
371  IntPtr input = handle.AddrOfPinnedObject();
372  int status = AiliaVoice.ailiaVoiceInference(net, input);
373  handle.Free();
374  if (status != 0){
375  if (debug_log){
376  Debug.Log("ailiaVoiceInference faield " + status);
377  }
378  return false;
379  }
380  status = AiliaVoice.ailiaVoiceGetWaveInfo(net, ref samples, ref channels, ref sampling_rate);
381  if (status != 0){
382  if (debug_log){
383  Debug.Log("ailiaVoiceGetWaveInfo faield " + status);
384  }
385  return false;
386  }
387 
388  uint count = samples * channels;
389  audio_data = new float [count];
390  handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
391  IntPtr output = handle.AddrOfPinnedObject();
392  status = AiliaVoice.ailiaVoiceGetWave(net, output, count * sizeof(float));
393  handle.Free();
394  if (status != 0){
395  if (debug_log){
396  Debug.Log("ailiaVoiceGetWave faield " + status);
397  }
398  return false;
399  }
400 
401  audio_clip_name = feature;
402 
403  return true;
404  }

◆ OpenDictionary()

bool ailiaVoice.AiliaVoiceModel.OpenDictionary ( string  dict_path,
int  dict_type 
)
inline

Set dictionary path.

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.
165  {
166  int status = AiliaVoice.ailiaVoiceOpenDictionaryFile(net, dict_path, dict_type);
167  if (status != 0){
168  if (debug_log){
169  Debug.Log("ailiaVoiceOpenDictionaryFile faield " + status);
170  }
171  return false;
172  }
173  return true;
174  }

◆ 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.
201  {
202  AiliaLicense.CheckAndDownloadLicense();
203 
204  int status = AiliaVoice.ailiaVoiceOpenModelFile(net, encoder, decoder1, decoder2, wave, ssl, model_type, cleaner_type);
205  if (status != 0){
206  if (debug_log){
207  Debug.Log("ailiaVoiceOpenModelFile faield " + status);
208  }
209  return false;
210  }
211  return true;
212  }

◆ 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.
330  {
331  float[] audio_data = new float[ref_audio.samples * ref_audio.channels];
332  ref_audio.GetData(audio_data, 0);
333 
334  GCHandle audio_handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
335  IntPtr audio_input = audio_handle.AddrOfPinnedObject();
336 
337  byte[] text = System.Text.Encoding.UTF8.GetBytes(ref_text);
338  GCHandle text_handle = GCHandle.Alloc(text, GCHandleType.Pinned);
339  IntPtr text_input = text_handle.AddrOfPinnedObject();
340  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);
341  text_handle.Free();
342  audio_handle.Free();
343 
344  if (status != 0){
345  if (debug_log){
346  Debug.Log("ailiaVoiceSetReference faield " + status);
347  }
348  return false;
349  }
350 
351  return true;
352  }

◆ SetUserDictionary()

bool ailiaVoice.AiliaVoiceModel.SetUserDictionary ( string  dict_path,
int  dict_type 
)
inline

Set user dictionary file.

Parameters
netA network instance pointer
dictionary_pathThe path name to the user dictionary file
dictionary_typeAILIA_VOICE_DICTIONARY_TYPE_*
Returns
If this function is successful, it returns true , or false otherwise.

You need to call before OpenDictionary.

138  {
139  int status = AiliaVoice.ailiaVoiceSetUserDictionaryFile(net, dict_path, dict_type);
140  if (status != 0){
141  if (debug_log){
142  Debug.Log("ailiaVoiceSetUserDictionaryFile faield " + status);
143  }
144  return false;
145  }
146  return true;
147  }

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