ailia_speech  1.3.0.0
公開メンバ関数 | 静的公開メンバ関数 | 限定公開メンバ関数 | 全メンバ一覧
ailiaSpeech.AiliaSpeechModel クラス
ailiaSpeech.AiliaSpeechModel の継承関係図
Inheritance graph
[凡例]
ailiaSpeech.AiliaSpeechModel 連携図
Collaboration graph
[凡例]

公開メンバ関数

bool IsError ()
 エラーが発生したか確認します。 [詳解]
 
string GetErrorDetail ()
 エラーの詳細を取得します。 [詳解]
 
int GetEnvironmentId (bool is_gpu)
 実行環境を取得します。 [詳解]
 
string GetEnvironmentName ()
 実行環境の名称を取得します。 [詳解]
 
bool Open (string encoder_path, string decoder_path, int env_id, int memory_mode, int model_type, int task, int flag, string language)
 インスタンスを作成します。 [詳解]
 
bool OpenVad (string vad_path, int vad_type)
 VADファイルを開きます。 [詳解]
 
bool OpenDictionary (string dictionary_path, int dictionary_type)
 辞書ファイルを開きます。 [詳解]
 
bool OpenPostProcess (string encoder_path, string decoder_path, string source_path, string target_path, string prefix, int type)
 ポストプロセスファイルを開きます。 [詳解]
 
virtual void Close ()
 インスタンスを破棄します。 [詳解]
 
virtual void Dispose ()
 リソースを解放します。 [詳解]
 
bool SetPrompt (string prompt)
 プロンプトの設定を行います。 [詳解]
 
bool SetConstraint (string constraint, int constraint_type)
 制約の設定を行います。 [詳解]
 
bool Transcribe (float[] waveData, uint frequency, uint channels, bool tail)
 音声認識を実行します。 [詳解]
 
bool IsProcessing ()
 サブスレッドが実行中かどうか取得します。 [詳解]
 
bool IsTranscribing ()
 Speech2Textを実行中かどうか取得します。 [詳解]
 
bool IsCompleted ()
 全ての音声の処理が完了したかどうか取得します。 [詳解]
 
List< string > GetResults ()
 Speech2Textの実行結果を取得してクリアします。 [詳解]
 
string GetIntermediateText ()
 Speech2Textの途中のテキストを取得します。 [詳解]
 
bool ResetTranscribeState ()
 Speech2Textのステートを初期化します。 [詳解]
 

静的公開メンバ関数

static int IntermediateCallback (IntPtr handle, IntPtr text)
 

限定公開メンバ関数

virtual void Dispose (bool disposing)
 

関数詳解

◆ Close()

virtual void ailiaSpeech.AiliaSpeechModel.Close ( )
inlinevirtual

インスタンスを破棄します。

インスタンスを破棄し、初期化します。

341  {
342  DestroyThread();
343  DestroyInterrupt();
344  if (net != IntPtr.Zero){
345  AiliaSpeech.ailiaSpeechDestroy(net);
346  net = IntPtr.Zero;
347  }
348  }

◆ Dispose() [1/2]

virtual void ailiaSpeech.AiliaSpeechModel.Dispose ( )
inlinevirtual

リソースを解放します。

358  {
359  Dispose(true);
360  }

◆ Dispose() [2/2]

virtual void ailiaSpeech.AiliaSpeechModel.Dispose ( bool  disposing)
inlineprotectedvirtual
363  {
364  if (disposing){
365  // release managed resource
366  }
367  Close(); // release unmanaged resource
368  }

◆ GetEnvironmentId()

int ailiaSpeech.AiliaSpeechModel.GetEnvironmentId ( bool  is_gpu)
inline

実行環境を取得します。

引数
is_gpuGPUを使用するかどうか
戻り値
env_id
98  {
99  int env_id = Ailia.AILIA_ENVIRONMENT_ID_AUTO;
100  if (is_gpu) { // GPU
101  int count = 0;
102  Ailia.ailiaGetEnvironmentCount(ref count);
103  for (int i = 0; i < count; i++){
104  IntPtr env_ptr = IntPtr.Zero;
105  Ailia.ailiaGetEnvironment(ref env_ptr, (uint)i, Ailia.AILIA_ENVIRONMENT_VERSION);
106  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
107 
108  if (env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_MPS || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_CUDA || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_VULKAN){
109  env_id = env.id;
110  env_name = Marshal.PtrToStringAnsi(env.name);
111  }
112  }
113  } else {
114  env_name = "cpu";
115  }
116  return env_id;
117  }

◆ GetEnvironmentName()

string ailiaSpeech.AiliaSpeechModel.GetEnvironmentName ( )
inline

実行環境の名称を取得します。

戻り値
env_name
130  {
131  return env_name;
132  }

◆ GetErrorDetail()

string ailiaSpeech.AiliaSpeechModel.GetErrorDetail ( )
inline

エラーの詳細を取得します。

戻り値
エラーの詳細を示す文字列。
75  {
76  return m_error_detail;
77  }

◆ GetIntermediateText()

string ailiaSpeech.AiliaSpeechModel.GetIntermediateText ( )
inline

Speech2Textの途中のテキストを取得します。

戻り値
認識結果を返す。
818  {
819  lock (m_intermediate_lock_async){
820  return m_intermediate_text;
821  }
822  }

◆ GetResults()

List<string> ailiaSpeech.AiliaSpeechModel.GetResults ( )
inline

Speech2Textの実行結果を取得してクリアします。

戻り値
認識結果を返す。
798  {
799  lock (m_lock_async)
800  {
801  List<string> results = new List<string>(m_results);
802  m_results.Clear();
803  return results;
804  }
805  }

◆ IntermediateCallback()

static int ailiaSpeech.AiliaSpeechModel.IntermediateCallback ( IntPtr  handle,
IntPtr  text 
)
inlinestatic
497  {
498  lock (m_intermediate_lock_async){
499  try{
500  string decoded_text = Marshal.PtrToStringAnsi(text);
501  m_intermediate_text = decoded_text;
502  }catch(Exception e){
503  }
504  }
505  if (Marshal.ReadInt32(handle) != 0){
506  return -1; // 中断
507  }
508  return 0;
509  }

◆ IsCompleted()

bool ailiaSpeech.AiliaSpeechModel.IsCompleted ( )
inline

全ての音声の処理が完了したかどうか取得します。

戻り値
完了した場合はtrue、それ以外の場合はfalseを返す。
780  {
781  lock (m_lock_async)
782  {
783  return m_complete;
784  }
785  }

◆ IsError()

bool ailiaSpeech.AiliaSpeechModel.IsError ( )
inline

エラーが発生したか確認します。

戻り値
エラーが発生した場合はtrue、発生していない場合はfalseを返す。
60  {
61  return m_error;
62  }

◆ IsProcessing()

bool ailiaSpeech.AiliaSpeechModel.IsProcessing ( )
inline

サブスレッドが実行中かどうか取得します。

戻り値
実行中はtrue、それ以外の場合はfalseを返す。
744  {
745  lock (m_lock_async)
746  {
747  return m_processing;
748  }
749  }

◆ IsTranscribing()

bool ailiaSpeech.AiliaSpeechModel.IsTranscribing ( )
inline

Speech2Textを実行中かどうか取得します。

戻り値
実行中はtrue、それ以外の場合はfalseを返す。
762  {
763  lock (m_lock_async)
764  {
765  return m_decoding;
766  }
767  }

◆ Open()

bool ailiaSpeech.AiliaSpeechModel.Open ( string  encoder_path,
string  decoder_path,
int  env_id,
int  memory_mode,
int  model_type,
int  task,
int  flag,
string  language 
)
inline

インスタンスを作成します。

引数
encoder_pathエンコーダのONNXファイルヘのパス
decoder_pathデコーダのONNXファイルヘのパス
env_id実行環境 (Ailia.AILIA_ENVIRONMENT_ID_AUTOで自動選択)
memory_modeメモリモード (Ailia.AILIA_MEMORY_REDUCE_CONSTANT | Ailia.AILIA_MEMORY_REDUCE_CONSTANT_WITH_INPUT_INITIALIZER | Ailia.AILIA_MEMORY_REUSE_INTERSTAGE など)
model_type モデル種別(AiliaSpeech.AILIA_SPEECH_MODEL_TYPE_*)
taskタスク種別(AiliaSpeech.AILIA_SPEECH_TASK_*)
flagフラグの論理和(AiliaSpeech.AILIA_SPEECH_FLAG_*)
language言語(jaやenなど、autoの場合は自動選択)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
165  {
166  AiliaLicense.CheckAndDownloadLicense();
167 
168  if (net != null){
169  Close();
170  }
171 
172  AiliaSpeech.AILIASpeechApiCallback callback = AiliaSpeech.GetCallback();
173 
174  int status = AiliaSpeech.ailiaSpeechCreate(ref net, env_id, Ailia.AILIA_MULTITHREAD_AUTO, memory_mode, task, flag, callback, AiliaSpeech.AILIA_SPEECH_API_CALLBACK_VERSION);
175  Check(status, "ailiaSpeechCreate");
176  if (status != 0){
177  return false;
178  }
179 
180  status = AiliaSpeech.ailiaSpeechOpenModelFile(net, encoder_path, decoder_path, model_type);
181  Check(status, "ailiaSpeechOpenModelFile");
182  if (status != 0){
183  return false;
184  }
185 
186  if (language != "auto"){
187  status = AiliaSpeech.ailiaSpeechSetLanguage(net, language);
188  Check(status, "ailiaSpeechSetLanguage");
189  if (status != 0){
190  return false;
191  }
192  }
193 
194  status = AiliaSpeech.ailiaSpeechSetSilentThreshold(net, THRESHOLD_VOLUME, SPEECH_SEC, NO_SPEECH_SEC);
195  Check(status, "ailiaSpeechSetSilentThreshold");
196  if (status != 0){
197  return false;
198  }
199 
200  CreateInterrupt();
201 
202  status = AiliaSpeech.ailiaSpeechSetIntermediateCallback(net, IntermediateCallback, m_interrupt_ptr);
203  Check(status, "ailiaSpeechSetIntermediateCallback");
204  if (status != 0){
205  return false;
206  }
207 
208  CreateThread();
209 
210  m_error = false;
211  m_error_detail = "";
212 
213  if ((flag & AiliaSpeech.AILIA_SPEECH_FLAG_LIVE) != 0){
214  live_mode = true;
215  }else{
216  live_mode = false;
217  }
218 
219  return true;
220  }

◆ OpenDictionary()

bool ailiaSpeech.AiliaSpeechModel.OpenDictionary ( string  dictionary_path,
int  dictionary_type 
)
inline

辞書ファイルを開きます。

引数
dictionary_path辞書ファイルヘのパス
dictionary_type辞書種別(AiliaSpeech.AILIA_SPEECH_DICTIONARY_TYPE_*)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
269  {
270  if (net == null){
271  return false;
272  }
273  int status = AiliaSpeech.ailiaSpeechOpenDictionaryFile(net, dictionary_path, dictionary_type);
274  Check(status, "ailiaSpeechOpenDictionaryFile");
275  if (status != 0){
276  return false;
277  }
278  return true;
279  }

◆ OpenPostProcess()

bool ailiaSpeech.AiliaSpeechModel.OpenPostProcess ( string  encoder_path,
string  decoder_path,
string  source_path,
string  target_path,
string  prefix,
int  type 
)
inline

ポストプロセスファイルを開きます。

引数
encoder_pathonnxファイルのパス名
decoder_pathonnxファイルのパス名
source_pathTokenizerのmodelファイルのパス名
target_pathTokenizerのmodelファイルのパス名
prefixT5のprefix (UTF8)、FuguMTの場合はnull
post_process_typeAILIA_SPEECH_POST_PROCESS_TYPE_*
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
304  {
305  if (net == null){
306  return false;
307  }
308  int status;
309  if (prefix == null){
310  status = AiliaSpeech.ailiaSpeechOpenPostProcessFile(net, encoder_path, decoder_path, source_path, target_path, IntPtr.Zero, type);
311  }else{
312  byte[] text = System.Text.Encoding.UTF8.GetBytes(prefix+"\u0000");
313  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
314  IntPtr prefix_ptr = handle.AddrOfPinnedObject();
315  status = AiliaSpeech.ailiaSpeechOpenPostProcessFile(net, encoder_path, decoder_path, source_path, target_path, prefix_ptr, type);
316  handle.Free();
317  }
318  Check(status, "ailiaSpeechOpenPostProcessFile");
319  if (status != 0){
320  return false;
321  }
322  post_process_mode = true;
323  return true;
324  }

◆ OpenVad()

bool ailiaSpeech.AiliaSpeechModel.OpenVad ( string  vad_path,
int  vad_type 
)
inline

VADファイルを開きます。

引数
vad_pathVADのONNXファイルヘのパス
vad_typeVAD種別(AiliaSpeech.AILIA_SPEECH_VAD_TYPE_*)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
237  {
238  if (net == null){
239  return false;
240  }
241  int status = AiliaSpeech.ailiaSpeechOpenVadFile(net, vad_path, vad_type);
242  Check(status, "ailiaSpeechOpenVadFile");
243  if (status != 0){
244  return false;
245  }
246  status = AiliaSpeech.ailiaSpeechSetSilentThreshold(net, THRESHOLD_VAD, SPEECH_SEC, NO_SPEECH_SEC);
247  Check(status, "ailiaSpeechSetSilentThreshold");
248  if (status != 0){
249  return false;
250  }
251  return true;
252  }

◆ ResetTranscribeState()

bool ailiaSpeech.AiliaSpeechModel.ResetTranscribeState ( )
inline

Speech2Textのステートを初期化します。

戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
835  {
836  int status = AiliaSpeech.ailiaSpeechResetTranscribeState(net);
837  lock (m_lock_async)
838  {
839  m_complete = false;
840  }
841  if (status == 0){
842  return true;
843  }
844  return false;
845  }

◆ SetConstraint()

bool ailiaSpeech.AiliaSpeechModel.SetConstraint ( string  constraint,
int  constraint_type 
)
inline

制約の設定を行います。

引数
constraintconstraintとなるテキスト(UTF8)
constraint_typeAILIA_SPEECH_CONSTRAINT_*
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
424  {
425  byte[] text = System.Text.Encoding.UTF8.GetBytes(constraint+"\u0000");
426  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
427  IntPtr input = handle.AddrOfPinnedObject();
428  int status = AiliaSpeech.ailiaSpeechSetConstraint(net, input, constraint_type);
429  handle.Free();
430  if (status != 0){
431  return false;
432  }
433  return true;
434  }

◆ SetPrompt()

bool ailiaSpeech.AiliaSpeechModel.SetPrompt ( string  prompt)
inline

プロンプトの設定を行います。

引数
promptpromptとなるテキスト(UTF8)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
392  {
393  byte[] text = System.Text.Encoding.UTF8.GetBytes(prompt+"\u0000");
394  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
395  IntPtr input = handle.AddrOfPinnedObject();
396  int status = AiliaSpeech.ailiaSpeechSetPrompt(net, input);
397  handle.Free();
398  if (status != 0){
399  return false;
400  }
401  return true;
402  }

◆ Transcribe()

bool ailiaSpeech.AiliaSpeechModel.Transcribe ( float[]  waveData,
uint  frequency,
uint  channels,
bool  tail 
)
inline

音声認識を実行します。

引数
waveQueue入力PCM
frequency入力PCMの周波数
channels入力PCMのチャンネル数
tail 入力が最後かどうか
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。 @detail 音声認識を実行します。 ノンブロッキングAPIです。 実行が完了するとIsTranscribed APIがTrueを返します。 実行結果はGetResults APIで取得可能です。 実行の途中結果はGetIntermediateText APIで取得可能です。
717  {
718  if (waveData.Length == 0){
719  return false;
720  }
721  lock (m_lock_async)
722  {
723  threadChannels = channels;
724  threadFrequency = frequency;
725  threadWaveQueue.Add(waveData);
726  threadComplete = tail;
727  m_processing = true;
728  m_auto_event.Set();
729  }
730  return true;
731  }

このクラス詳解は次のファイルから抽出されました:
ailiaSpeech.AiliaSpeechModel.Close
virtual void Close()
インスタンスを破棄します。
Definition: AiliaSpeechModel.cs:340
ailiaSpeech.AiliaSpeechModel.IntermediateCallback
static int IntermediateCallback(IntPtr handle, IntPtr text)
Definition: AiliaSpeechModel.cs:497
ailiaSpeech.AiliaSpeechModel.Dispose
virtual void Dispose()
リソースを解放します。
Definition: AiliaSpeechModel.cs:357