ailia_speech  1.3.0.0
Public Member Functions | Protected Member Functions | List of all members
ailiaSpeech.AiliaSpeechTranslateModel Class Reference
Inheritance diagram for ailiaSpeech.AiliaSpeechTranslateModel:
Inheritance graph
[legend]
Collaboration diagram for ailiaSpeech.AiliaSpeechTranslateModel:
Collaboration graph
[legend]

Public Member Functions

bool IsError ()
 Check is error occured. More...
 
string GetErrorDetail ()
 Get error detail. More...
 
int GetEnvironmentId (bool is_gpu)
 Get the environmen id. More...
 
string GetEnvironmentName ()
 Get the environmen name. More...
 
bool Open (string encoder_path, string decoder_path, string source_path, string target_path, int type, int env_id, int memory_mode)
 Create a instance. More...
 
virtual void Close ()
 Destroys instance. More...
 
virtual void Dispose ()
 Release resources. More...
 
string Translate (string input_text)
 Perform speech recognition. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Member Function Documentation

◆ Close()

virtual void ailiaSpeech.AiliaSpeechTranslateModel.Close ( )
inlinevirtual

Destroys instance.

Destroys and initializes the instance.

203  {
204  if (net != IntPtr.Zero){
205  AiliaSpeech.ailiaSpeechDestroy(net);
206  net = IntPtr.Zero;
207  }
208  }

◆ Dispose() [1/2]

virtual void ailiaSpeech.AiliaSpeechTranslateModel.Dispose ( )
inlinevirtual

Release resources.

218  {
219  Dispose(true);
220  }

◆ Dispose() [2/2]

virtual void ailiaSpeech.AiliaSpeechTranslateModel.Dispose ( bool  disposing)
inlineprotectedvirtual
223  {
224  if (disposing){
225  // release managed resource
226  }
227  Close(); // release unmanaged resource
228  }

◆ GetEnvironmentId()

int ailiaSpeech.AiliaSpeechTranslateModel.GetEnvironmentId ( bool  is_gpu)
inline

Get the environmen id.

Parameters
is_gpuWhether to use GPU
Returns
env_id
91  {
92  int env_id = Ailia.AILIA_ENVIRONMENT_ID_AUTO;
93  if (is_gpu) { // GPU
94  int count = 0;
95  Ailia.ailiaGetEnvironmentCount(ref count);
96  for (int i = 0; i < count; i++){
97  IntPtr env_ptr = IntPtr.Zero;
98  Ailia.ailiaGetEnvironment(ref env_ptr, (uint)i, Ailia.AILIA_ENVIRONMENT_VERSION);
99  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
100 
101  if (env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_MPS || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_CUDA || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_VULKAN){
102  env_id = env.id;
103  env_name = Marshal.PtrToStringAnsi(env.name);
104  }
105  }
106  } else {
107  env_name = "cpu";
108  }
109  return env_id;
110  }

◆ GetEnvironmentName()

string ailiaSpeech.AiliaSpeechTranslateModel.GetEnvironmentName ( )
inline

Get the environmen name.

Returns
env_name
123  {
124  return env_name;
125  }

◆ GetErrorDetail()

string ailiaSpeech.AiliaSpeechTranslateModel.GetErrorDetail ( )
inline

Get error detail.

Returns
The error detail string.
68  {
69  return m_error_detail;
70  }

◆ IsError()

bool ailiaSpeech.AiliaSpeechTranslateModel.IsError ( )
inline

Check is error occured.

Returns
If error is occured, it returns true , or false otherwise.
53  {
54  return m_error;
55  }

◆ Open()

bool ailiaSpeech.AiliaSpeechTranslateModel.Open ( string  encoder_path,
string  decoder_path,
string  source_path,
string  target_path,
int  type,
int  env_id,
int  memory_mode 
)
inline

Create a instance.

Open PostProcess file.

Parameters
encoder_pathThe path name to the onnx file
decoder_pathThe path name to the onnx file
source_pathThe path name to the tokenizer model file
target_pathThe path name to the tokenizer model file
post_process_typeAILIA_SPEECH_POST_PROCESS_TYPE_*
env_idRuntime environment (Ailia.AILIA_ENVIRONMENT_ID_AUTO for automatic selection)
memory_modeMemory mode (Ailia.AILIA_MEMORY_REDUCE_CONSTANT | Ailia.AILIA_MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER | Ailia.AILIA_MEMORY_REUSE_INTERSTAGE etc)
Returns
If this function is successful, it returns true , or false otherwise.
157  {
158  AiliaLicense.CheckAndDownloadLicense();
159 
160  if (net != null){
161  Close();
162  }
163 
164  AiliaSpeech.AILIASpeechApiCallback callback = AiliaSpeech.GetCallback();
165 
166  int task = AiliaSpeech.AILIA_SPEECH_TASK_TRANSCRIBE;
167  int flag = AiliaSpeech.AILIA_SPEECH_FLAG_NONE;
168 
169  int status = AiliaSpeech.ailiaSpeechCreate(ref net, env_id, Ailia.AILIA_MULTITHREAD_AUTO, memory_mode, task, flag, callback, AiliaSpeech.AILIA_SPEECH_API_CALLBACK_VERSION);
170  Check(status, "ailiaSpeechCreate");
171  if (status != 0){
172  return false;
173  }
174 
175 
176  status = AiliaSpeech.ailiaSpeechOpenPostProcessFile(net, encoder_path, decoder_path, source_path, target_path, IntPtr.Zero, type);
177  Check(status, "ailiaSpeechOpenPostProcessFile");
178  if (status != 0){
179  return false;
180  }
181 
182  m_error = false;
183  m_error_detail = "";
184 
185  return true;
186  }

◆ Translate()

string ailiaSpeech.AiliaSpeechTranslateModel.Translate ( string  input_text)
inline

Perform speech recognition.

Parameters
input_textInput Text
Returns
If this function is successful, it returns translated string , or null otherwise. @detail Run translate. Blocked API.
257  {
258  AiliaSpeech.AILIASpeechText text = new AiliaSpeech.AILIASpeechText();
259 
260  byte[] input_text_byte = System.Text.Encoding.UTF8.GetBytes(input_text+"\u0000");
261  GCHandle input_text_handle = GCHandle.Alloc(input_text_byte, GCHandleType.Pinned);
262  IntPtr input_text_ptr = input_text_handle.AddrOfPinnedObject();
263 
264  byte[] language_text_byte = System.Text.Encoding.UTF8.GetBytes("None\u0000");
265  GCHandle language_handle = GCHandle.Alloc(language_text_byte, GCHandleType.Pinned);
266  IntPtr language_text_ptr = language_handle.AddrOfPinnedObject();
267 
268  text.text = input_text_ptr;
269  text.time_stamp_begin = 0.0f;
270  text.time_stamp_end = 0.0f;
271  text.confidence = 0.0f;
272  text.person_id = 0;
273  text.language = language_text_ptr;
274 
275  uint idx = 0;
276  int status = AiliaSpeech.ailiaSpeechSetText(net, text, AiliaSpeech.AILIA_SPEECH_TEXT_VERSION, idx);
277  if(status!=0){
278  Check(status, "ailiaSpeechSetText");
279  return null;
280  }
281 
282  status = AiliaSpeech.ailiaSpeechPostProcess(net);
283  if(status!=0){
284  Check(status, "ailiaSpeechPostProcess");
285  return null;
286  }
287 
288  status = AiliaSpeech.ailiaSpeechGetText(net, text, AiliaSpeech.AILIA_SPEECH_TEXT_VERSION, idx);
289  if(status!=0){
290  Check(status, "ailiaSpeechGetText");
291  return null;
292  }
293 
294  input_text_handle.Free();
295  language_handle.Free();
296 
297  return Marshal.PtrToStringAnsi(text.text);
298  }

The documentation for this class was generated from the following file:
ailiaSpeech.AiliaSpeechTranslateModel.Close
virtual void Close()
Destroys instance.
Definition: AiliaSpeechTranslateModel.cs:202
ailiaSpeech.AiliaSpeechTranslateModel.Dispose
virtual void Dispose()
Release resources.
Definition: AiliaSpeechTranslateModel.cs:217