ailia_voice  1.5.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)
 
bool OpenTacotron2ModelFile (string encoder, string decoder1, string decoder2, string wave, int cleaner_type)
 Open Tacotron2 model. More...
 
bool OpenGPTSoVITSV1ModelFile (string encoder, string decoder1, string decoder2, string wave, string ssl)
 Open GPT-SoVITS V1 model. More...
 
bool OpenGPTSoVITSV2ModelFile (string encoder, string decoder1, string decoder2, string wave, string ssl, string chinese_bert, string vocab)
 Open GPT-SoVITS V2 model. More...
 
bool OpenGPTSoVITSV3ModelFile (string encoder, string decoder1, string decoder2, string ssl, string vq, string cfm, string bigvgan, string chinese_bert, string vocab)
 Open GPT-SoVITS V3 model. More...
 
bool OpenGPTSoVITSV2ProModelFile (string encoder, string decoder1, string decoder2, string ssl, string vits, string sv, string chinese_bert, string vocab)
 Open GPT-SoVITS V2-Pro model. More...
 
bool SetSampleSteps (int steps)
 Set CFM sampling steps. More...
 
bool SetSpeed (float speed)
 Set the speech speed for synthesis. More...
 
bool SetModelType (int model_type)
 Set the model type for G2P processing. More...
 
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.

499  {
500  if (net != IntPtr.Zero){
501  AiliaVoice.ailiaVoiceDestroy(net);
502  net = IntPtr.Zero;
503  }
504  }

◆ 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  }
virtual void Close()
Destroys instance.
Definition: AiliaVoiceModel.cs:498

◆ Dispose() [1/2]

virtual void ailiaVoice.AiliaVoiceModel.Dispose ( )
inlinevirtual

Release resources.

514  {
515  Dispose(true);
516  }
virtual void Dispose()
Release resources.
Definition: AiliaVoiceModel.cs:513

◆ Dispose() [2/2]

virtual void ailiaVoice.AiliaVoiceModel.Dispose ( bool  disposing)
inlineprotectedvirtual
519  {
520  if (disposing){
521  // release managed resource
522  }
523  Close(); // release unmanaged resource
524  }

◆ 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.
549  {
550  byte[] text = System.Text.Encoding.UTF8.GetBytes(utf8+"\u0000");
551  //Debug.Log(text[text.Length - 1]);
552  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
553  IntPtr input = handle.AddrOfPinnedObject();
554  int status = AiliaVoice.ailiaVoiceGraphemeToPhoneme(net, input, g2p_type);
555  handle.Free();
556  if (status != 0){
557  if (debug_log){
558  Debug.Log("ailiaVoiceGraphemeToPhoneme faield " + status);
559  }
560  return "";
561  }
562  uint count = 0;
563  status = AiliaVoice.ailiaVoiceGetFeatureLength(net, ref count);
564  if (status != 0){
565  if (debug_log){
566  Debug.Log("ailiaVoiceGetFeatureLength faield " + status);
567  }
568  return "";
569  }
570  byte[] texts = new byte [count];
571  handle = GCHandle.Alloc(texts, GCHandleType.Pinned);
572  IntPtr output = handle.AddrOfPinnedObject();
573  status = AiliaVoice.ailiaVoiceGetFeatures(net, output, count);
574  handle.Free();
575  if (status != 0){
576  if (debug_log){
577  Debug.Log("ailiaVoiceGetFeatures faield " + status);
578  }
579  return "";
580  }
581  return System.Text.Encoding.UTF8.GetString(texts);
582  }

◆ GetAudioClip()

AudioClip ailiaVoice.AiliaVoiceModel.GetAudioClip ( )
inline

Get audio clip.

Returns
If this function is successful, it returns AudioClip , or null otherwise.
688  {
689  AudioClip audioClip = AudioClip.Create(audio_clip_name, audio_data.Length, (int)channels, (int)sampling_rate, false);
690  audioClip.SetData(audio_data, 0);
691  return audioClip;
692  }

◆ 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.
638  {
639  byte[] text = System.Text.Encoding.UTF8.GetBytes(feature);
640  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
641  IntPtr input = handle.AddrOfPinnedObject();
642  int status = AiliaVoice.ailiaVoiceInference(net, input);
643  handle.Free();
644  if (status != 0){
645  if (debug_log){
646  Debug.Log("ailiaVoiceInference faield " + status);
647  }
648  return false;
649  }
650  status = AiliaVoice.ailiaVoiceGetWaveInfo(net, ref samples, ref channels, ref sampling_rate);
651  if (status != 0){
652  if (debug_log){
653  Debug.Log("ailiaVoiceGetWaveInfo faield " + status);
654  }
655  return false;
656  }
657 
658  uint count = samples * channels;
659  audio_data = new float [count];
660  handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
661  IntPtr output = handle.AddrOfPinnedObject();
662  status = AiliaVoice.ailiaVoiceGetWave(net, output, count * sizeof(float));
663  handle.Free();
664  if (status != 0){
665  if (debug_log){
666  Debug.Log("ailiaVoiceGetWave faield " + status);
667  }
668  return false;
669  }
670 
671  audio_clip_name = feature;
672 
673  return true;
674  }

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

◆ OpenGPTSoVITSV1ModelFile()

bool ailiaVoice.AiliaVoiceModel.OpenGPTSoVITSV1ModelFile ( string  encoder,
string  decoder1,
string  decoder2,
string  wave,
string  ssl 
)
inline

Open GPT-SoVITS V1 model.

Parameters
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
Returns
If this function is successful, it returns true , or false otherwise.
269  {
270  AiliaLicense.CheckAndDownloadLicense();
271 
272  int status = AiliaVoice.ailiaVoiceOpenGPTSoVITSV1ModelFile(net, encoder, decoder1, decoder2, wave, ssl);
273  if (status != 0){
274  if (debug_log){
275  Debug.Log("ailiaVoiceOpenGPTSoVITSV1ModelFile failed " + status);
276  }
277  return false;
278  }
279  return true;
280  }

◆ OpenGPTSoVITSV2ModelFile()

bool ailiaVoice.AiliaVoiceModel.OpenGPTSoVITSV2ModelFile ( string  encoder,
string  decoder1,
string  decoder2,
string  wave,
string  ssl,
string  chinese_bert,
string  vocab 
)
inline

Open GPT-SoVITS V2 model.

Parameters
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
chinese_bertThe path name to the chinese-roberta.onnx file (null to disable Chinese BERT)
vocabThe path name to the vocab.txt file (null to disable Chinese BERT)
Returns
If this function is successful, it returns true , or false otherwise.
307  {
308  AiliaLicense.CheckAndDownloadLicense();
309 
310  int status = AiliaVoice.ailiaVoiceOpenGPTSoVITSV2ModelFile(net, encoder, decoder1, decoder2, wave, ssl, chinese_bert, vocab);
311  if (status != 0){
312  if (debug_log){
313  Debug.Log("ailiaVoiceOpenGPTSoVITSV2ModelFile failed " + status);
314  }
315  return false;
316  }
317  return true;
318  }

◆ OpenGPTSoVITSV2ProModelFile()

bool ailiaVoice.AiliaVoiceModel.OpenGPTSoVITSV2ProModelFile ( string  encoder,
string  decoder1,
string  decoder2,
string  ssl,
string  vits,
string  sv,
string  chinese_bert,
string  vocab 
)
inline

Open GPT-SoVITS V2-Pro model.

Parameters
encoderThe path name to the onnx file
decoder1The path name to the onnx file
decoder2The path name to the onnx file
sslThe path name to the onnx file
vitsThe path name to the onnx file
svThe path name to the onnx file
chinese_bertThe path name to the chinese-roberta.onnx file (null to disable Chinese BERT)
vocabThe path name to the vocab.txt file (null to disable Chinese BERT)
Returns
If this function is successful, it returns true , or false otherwise.
389  {
390  AiliaLicense.CheckAndDownloadLicense();
391 
392  int status = AiliaVoice.ailiaVoiceOpenGPTSoVITSV2ProModelFile(net, encoder, decoder1, decoder2, ssl, vits, sv, chinese_bert, vocab);
393  if (status != 0){
394  if (debug_log){
395  Debug.Log("ailiaVoiceOpenGPTSoVITSV2ProModelFile failed " + status);
396  }
397  return false;
398  }
399  return true;
400  }

◆ OpenGPTSoVITSV3ModelFile()

bool ailiaVoice.AiliaVoiceModel.OpenGPTSoVITSV3ModelFile ( string  encoder,
string  decoder1,
string  decoder2,
string  ssl,
string  vq,
string  cfm,
string  bigvgan,
string  chinese_bert,
string  vocab 
)
inline

Open GPT-SoVITS V3 model.

Parameters
encoderThe path name to the onnx file
decoder1The path name to the onnx file
decoder2The path name to the onnx file
sslThe path name to the onnx file
vqThe path name to the onnx file
cfmThe path name to the onnx file
bigvganThe path name to the onnx file
chinese_bertThe path name to the chinese-roberta.onnx file (null to disable Chinese BERT)
vocabThe path name to the vocab.txt file (null to disable Chinese BERT)
Returns
If this function is successful, it returns true , or false otherwise.
349  {
350  AiliaLicense.CheckAndDownloadLicense();
351 
352  int status = AiliaVoice.ailiaVoiceOpenGPTSoVITSV3ModelFile(net, encoder, decoder1, decoder2, ssl, vq, cfm, bigvgan, chinese_bert, vocab);
353  if (status != 0){
354  if (debug_log){
355  Debug.Log("ailiaVoiceOpenGPTSoVITSV3ModelFile failed " + status);
356  }
357  return false;
358  }
359  return true;
360  }

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

◆ OpenTacotron2ModelFile()

bool ailiaVoice.AiliaVoiceModel.OpenTacotron2ModelFile ( string  encoder,
string  decoder1,
string  decoder2,
string  wave,
int  cleaner_type 
)
inline

Open Tacotron2 model.

Parameters
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
cleaner_typeAILIA_VOICE_CLEANER_TYPE_*
Returns
If this function is successful, it returns true , or false otherwise.
235  {
236  AiliaLicense.CheckAndDownloadLicense();
237 
238  int status = AiliaVoice.ailiaVoiceOpenTacotron2ModelFile(net, encoder, decoder1, decoder2, wave, cleaner_type);
239  if (status != 0){
240  if (debug_log){
241  Debug.Log("ailiaVoiceOpenTacotron2ModelFile failed " + status);
242  }
243  return false;
244  }
245  return true;
246  }

◆ SetModelType()

bool ailiaVoice.AiliaVoiceModel.SetModelType ( int  model_type)
inline

Set the model type for G2P processing.

Parameters
model_typeAILIA_VOICE_MODEL_TYPE_*
Returns
If this function is successful, it returns true , or false otherwise.

Sets the model type when using G2P standalone without loading model files. Automatically set when OpenModel or OpenGPTSoVITSV3ModelFile is called.

473  {
474  int status = AiliaVoice.ailiaVoiceSetModelType(net, model_type);
475  if (status != 0){
476  if (debug_log){
477  Debug.Log("ailiaVoiceSetModelType failed " + status);
478  }
479  return false;
480  }
481  return true;
482  }

◆ 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.
600  {
601  float[] audio_data = new float[ref_audio.samples * ref_audio.channels];
602  ref_audio.GetData(audio_data, 0);
603 
604  GCHandle audio_handle = GCHandle.Alloc(audio_data, GCHandleType.Pinned);
605  IntPtr audio_input = audio_handle.AddrOfPinnedObject();
606 
607  byte[] text = System.Text.Encoding.UTF8.GetBytes(ref_text);
608  GCHandle text_handle = GCHandle.Alloc(text, GCHandleType.Pinned);
609  IntPtr text_input = text_handle.AddrOfPinnedObject();
610  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);
611  text_handle.Free();
612  audio_handle.Free();
613 
614  if (status != 0){
615  if (debug_log){
616  Debug.Log("ailiaVoiceSetReference faield " + status);
617  }
618  return false;
619  }
620 
621  return true;
622  }

◆ SetSampleSteps()

bool ailiaVoice.AiliaVoiceModel.SetSampleSteps ( int  steps)
inline

Set CFM sampling steps.

Parameters
stepsNumber of sampling steps
Returns
If this function is successful, it returns true , or false otherwise.
415  {
416  int status = AiliaVoice.ailiaVoiceSetSampleSteps(net, steps);
417  if (status != 0){
418  if (debug_log){
419  Debug.Log("ailiaVoiceSetSampleSteps failed " + status);
420  }
421  return false;
422  }
423  return true;
424  }

◆ SetSpeed()

bool ailiaVoice.AiliaVoiceModel.SetSpeed ( float  speed)
inline

Set the speech speed for synthesis.

Parameters
speedSpeed value (default 1.0, must be greater than 0)
Returns
If this function is successful, it returns true , or false otherwise.

Supported by GPT-SoVITS V2 and V3. Not effective for V1.

443  {
444  int status = AiliaVoice.ailiaVoiceSetSpeed(net, speed);
445  if (status != 0){
446  if (debug_log){
447  Debug.Log("ailiaVoiceSetSpeed failed " + status);
448  }
449  return false;
450  }
451  return true;
452  }

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