Created
February 22, 2022 13:17
-
-
Save ksasao/10e298a1adcd772d59eec1b43e3f701b to your computer and use it in GitHub Desktop.
A.I.VOICE Editor 外部連携API を DLL参照せずに動的に読み込んで利用するサンプルコードです。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| using System.Reflection; | |
| using System.IO; | |
| namespace HelloAIVOICE | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| string path = | |
| Environment.ExpandEnvironmentVariables("%ProgramW6432%") | |
| +@"\AI\AIVoice\AIVoiceEditor\AI.Talk.Editor.Api.dll"; | |
| if (File.Exists(path)) | |
| { | |
| Assembly assembly = Assembly.LoadFrom(path); | |
| Type type = assembly.GetType("AI.Talk.Editor.Api.TtsControl"); | |
| dynamic ttsControl = Activator.CreateInstance(type, new object[] { }); | |
| // A.I.VOICE Editor に接続 | |
| var names = ttsControl.GetAvailableHostNames(); | |
| ttsControl.Initialize(names[0]); // names[0] = "A.I.VOICE Editor" | |
| ttsControl.Connect(); | |
| // プリセット一覧を取得 | |
| string[] list = ttsControl.VoicePresetNames; | |
| for(int i=0; i<list.Length; i++) | |
| { | |
| Console.WriteLine($"{i}: {list[i]}"); | |
| } | |
| // 指定した声で再生 | |
| ttsControl.CurrentVoicePresetName = list[0]; // 0番目のプリセットを選択 | |
| ttsControl.Text = "こんにちは"; | |
| ttsControl.Play(); | |
| Console.WriteLine("何かキーを押してください。"); | |
| ttsControl.Disconnect(); | |
| } | |
| else | |
| { | |
| Console.WriteLine("最新のA.I.VOICE Editor をインストールしてください"); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment