Skip to content

Instantly share code, notes, and snippets.

@ksasao
Last active October 31, 2020 05:33
Show Gist options
  • Select an option

  • Save ksasao/14b29404bce507192a64734fc2f6d712 to your computer and use it in GitHub Desktop.

Select an option

Save ksasao/14b29404bce507192a64734fc2f6d712 to your computer and use it in GitHub Desktop.
CeVIO CS6/CS7 の DLL を動的に呼び出すサンプル。32bitビルドでも64bitの CeVIO CS7 を呼び出せます。
// CeVIO の DLL を動的に呼び出すサンプル
// CeVIO 試用版は下記
// https://sites.google.com/site/ceviouserguides/archive/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace SpeechTestDynamic
{
class Program
{
static void Main(string[] args)
{
try
{
Assembly assembly = null;
// CeVIO CS6 / CS7 を探す
string cevioCS7Path = Environment.ExpandEnvironmentVariables("%ProgramW6432%")
+ @"\CeVIO\CeVIO Creative Studio (64bit)\CeVIO.Talk.RemoteService.dll";
string cevioCS6Path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
+ @"\CeVIO\CeVIO Creative Studio\CeVIO.Talk.RemoteService.dll";
if (File.Exists(cevioCS7Path))
{
assembly = Assembly.LoadFrom(cevioCS7Path);
}
else if (File.Exists(cevioCS6Path))
{
assembly = Assembly.LoadFrom(cevioCS6Path);
}
if(assembly == null)
{
throw new FileNotFoundException();
}
Type serviceControl = assembly.GetType("CeVIO.Talk.RemoteService.ServiceControl");
Type talkerAgent = assembly.GetType("CeVIO.Talk.RemoteService.TalkerAgent");
//// 【CeVIO Creative Studio】起動
//ServiceControl.StartHost(false);
MethodInfo startHost = serviceControl.GetMethod("StartHost");
startHost.Invoke(null, new object[] { false });
// インストールされているキャストの名前を列挙
PropertyInfo property = talkerAgent.GetProperty("AvailableCasts");
string[] names = (string[])property.GetValue(null, new object[] { });
foreach (var n in names)
{
Console.WriteLine(n);
}
dynamic talker = Activator.CreateInstance(assembly.GetType("CeVIO.Talk.RemoteService.Talker"), new object[] { names[0] });
Console.WriteLine(talker.Speed); // 速度(default: 50)
Console.WriteLine(talker.Tone); // 高さ(default: 50)
Console.WriteLine(talker.ToneScale); // 抑揚(default: 50)
Console.WriteLine(talker.Volume); // 音量(default: 50)
dynamic state = talker.Speak("こんにちは。");
state.Wait(); // 発話終了待ち
//// 【CeVIO Creative Studio】終了
//ServiceControl.CloseHost();
MethodInfo closeHost = serviceControl.GetMethod("CloseHost");
var hostCloseMode = assembly.GetType("CeVIO.Talk.RemoteService.HostCloseMode");
var mode = Enum.Parse(hostCloseMode, "Default"); // Default, Interrupt, NotCancelable
closeHost.Invoke(null, new object[] { mode });
}catch(FileNotFoundException)
{
Console.WriteLine("CeVIO が見つかりませんでした");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment