Skip to content

Instantly share code, notes, and snippets.

@Qofar
Last active September 21, 2017 00:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qofar/11364454 to your computer and use it in GitHub Desktop.
Save Qofar/11364454 to your computer and use it in GitHub Desktop.
AdvancedCombatTrackerのText-to-Speechを棒読みちゃんにするPlugin
%windir%\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library /r:"Advanced Combat Tracker.exe" TTS2BouyomiChan.cs
using Advanced_Combat_Tracker;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
[assembly: AssemblyTitle("TTS2BouyomiChan")]
[assembly: AssemblyVersion("1.1.0.0")]
// =======================================================================
// 64bit対応は以下をコピペしました
// thx anoyetta
// https://github.com/anoyetta/ACT.TTSYukkuri
// =======================================================================
namespace ACT_Plugin
{
public class TTS2BouyomiChan : IActPluginV1
{
Label lblStatus;
private FormActMain.PlayTtsDelegate originalTTSDelegate;
public void newTTS(string sMessage)
{
byte bCode = 0;
Int16 iVoice = 1;
Int16 iVolume = -1;
Int16 iSpeed = -1;
Int16 iTone = -1;
Int16 iCommand = 0x0001;
byte[] bMessage = Encoding.UTF8.GetBytes(sMessage);
Int32 iLength = bMessage.Length;
//棒読みちゃんのTCPサーバへ接続
string sHost = "127.0.0.1"; //棒読みちゃんが動いているホスト
int iPort = 50001; //棒読みちゃんのTCPサーバのポート番号(デフォルト値)
TcpClient tc = null;
try
{
tc = new TcpClient(sHost, iPort);
}
catch (Exception ex)
{
ActGlobals.oFormActMain.WriteExceptionLog(ex, "TTS2BouyomiChan Error");
}
if (tc != null)
{
//メッセージ送信
using (NetworkStream ns = tc.GetStream())
{
using (BinaryWriter bw = new BinaryWriter(ns))
{
bw.Write(iCommand); //コマンド( 0:メッセージ読み上げ)
bw.Write(iSpeed); //速度 (-1:棒読みちゃん画面上の設定)
bw.Write(iTone); //音程 (-1:棒読みちゃん画面上の設定)
bw.Write(iVolume); //音量 (-1:棒読みちゃん画面上の設定)
bw.Write(iVoice); //声質 ( 0:棒読みちゃん画面上の設定、1:女性1、2:女性2、3:男性1、4:男性2、5:中性、6:ロボット、7:機械1、8:機械2、10001~:SAPI5)
bw.Write(bCode); //文字列のbyte配列の文字コード(0:UTF-8, 1:Unicode, 2:Shift-JIS)
bw.Write(iLength); //文字列のbyte配列の長さ
bw.Write(bMessage); //文字列のbyte配列
}
}
//切断
tc.Close();
}
}
#region IActPluginV1 Members
public void InitPlugin(TabPage pluginScreenSpace, Label pluginStatusText)
{
lblStatus = pluginStatusText; // Hand the status label's reference to our local var
// TTSメソッドを置き換える
this.originalTTSDelegate = (FormActMain.PlayTtsDelegate)ActGlobals.oFormActMain.PlayTtsMethod.Clone();
ActGlobals.oFormActMain.PlayTtsMethod = new FormActMain.PlayTtsDelegate(this.newTTS);
lblStatus.Text = "Plugin Started";
}
public void DeInitPlugin()
{
if (this.originalTTSDelegate != null)
{
ActGlobals.oFormActMain.PlayTtsMethod = this.originalTTSDelegate;
}
lblStatus.Text = "Plugin Exited";
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment