ailia_speech  1.4.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)
 ポストプロセスファイルを開きます。 [詳解]
 
bool OpenDiarization (string segmentation_path, string embedding_path, int type)
 話者分離に適用するAIモデルを開きます。 [詳解]
 
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の実行結果を取得してクリアします。 [詳解]
 
List< AiliaSpeechTextGetStructuredResults ()
 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

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

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

380  {
381  DestroyThread();
382  DestroyInterrupt();
383  if (net != IntPtr.Zero)
384  {
385  AiliaSpeech.ailiaSpeechDestroy(net);
386  net = IntPtr.Zero;
387  }
388  }

◆ Dispose() [1/2]

virtual void ailiaSpeech.AiliaSpeechModel.Dispose ( )
inlinevirtual

リソースを解放します。

398  {
399  Dispose(true);
400  }
virtual void Dispose()
リソースを解放します。
Definition: AiliaSpeechModel.cs:397

◆ Dispose() [2/2]

virtual void ailiaSpeech.AiliaSpeechModel.Dispose ( bool  disposing)
inlineprotectedvirtual
403  {
404  if (disposing){
405  // release managed resource
406  }
407  Close(); // release unmanaged resource
408  }
virtual void Close()
インスタンスを破棄します。
Definition: AiliaSpeechModel.cs:379

◆ GetEnvironmentId()

int ailiaSpeech.AiliaSpeechModel.GetEnvironmentId ( bool  is_gpu)
inline

実行環境を取得します。

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

◆ GetEnvironmentName()

string ailiaSpeech.AiliaSpeechModel.GetEnvironmentName ( )
inline

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

戻り値
env_name
139  {
140  return env_name;
141  }

◆ GetErrorDetail()

string ailiaSpeech.AiliaSpeechModel.GetErrorDetail ( )
inline

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

戻り値
エラーの詳細を示す文字列。
84  {
85  return m_error_detail;
86  }

◆ GetIntermediateText()

string ailiaSpeech.AiliaSpeechModel.GetIntermediateText ( )
inline

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

戻り値
認識結果を返す。
895  {
896  lock (m_intermediate_lock_async){
897  return m_intermediate_text;
898  }
899  }

◆ GetResults()

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

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

戻り値
認識結果を返す。
854  {
855  lock (m_lock_async)
856  {
857  List<string> results = new List<string>(m_results);
858  m_results.Clear();
859  return results;
860  }
861  }

◆ GetStructuredResults()

List<AiliaSpeechText> ailiaSpeech.AiliaSpeechModel.GetStructuredResults ( )
inline

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

戻り値
認識結果を返す。
875  {
876  lock (m_lock_async)
877  {
878  List<AiliaSpeechText> results_struct = new List<AiliaSpeechText>(m_results_struct);
879  m_results_struct.Clear();
880  return results_struct;
881  }
882  }

◆ IntermediateCallback()

static int ailiaSpeech.AiliaSpeechModel.IntermediateCallback ( IntPtr  handle,
IntPtr  text 
)
inlinestatic
552  {
553  lock (m_intermediate_lock_async){
554  try{
555  string decoded_text = Marshal.PtrToStringAnsi(text);
556  m_intermediate_text = decoded_text;
557  }catch(Exception e){
558  }
559  }
560  if (Marshal.ReadInt32(handle) != 0){
561  return -1; // 中断
562  }
563  return 0;
564  }

◆ IsCompleted()

bool ailiaSpeech.AiliaSpeechModel.IsCompleted ( )
inline

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

戻り値
完了した場合はtrue、それ以外の場合はfalseを返す。
836  {
837  lock (m_lock_async)
838  {
839  return m_complete;
840  }
841  }

◆ IsError()

bool ailiaSpeech.AiliaSpeechModel.IsError ( )
inline

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

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

◆ IsProcessing()

bool ailiaSpeech.AiliaSpeechModel.IsProcessing ( )
inline

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

戻り値
実行中はtrue、それ以外の場合はfalseを返す。
800  {
801  lock (m_lock_async)
802  {
803  return m_processing;
804  }
805  }

◆ IsTranscribing()

bool ailiaSpeech.AiliaSpeechModel.IsTranscribing ( )
inline

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

戻り値
実行中はtrue、それ以外の場合はfalseを返す。
818  {
819  lock (m_lock_async)
820  {
821  return m_decoding;
822  }
823  }

◆ 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を返す。
174  {
175  AiliaLicense.CheckAndDownloadLicense();
176 
177  if (net != null){
178  Close();
179  }
180 
181  AiliaSpeech.AILIASpeechApiCallback callback = AiliaSpeech.GetCallback();
182 
183  int status = AiliaSpeech.ailiaSpeechCreate(ref net, env_id, Ailia.AILIA_MULTITHREAD_AUTO, memory_mode, task, flag, callback, AiliaSpeech.AILIA_SPEECH_API_CALLBACK_VERSION);
184  Check(status, "ailiaSpeechCreate");
185  if (status != 0){
186  return false;
187  }
188 
189  status = AiliaSpeech.ailiaSpeechOpenModelFile(net, encoder_path, decoder_path, model_type);
190  Check(status, "ailiaSpeechOpenModelFile");
191  if (status != 0){
192  return false;
193  }
194 
195  if (language != "auto"){
196  status = AiliaSpeech.ailiaSpeechSetLanguage(net, language);
197  Check(status, "ailiaSpeechSetLanguage");
198  if (status != 0){
199  return false;
200  }
201  }
202 
203  status = AiliaSpeech.ailiaSpeechSetSilentThreshold(net, THRESHOLD_VOLUME, SPEECH_SEC, NO_SPEECH_SEC);
204  Check(status, "ailiaSpeechSetSilentThreshold");
205  if (status != 0){
206  return false;
207  }
208 
209  CreateInterrupt();
210 
211  status = AiliaSpeech.ailiaSpeechSetIntermediateCallback(net, IntermediateCallback, m_interrupt_ptr);
212  Check(status, "ailiaSpeechSetIntermediateCallback");
213  if (status != 0){
214  return false;
215  }
216 
217  CreateThread();
218 
219  m_error = false;
220  m_error_detail = "";
221 
222  if ((flag & AiliaSpeech.AILIA_SPEECH_FLAG_LIVE) != 0){
223  live_mode = true;
224  }else{
225  live_mode = false;
226  }
227 
228  return true;
229  }
static int IntermediateCallback(IntPtr handle, IntPtr text)
Definition: AiliaSpeechModel.cs:552

◆ OpenDiarization()

bool ailiaSpeech.AiliaSpeechModel.OpenDiarization ( string  segmentation_path,
string  embedding_path,
int  type 
)
inline

話者分離に適用するAIモデルを開きます。

引数
segmentation_pathonnxファイルのパス名
embedding_pathonnxファイルのパス名
typeAILIA_SPEECH_DIARIZATION_TYPE_PYANNOTE_AUDIO
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
352  {
353  if (net == null){
354  return false;
355  }
356  int status;
357  status = AiliaSpeech.ailiaSpeechOpenDiarizationFile(net, segmentation_path, embedding_path, type);
358  Check(status, "ailiaSpeechOpenDializationFile");
359  if (status != 0){
360  return false;
361  }
362  return true;
363  }

◆ OpenDictionary()

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

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

引数
dictionary_path辞書ファイルヘのパス
dictionary_type辞書種別(AiliaSpeech.AILIA_SPEECH_DICTIONARY_TYPE_*)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
278  {
279  if (net == null){
280  return false;
281  }
282  int status = AiliaSpeech.ailiaSpeechOpenDictionaryFile(net, dictionary_path, dictionary_type);
283  Check(status, "ailiaSpeechOpenDictionaryFile");
284  if (status != 0){
285  return false;
286  }
287  return true;
288  }

◆ 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を返す。
313  {
314  if (net == null){
315  return false;
316  }
317  int status;
318  if (prefix == null){
319  status = AiliaSpeech.ailiaSpeechOpenPostProcessFile(net, encoder_path, decoder_path, source_path, target_path, IntPtr.Zero, type);
320  }else{
321  byte[] text = System.Text.Encoding.UTF8.GetBytes(prefix+"\u0000");
322  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
323  IntPtr prefix_ptr = handle.AddrOfPinnedObject();
324  status = AiliaSpeech.ailiaSpeechOpenPostProcessFile(net, encoder_path, decoder_path, source_path, target_path, prefix_ptr, type);
325  handle.Free();
326  }
327  Check(status, "ailiaSpeechOpenPostProcessFile");
328  if (status != 0){
329  return false;
330  }
331  post_process_mode = true;
332  return true;
333  }

◆ 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を返す。
246  {
247  if (net == null){
248  return false;
249  }
250  int status = AiliaSpeech.ailiaSpeechOpenVadFile(net, vad_path, vad_type);
251  Check(status, "ailiaSpeechOpenVadFile");
252  if (status != 0){
253  return false;
254  }
255  status = AiliaSpeech.ailiaSpeechSetSilentThreshold(net, THRESHOLD_VAD, SPEECH_SEC, NO_SPEECH_SEC);
256  Check(status, "ailiaSpeechSetSilentThreshold");
257  if (status != 0){
258  return false;
259  }
260  return true;
261  }

◆ ResetTranscribeState()

bool ailiaSpeech.AiliaSpeechModel.ResetTranscribeState ( )
inline

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

戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
912  {
913  int status = AiliaSpeech.ailiaSpeechResetTranscribeState(net);
914  lock (m_lock_async)
915  {
916  m_complete = false;
917  }
918  if (status == 0){
919  return true;
920  }
921  return false;
922  }

◆ SetConstraint()

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

制約の設定を行います。

引数
constraintconstraintとなるテキスト(UTF8)
constraint_typeAILIA_SPEECH_CONSTRAINT_*
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
464  {
465  byte[] text = System.Text.Encoding.UTF8.GetBytes(constraint+"\u0000");
466  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
467  IntPtr input = handle.AddrOfPinnedObject();
468  int status = AiliaSpeech.ailiaSpeechSetConstraint(net, input, constraint_type);
469  handle.Free();
470  if (status != 0){
471  return false;
472  }
473  return true;
474  }

◆ SetPrompt()

bool ailiaSpeech.AiliaSpeechModel.SetPrompt ( string  prompt)
inline

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

引数
promptpromptとなるテキスト(UTF8)
戻り値
成功した場合はtrue、失敗した場合はfalseを返す。
432  {
433  byte[] text = System.Text.Encoding.UTF8.GetBytes(prompt+"\u0000");
434  GCHandle handle = GCHandle.Alloc(text, GCHandleType.Pinned);
435  IntPtr input = handle.AddrOfPinnedObject();
436  int status = AiliaSpeech.ailiaSpeechSetPrompt(net, input);
437  handle.Free();
438  if (status != 0){
439  return false;
440  }
441  return true;
442  }

◆ 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で取得可能です。
773  {
774  if (waveData.Length == 0){
775  return false;
776  }
777  lock (m_lock_async)
778  {
779  threadChannels = channels;
780  threadFrequency = frequency;
781  threadWaveQueue.Add(waveData);
782  threadComplete = tail;
783  m_processing = true;
784  m_auto_event.Set();
785  }
786  return true;
787  }

このクラス詳解は次のファイルから抽出されました: