├── .gitattributes ├── .gitignore ├── License.txt ├── README.md ├── SApiClient ├── Assets │ ├── ChatRobot.meta │ ├── ChatRobot │ │ ├── Cleverbot.meta │ │ ├── Cleverbot │ │ │ ├── CleverBot.cs │ │ │ ├── CleverBot.cs.meta │ │ │ ├── CleverBot.unity │ │ │ ├── CleverBot.unity.meta │ │ │ ├── CleverBotManager.cs │ │ │ └── CleverBotManager.cs.meta │ │ ├── TuLing.meta │ │ ├── TuLing │ │ │ ├── TuLing.unity │ │ │ ├── TuLing.unity.meta │ │ │ ├── TuLingChatRobot.cs │ │ │ ├── TuLingChatRobot.cs.meta │ │ │ ├── TuLingChatRobotManager.cs │ │ │ └── TuLingChatRobotManager.cs.meta │ │ ├── WebChatBot.cs │ │ ├── WebChatBot.cs.meta │ │ ├── WebChatBotManager.cs │ │ └── WebChatBotManager.cs.meta │ ├── Core.meta │ ├── Core │ │ ├── ByteInArg.cs │ │ ├── ByteInArg.cs.meta │ │ ├── SocketExtra.cs │ │ └── SocketExtra.cs.meta │ ├── Sapi.meta │ ├── Sapi │ │ ├── Speecher.cs │ │ ├── Speecher.cs.meta │ │ ├── SpeecherManager.cs │ │ └── SpeecherManager.cs.meta │ ├── Scene.meta │ └── Scene │ │ ├── test.unity │ │ └── test.unity.meta ├── ProjectSettings │ ├── AudioManager.asset │ ├── ClusterInputManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ ├── TimeManager.asset │ ├── UnityAdsSettings.asset │ └── UnityConnectSettings.asset ├── SApiClient.CSharp.csproj ├── SApiClient.sln ├── SapiClient.v12.suo ├── Speech.exe └── Speech.exe.config ├── Speech ├── EmCmd.cs ├── NetServer.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Settings.Designer.cs │ └── Settings.settings ├── Recognizer.cs ├── Speech.csproj ├── Speech.csproj.user ├── Speech.exe ├── Speech.exe.config ├── Speech.sln ├── Speech.v12.suo ├── Speecher.cs └── app.config └── _config.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | Unity3d使用SAPI语音在Windows上进行文本发音.docx 49 | /SApiClient/Library 50 | /SApiClient/Temp 51 | /SApiClient/.vs 52 | /Speech/bin 53 | /Speech/obj 54 | /Speech/.vs 55 | /SApiClient/Output 56 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Copyright © 2016-2017 CodeGize 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnitySapi 2 | UnitySapi是一个Unity可以调用Sapi的工具。 3 | 4 | 语音开发主要是两种技术:语音识别和语音合成 5 | Sapi是微软提供的语音引擎,win7之后系统自带,效率和质量都很好。 6 | 使用Sapi需要使用System.Speech.dll文件,因此在unity中需要拷贝这个文件到Assets目录下,但是会出现无法初始化的错误。 7 | 因此,创建一个专门调用Sapi的控制台程序。然后在Unity中和这个控制台程序进行数据交互,以达到在Unity调用Sapi的目的。 8 | 9 | #程序工作流程 10 | Unity使用Socket发送语音文本给控制台程序Speech,然后Speech调用Sapi进行语音合成或者语音识别。 11 | 12 | 备注:win10 64位操作系统测试通过,其他系统未测试 13 | 14 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5f1624b8b2b57f469f0b8b26ba6af91 3 | folderAsset: yes 4 | timeCreated: 1492989530 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0f6e5c67c08f2841a0ae9e656db1b00 3 | folderAsset: yes 4 | timeCreated: 1496843213 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Assets.ChatRobot.Cleverbot 4 | { 5 | public class CleverBot : WebChatBot 6 | { 7 | public override string Url 8 | { 9 | get { return "https://www.cleverbot.com/getreply"; } 10 | } 11 | 12 | public override string Key 13 | { 14 | get { return "CC2me_S7B1Qh1diYLI9CJBZxXgQ"; } 15 | } 16 | 17 | public string Cs { get; set; } 18 | 19 | protected override WWW ProcessWWW(string req) 20 | { 21 | var url = string.Format("{0}?key={1}&input={2}&cs={3}", Url, Key, req, Cs); 22 | var www = new WWW(url); 23 | return www; 24 | } 25 | } 26 | 27 | internal class CleverBotResponseBase : IWebChatBotResponseBase 28 | { 29 | public string cs; 30 | public int interaction_count; 31 | public string input; 32 | public string output; 33 | public string conversation_id; 34 | 35 | public string Text 36 | { 37 | get { return output; } 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01fad431417c95d4096c027690093790 3 | timeCreated: 1496844102 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBot.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/Assets/ChatRobot/Cleverbot/CleverBot.unity -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBot.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 010a2925e10a00b45836b6596fd21051 3 | timeCreated: 1496844127 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBotManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Assets.ChatRobot.Cleverbot 4 | { 5 | public class CleverBotManager : WebChatBotManager 6 | { 7 | protected override void OnGetResponse(string res) 8 | { 9 | var response = JsonUtility.FromJson(res); 10 | Speecher.Speech(response.Text); 11 | ChatBot.Cs = response.cs; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/Cleverbot/CleverBotManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee176403c2d7db745ac3bd62f047a650 3 | timeCreated: 1496845146 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6aefd1e46020da54cac47b69ad7223e7 3 | folderAsset: yes 4 | timeCreated: 1493028536 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLing.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/Assets/ChatRobot/TuLing/TuLing.unity -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLing.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06e51df93e61d4d40953682c0ee91e9a 3 | timeCreated: 1493028546 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLingChatRobot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace Assets.ChatRobot.TuLing 5 | { 6 | public class TuLingChatRobot : WebChatBot 7 | { 8 | public override string Url 9 | { 10 | get { return "http://www.tuling123.com/openapi/api"; } 11 | } 12 | 13 | public override string Key 14 | { 15 | get { return "7c4071624723cdd32213619dd69fd163"; } 16 | } 17 | 18 | protected override WWW ProcessWWW(string req) 19 | { 20 | var pf = new WWWForm(); 21 | pf.AddField("key", Key); 22 | pf.AddField("info", req); 23 | var www = new WWW(Url, pf); 24 | return www; 25 | } 26 | } 27 | 28 | 29 | 30 | public class TuLingResponseBase : IWebChatBotResponseBase 31 | { 32 | public int code; 33 | public string text; 34 | 35 | public string Text { get { return text; } } 36 | } 37 | 38 | public class TuLingUrlResponse : TuLingResponseBase 39 | { 40 | public string url; 41 | } 42 | 43 | public class TuLingNewsResponse : TuLingUrlResponse 44 | { 45 | public List list; 46 | 47 | public class NewsData 48 | { 49 | public string article; 50 | public string source; 51 | public string icon; 52 | public string detailurl; 53 | } 54 | } 55 | 56 | public class TuLingCookBookResponse : TuLingResponseBase 57 | { 58 | 59 | public List list; 60 | 61 | public class CookBookData 62 | { 63 | public string name; 64 | public string info; 65 | public string icon; 66 | public string detailurl; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLingChatRobot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3bdd3bf1cb967a4e871d89f19fefa7e 3 | timeCreated: 1492990794 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLingChatRobotManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Assets.ChatRobot.TuLing 4 | { 5 | public class TuLingChatRobotManager : WebChatBotManager 6 | { 7 | protected override void OnGetResponse(string res) 8 | { 9 | var response = JsonUtility.FromJson(res); 10 | Speecher.Speech(response.text); 11 | } 12 | } 13 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/TuLing/TuLingChatRobotManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7133d507870cdab40bd120c6bd5f73b1 3 | timeCreated: 1493029135 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/WebChatBot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using UnityEngine; 3 | 4 | namespace Assets.ChatRobot 5 | { 6 | public delegate void WebChatResponse(string res); 7 | 8 | public abstract class WebChatBot : MonoBehaviour 9 | { 10 | public abstract string Url { get; } 11 | public abstract string Key { get; } 12 | 13 | public void Require(string req) 14 | { 15 | StartCoroutine(_Require(req)); 16 | } 17 | 18 | public WebChatResponse OnGetResponse; 19 | 20 | private IEnumerator _Require(string req) 21 | { 22 | var www = ProcessWWW(req); 23 | yield return www; 24 | if (www.error != null) 25 | { 26 | Debug.Log(www.error); 27 | yield break; 28 | } 29 | var text = www.text; 30 | Debug.Log(text); 31 | if (OnGetResponse != null) 32 | OnGetResponse.Invoke(text); 33 | } 34 | 35 | protected abstract WWW ProcessWWW(string req); 36 | } 37 | 38 | public interface IWebChatBotResponseBase 39 | { 40 | string Text { get; } 41 | } 42 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/WebChatBot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e76ef8cb12510d340ad9b14cf56cfbfc 3 | timeCreated: 1496844102 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/WebChatBotManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Assets.ChatRobot 4 | { 5 | public abstract class WebChatBotManager : SpeecherManager where T : WebChatBot 6 | { 7 | private string m_req = ""; 8 | protected T ChatBot; 9 | 10 | protected override void Awake() 11 | { 12 | base.Awake(); 13 | ChatBot = GetComponent(); 14 | Speecher.OnGetRecognize = ChatBot.Require; 15 | ChatBot.OnGetResponse = OnGetResponse; 16 | } 17 | 18 | protected abstract void OnGetResponse(string res); 19 | 20 | public override void OnGUI() 21 | { 22 | base.OnGUI(); 23 | 24 | m_req = GUILayout.TextField(m_req); 25 | if (GUILayout.Button("ChatBot")) 26 | { 27 | if (!string.IsNullOrEmpty(m_req)) 28 | { 29 | ChatBot.Require(m_req); 30 | } 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /SApiClient/Assets/ChatRobot/WebChatBotManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d967416208bbacd47803919e25d45909 3 | timeCreated: 1496845146 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7fe7126bbc872c47b43e030e07cea5f 3 | folderAsset: yes 4 | timeCreated: 1490855497 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/Core/ByteInArg.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Stardust 4 | { 5 | public class ByteInArg 6 | { 7 | private readonly MemoryStream m_stream = new MemoryStream(); 8 | private readonly BinaryWriter m_writer; 9 | 10 | public ByteInArg() 11 | { 12 | m_writer = new BinaryWriter(m_stream); 13 | } 14 | 15 | public void Write(bool value) 16 | { 17 | m_writer.Write(value); 18 | } 19 | 20 | public void Write(byte value) 21 | { 22 | m_writer.Write(value); 23 | } 24 | 25 | public void Write(char ch) 26 | { 27 | m_writer.Write(ch); 28 | } 29 | 30 | public void Write(int value) 31 | { 32 | m_writer.Write(value); 33 | } 34 | 35 | public void Write(string value) 36 | { 37 | m_writer.Write(value); 38 | } 39 | 40 | public byte[] GetBuffer() 41 | { 42 | return m_stream.GetBuffer(); 43 | } 44 | } 45 | 46 | public class ByteOutArg 47 | { 48 | private readonly BinaryReader m_reader; 49 | 50 | public ByteOutArg(byte[] buffer) 51 | { 52 | var stream = new MemoryStream(buffer); 53 | m_reader = new BinaryReader(stream); 54 | } 55 | 56 | public bool ReadBoolean() 57 | { 58 | return m_reader.ReadBoolean(); 59 | } 60 | 61 | public byte ReadByte() 62 | { 63 | return m_reader.ReadByte(); 64 | } 65 | 66 | public int ReadInt32() 67 | { 68 | return m_reader.ReadInt32(); 69 | } 70 | 71 | public string ReadString() 72 | { 73 | return m_reader.ReadString(); 74 | } 75 | } 76 | } -------------------------------------------------------------------------------- /SApiClient/Assets/Core/ByteInArg.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6275e6873793c6c4eba4063485387a40 3 | timeCreated: 1490846717 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/Core/SocketExtra.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | 6 | namespace Stardust 7 | { 8 | public interface INetComponent 9 | { 10 | bool NetReciveMsg(byte[] recivebuffer, int netID); 11 | } 12 | 13 | public class SocketClient : SocketBase 14 | { 15 | public SocketClient(INetComponent netComponent) : base(netComponent) 16 | { 17 | } 18 | 19 | public void Connect(string ip, int port) 20 | { 21 | Socket.BeginConnect(ip, port, OnConnectCallBack, Socket); 22 | } 23 | 24 | private void OnConnectCallBack(IAsyncResult ar) 25 | { 26 | if (Socket != null && Socket.Connected) 27 | { 28 | StartListen(Socket); 29 | } 30 | else 31 | { 32 | Error = "Connect faild"; 33 | } 34 | } 35 | 36 | public bool SendMsg(byte[] buffer) 37 | { 38 | return SendMsg(buffer, Socket); 39 | } 40 | } 41 | public class SocketServer : SocketBase 42 | { 43 | public SocketServer(INetComponent netComponent) : base(netComponent) 44 | { 45 | } 46 | 47 | public void Bind(string ip, int port) 48 | { 49 | var ipadr = IPAddress.Parse(ip); 50 | var ipend = new IPEndPoint(ipadr, port); 51 | Socket.Bind(ipend); 52 | Socket.Listen(0); 53 | Socket.BeginAccept(OnClientConnecte, Socket); 54 | } 55 | 56 | private readonly Dictionary m_clients = new Dictionary(); 57 | 58 | public delegate void OnConnecteEvent(int cid); 59 | 60 | public OnConnecteEvent OnConnecte; 61 | 62 | private void OnClientConnecte(IAsyncResult ar) 63 | { 64 | var socket = (Socket)ar.AsyncState; 65 | var client = socket.EndAccept(ar); 66 | var id = StartListen(client); 67 | m_clients.Add(id, client); 68 | if (OnConnecte != null) 69 | OnConnecte(id); 70 | } 71 | 72 | public bool SendMsg(byte[] buffer, int cid) 73 | { 74 | var client = m_clients[cid]; 75 | return SendMsg(buffer, client); 76 | } 77 | 78 | protected override void OnDisconnect() 79 | { 80 | base.OnDisconnect(); 81 | OnConnecte = null; 82 | } 83 | } 84 | 85 | public abstract class SocketBase 86 | { 87 | private INetComponent m_net; 88 | protected Socket Socket { get; private set; } 89 | 90 | protected SocketBase(INetComponent netComponent) 91 | { 92 | m_net = netComponent; 93 | Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 94 | Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); 95 | Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); 96 | } 97 | 98 | private int m_idIndex; 99 | 100 | protected int StartListen(Socket socket) 101 | { 102 | var res = m_idIndex; 103 | m_idIndex++; 104 | var state = new StateObject { WorkSocket = socket, NetID = m_idIndex }; 105 | if (socket != null && socket.Connected) 106 | socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state); 107 | return res; 108 | } 109 | 110 | private void ReceiveCallback(IAsyncResult ar) 111 | { 112 | try 113 | { 114 | var state = (StateObject)ar.AsyncState; 115 | var socket = state.WorkSocket; 116 | if (!socket.Connected) 117 | return; 118 | var bytesRead = socket.EndReceive(ar); 119 | if (bytesRead > 0) 120 | { 121 | var len = state.Result == null ? 0 : state.Result.Length; 122 | var res = new byte[len + bytesRead]; 123 | if (state.Result != null) 124 | Array.Copy(state.Result, 0, res, 0, len); 125 | Array.Copy(state.Buffer, 0, res, len, bytesRead); 126 | state.Result = res; 127 | if (bytesRead <= StateObject.BufferSize) 128 | { 129 | m_net.NetReciveMsg(state.Result, state.NetID); 130 | state.Result = null; 131 | } 132 | if (socket.Connected) 133 | socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state); 134 | } 135 | else 136 | { 137 | Disconnect("Socket Disconnect:bytesRead <= 0"); 138 | } 139 | } 140 | catch (Exception e) 141 | { 142 | Disconnect("Socket Disconnect:" + e.Message); 143 | Error = e.Message; 144 | } 145 | } 146 | 147 | public string DisConnectReason { get; private set; } 148 | 149 | public void Disconnect(string msg) 150 | { 151 | OnDisconnect(); 152 | DisConnectReason = msg; 153 | if (Socket != null && Socket.Connected) 154 | { 155 | try 156 | { 157 | Socket.Shutdown(SocketShutdown.Both); 158 | Socket.Close(); 159 | } 160 | catch (Exception) 161 | { 162 | Socket = null; 163 | } 164 | } 165 | } 166 | 167 | protected virtual void OnDisconnect() 168 | { 169 | } 170 | 171 | public void Destroy() 172 | { 173 | Disconnect("Socket Disconnect:Destroy"); 174 | Socket = null; 175 | m_net = null; 176 | } 177 | 178 | protected bool SendMsg(byte[] buffer, Socket socket) 179 | { 180 | try 181 | { 182 | return socket != null && socket.Send(buffer) > 0; 183 | } 184 | catch (Exception e) 185 | { 186 | Error = e.Message; 187 | return false; 188 | } 189 | } 190 | 191 | public string Error { get; protected set; } 192 | 193 | public bool Connected 194 | { 195 | get 196 | { 197 | if (Socket == null) 198 | return false; 199 | return Socket.Connected; 200 | } 201 | } 202 | 203 | private class StateObject 204 | { 205 | public Socket WorkSocket; 206 | 207 | public const int BufferSize = 1024; 208 | public readonly byte[] Buffer = new byte[BufferSize]; 209 | public byte[] Result; 210 | 211 | public int NetID; 212 | } 213 | } 214 | } -------------------------------------------------------------------------------- /SApiClient/Assets/Core/SocketExtra.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac382fcba77d0774eaeaa099951ba13a 3 | timeCreated: 1461247644 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/Sapi.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13672862acd11ee4a9334a00e5b10d9b 3 | folderAsset: yes 4 | timeCreated: 1461247184 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/Sapi/Speecher.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using Stardust; 5 | using UnityEngine; 6 | using UnityEngine.Events; 7 | 8 | public class Speecher : MonoBehaviour, INetComponent 9 | { 10 | private SocketClient m_socket; 11 | private Process m_process; 12 | 13 | [Header("是否显示Speech.exe")] 14 | public bool ServerDisplay; 15 | 16 | protected void Awake() 17 | { 18 | Ins = this; 19 | m_process = new Process 20 | { 21 | StartInfo = new ProcessStartInfo 22 | { 23 | FileName = "speech.exe", 24 | CreateNoWindow = !ServerDisplay, 25 | WindowStyle = ServerDisplay ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden 26 | }, 27 | }; 28 | m_process.Start(); 29 | } 30 | 31 | /// 32 | /// 开始或者结束语音识别功能 33 | /// 34 | /// 35 | public void Recognize(bool tf) 36 | { 37 | var arg = new ByteInArg(); 38 | arg.Write(3); 39 | arg.Write(tf ? 1 : 0); 40 | NetSendMsg(arg.GetBuffer()); 41 | } 42 | 43 | public IEnumerator Connect() 44 | { 45 | m_socket = new SocketClient(this); 46 | m_socket.Connect("127.0.0.1", 9903); 47 | while (!m_socket.Connected) 48 | { 49 | yield return 1; 50 | } 51 | } 52 | 53 | public IEnumerator InitServer() 54 | { 55 | var arg = new ByteInArg(); 56 | arg.Write(1); 57 | NetSendMsg(arg.GetBuffer()); 58 | yield return 1; 59 | } 60 | 61 | protected void OnDestroy() 62 | { 63 | if (m_process != null && !m_process.HasExited) 64 | { 65 | var res = m_process.CloseMainWindow(); 66 | if (!res) 67 | //m_process.Close(); 68 | m_process.Kill(); 69 | } 70 | m_process = null; 71 | } 72 | 73 | public static Speecher Ins { get; private set; } 74 | 75 | // public void Speak(string str) 76 | // { 77 | //#if UNITY_EDITOR||UNITY_STANDALONE_WIN 78 | // Ins.Speech(str); 79 | //#endif 80 | // } 81 | 82 | public void Speech(string str) 83 | { 84 | if (m_socket.Connected) 85 | { 86 | var arg = new ByteInArg(); 87 | arg.Write(2); 88 | arg.Write(0); 89 | arg.Write(str); 90 | //var bytes = Encoding.Default.GetBytes(str); 91 | NetSendMsg(arg.GetBuffer()); 92 | } 93 | } 94 | 95 | public bool NetReciveMsg(byte[] recivebuffer, int netID) 96 | { 97 | var arg = new ByteOutArg(recivebuffer); 98 | var str = arg.ReadString(); 99 | ResList.Enqueue(str); 100 | //UnityEngine.Debug.Log(str); 101 | return true; 102 | } 103 | 104 | public Queue ResList = new Queue(); 105 | 106 | public void Update() 107 | { 108 | if (ResList.Count > 0) 109 | { 110 | var str = ResList.Dequeue(); 111 | if (OnGetRecognize != null) 112 | OnGetRecognize.Invoke(str); 113 | } 114 | } 115 | 116 | public bool NetSendMsg(byte[] sendbuffer) 117 | { 118 | return m_socket.SendMsg(sendbuffer); 119 | } 120 | 121 | public delegate void GetRecognize(string msg); 122 | public GetRecognize OnGetRecognize; 123 | 124 | public UnityEvent OnGetRecognizeAct; 125 | 126 | public IEnumerator Pause() 127 | { 128 | var arg = new ByteInArg(); 129 | arg.Write(2); 130 | arg.Write(1); 131 | NetSendMsg(arg.GetBuffer()); 132 | yield return 1; 133 | } 134 | 135 | public IEnumerator Resume() 136 | { 137 | var arg = new ByteInArg(); 138 | arg.Write(2); 139 | arg.Write(2); 140 | NetSendMsg(arg.GetBuffer()); 141 | yield return 1; 142 | } 143 | } -------------------------------------------------------------------------------- /SApiClient/Assets/Sapi/Speecher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad230e9f84784844b8c69e9f31009ba1 3 | timeCreated: 1461247156 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/Sapi/SpeecherManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | public class SpeecherManager : MonoBehaviour 4 | { 5 | protected Speecher Speecher; 6 | 7 | protected virtual void Awake() 8 | { 9 | Speecher = GetComponent(); 10 | } 11 | 12 | /***测试代码,可删除Start***/ 13 | 14 | private string m_msg = "Hello World"; 15 | public virtual void OnGUI() 16 | { 17 | if (GUILayout.Button("Connect")) 18 | { 19 | StartCoroutine(Speecher.Connect()); 20 | } 21 | if (GUILayout.Button("InitServer")) 22 | { 23 | StartCoroutine(Speecher.InitServer()); 24 | } 25 | 26 | m_msg = GUILayout.TextField(m_msg); 27 | if (GUILayout.Button("Speak")) 28 | { 29 | Speecher.Speech(m_msg); 30 | } 31 | 32 | if (GUILayout.Button("Pause")) 33 | { 34 | StartCoroutine(Speecher.Pause()); 35 | } 36 | 37 | if (GUILayout.Button("Resume")) 38 | { 39 | StartCoroutine(Speecher.Resume()); 40 | } 41 | 42 | if (GUILayout.Button("Recognize Start")) 43 | { 44 | Speecher.Recognize(true); 45 | } 46 | if (GUILayout.Button("Recognize End")) 47 | { 48 | Speecher.Recognize(false); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /SApiClient/Assets/Sapi/SpeecherManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64a522966c0a2d641b00415fb5e867a3 3 | timeCreated: 1493029135 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /SApiClient/Assets/Scene.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f00a2453657c77c45bafa3e210c8af50 3 | folderAsset: yes 4 | timeCreated: 1461247974 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /SApiClient/Assets/Scene/test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/Assets/Scene/test.unity -------------------------------------------------------------------------------- /SApiClient/Assets/Scene/test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1e216d3772dfcb479e74fa95454fbf5 3 | timeCreated: 1461247974 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.2p1 2 | -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /SApiClient/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /SApiClient/SApiClient.CSharp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 10.0.20506 7 | 2.0 8 | {074B43BF-2FFD-065D-E810-B6D7008482F6} 9 | Library 10 | Assembly-CSharp 11 | 512 12 | {E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | .NETFramework 14 | v3.5 15 | Unity Subset v3.5 16 | 17 | Game:1 18 | StandaloneWindows:5 19 | 5.6.2p1 20 | 21 | 4 22 | 23 | 24 | pdbonly 25 | false 26 | Temp\UnityVS_bin\Debug\ 27 | Temp\UnityVS_obj\Debug\ 28 | prompt 29 | 4 30 | DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_5_6_2;UNITY_5_6;UNITY_5;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_RUNTIME_NAVMESH_BUILDING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;ENABLE_VIDEO;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 31 | false 32 | 33 | 34 | pdbonly 35 | false 36 | Temp\UnityVS_bin\Release\ 37 | Temp\UnityVS_obj\Release\ 38 | prompt 39 | 4 40 | TRACE;UNITY_5_3_OR_NEWER;UNITY_5_4_OR_NEWER;UNITY_5_5_OR_NEWER;UNITY_5_6_OR_NEWER;UNITY_5_6_2;UNITY_5_6;UNITY_5;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_GENERICS;ENABLE_PVR_GI;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_RUNTIME_NAVMESH_BUILDING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_LZMA;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES_COLLAB;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;ENABLE_NATIVE_ARRAY;INCLUDE_DYNAMIC_GI;INCLUDE_GI;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;INCLUDE_PUBNUB;ENABLE_PLAYMODE_TESTS_RUNNER;ENABLE_SCRIPTING_NEW_CSHARP_COMPILER;ENABLE_VIDEO;UNITY_STANDALONE_WIN;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_UNITYWEBREQUEST;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_CRASH_REPORTING;ENABLE_EVENT_QUEUE;ENABLE_CLUSTERINPUT;ENABLE_VR;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;NET_2_0_SUBSET;ENABLE_PROFILER;DEBUG;TRACE;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_WIN;ENABLE_NATIVE_ARRAY_CHECKS;UNITY_TEAM_LICENSE;ENABLE_VSTU;UNITY_PRO_LICENSE 41 | false 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Library\UnityAssemblies\UnityEngine.dll 54 | 55 | 56 | Library\UnityAssemblies\UnityEngine.UI.dll 57 | 58 | 59 | Library\UnityAssemblies\UnityEngine.Networking.dll 60 | 61 | 62 | Library\UnityAssemblies\UnityEngine.TestRunner.dll 63 | 64 | 65 | Library\UnityAssemblies\nunit.framework.dll 66 | 67 | 68 | Library\UnityAssemblies\UnityEngine.Analytics.dll 69 | 70 | 71 | Library\UnityAssemblies\UnityEngine.HoloLens.dll 72 | 73 | 74 | Library\UnityAssemblies\UnityEngine.VR.dll 75 | 76 | 77 | Library\UnityAssemblies\UnityEditor.dll 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /SApiClient/SApiClient.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SapiClient.CSharp", "SapiClient.CSharp.csproj", "{074B43BF-2FFD-065D-E810-B6D7008482F6}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {074B43BF-2FFD-065D-E810-B6D7008482F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {074B43BF-2FFD-065D-E810-B6D7008482F6}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {074B43BF-2FFD-065D-E810-B6D7008482F6}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {074B43BF-2FFD-065D-E810-B6D7008482F6}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /SApiClient/SapiClient.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/SapiClient.v12.suo -------------------------------------------------------------------------------- /SApiClient/Speech.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/SApiClient/Speech.exe -------------------------------------------------------------------------------- /SApiClient/Speech.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 100 12 | 13 | 14 | 0 15 | 16 | 17 | 18 | 19 | 20 | 9903 21 | 22 | 23 | 24 | 26 | Fire 27 | 发射 28 | 29 | 30 | 31 | 32 | zh-CN 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Speech/EmCmd.cs: -------------------------------------------------------------------------------- 1 | //using System; 2 | 3 | namespace Speech 4 | { 5 | public enum EmCmd 6 | { 7 | Init = 1, 8 | Speak = 2, 9 | Recognize = 3 10 | } 11 | 12 | // [Flags] 13 | // public enum EmInitType 14 | // { 15 | // Speak = 0x01, 16 | // Recognize = 0x02, 17 | // } 18 | 19 | // public enum EmRecognizeCmd 20 | // { 21 | // Stop = 0, 22 | // Start = 1, 23 | // } 24 | } -------------------------------------------------------------------------------- /Speech/NetServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Speech.Properties; 3 | using Stardust; 4 | 5 | namespace Speech 6 | { 7 | public class NetServer : INetComponent 8 | { 9 | private Speecher m_speecher; 10 | private Recognizer m_recognizer; 11 | private readonly SocketServer m_socket; 12 | 13 | public NetServer() 14 | { 15 | m_socket = new SocketServer(this); 16 | } 17 | 18 | public void Init() 19 | { 20 | m_speecher = new Speecher(); 21 | m_recognizer = new Recognizer 22 | { 23 | OnRecognized = OnRecognized 24 | }; 25 | Console.WriteLine("初始化完成"); 26 | } 27 | 28 | private void OnRecognized(string text) 29 | { 30 | var arg = new ByteInArg(); 31 | arg.Write(text); 32 | NetSendMsg(arg.GetBuffer()); 33 | } 34 | 35 | public void StartServer() 36 | { 37 | m_socket.OnConnecte = OnClientConnecte; 38 | m_socket.Bind("127.0.0.1", Settings.Default.Port); 39 | } 40 | 41 | private int m_clientid; 42 | private void OnClientConnecte(int cid) 43 | { 44 | m_clientid = cid; 45 | Console.WriteLine("已连接客户端:" + cid); 46 | } 47 | 48 | public bool NetSendMsg(byte[] sendbuffer) 49 | { 50 | return m_socket.SendMsg(sendbuffer, m_clientid); 51 | } 52 | 53 | public bool NetReciveMsg(byte[] recivebuffer, int netID) 54 | { 55 | var arg = new ByteOutArg(recivebuffer); 56 | var cmd = arg.ReadInt32(); 57 | switch ((EmCmd)cmd) 58 | { 59 | case EmCmd.Init: 60 | Init(); 61 | break; 62 | case EmCmd.Speak: 63 | var speakcmd= arg.ReadInt32(); 64 | if (speakcmd == 0) 65 | { 66 | var str = arg.ReadString(); 67 | Console.WriteLine(str); 68 | m_speecher.Speak(str); 69 | } 70 | else if (speakcmd == 1) 71 | { 72 | m_speecher.Pause(); 73 | } 74 | else if(speakcmd==2) 75 | { 76 | m_speecher.Resume(); 77 | } 78 | return true; 79 | case EmCmd.Recognize: 80 | var scmd = arg.ReadInt32(); 81 | if (scmd == 1) 82 | m_recognizer.BeginRec(); 83 | if (scmd == 0) 84 | m_recognizer.EndRec(); 85 | return true; 86 | default: 87 | throw new ArgumentOutOfRangeException(); 88 | } 89 | return false; 90 | } 91 | 92 | public bool Connected 93 | { 94 | get { return m_socket.Connected; } 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /Speech/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Speech.Synthesis; 3 | 4 | namespace Speech 5 | { 6 | class Program 7 | { 8 | static void Main(string[] args) 9 | { 10 | var server = new NetServer(); 11 | server.StartServer(); 12 | 13 | while (true) 14 | { 15 | var res = Console.ReadLine(); 16 | if (res == "exit") 17 | break; 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Speech/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // 有关程序集的常规信息通过以下 5 | // 特性集控制。更改这些特性值可修改 6 | // 与程序集关联的信息。 7 | [assembly: AssemblyTitle("Speech")] 8 | [assembly: AssemblyDescription("")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("")] 11 | [assembly: AssemblyProduct("Speech")] 12 | [assembly: AssemblyCopyright("Copyright © 2016")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // 将 ComVisible 设置为 false 使此程序集中的类型 17 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 18 | // 则将该类型上的 ComVisible 特性设置为 true。 19 | [assembly: ComVisible(false)] 20 | 21 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 22 | [assembly: Guid("3f688586-0cfa-48f5-8189-d027b52054e0")] 23 | 24 | // 程序集的版本信息由下面四个值组成: 25 | // 26 | // 主版本 27 | // 次版本 28 | // 生成号 29 | // 修订号 30 | // 31 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 32 | // 方法是按如下所示使用“*”: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /Speech/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Speech.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("100")] 29 | public int SpeakVolume { 30 | get { 31 | return ((int)(this["SpeakVolume"])); 32 | } 33 | set { 34 | this["SpeakVolume"] = value; 35 | } 36 | } 37 | 38 | [global::System.Configuration.UserScopedSettingAttribute()] 39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 40 | [global::System.Configuration.DefaultSettingValueAttribute("0")] 41 | public int SpeakRate { 42 | get { 43 | return ((int)(this["SpeakRate"])); 44 | } 45 | set { 46 | this["SpeakRate"] = value; 47 | } 48 | } 49 | 50 | [global::System.Configuration.UserScopedSettingAttribute()] 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 52 | [global::System.Configuration.DefaultSettingValueAttribute("")] 53 | public string SpeakVoice { 54 | get { 55 | return ((string)(this["SpeakVoice"])); 56 | } 57 | set { 58 | this["SpeakVoice"] = value; 59 | } 60 | } 61 | 62 | [global::System.Configuration.UserScopedSettingAttribute()] 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 | [global::System.Configuration.DefaultSettingValueAttribute("9903")] 65 | public int Port { 66 | get { 67 | return ((int)(this["Port"])); 68 | } 69 | set { 70 | this["Port"] = value; 71 | } 72 | } 73 | 74 | [global::System.Configuration.UserScopedSettingAttribute()] 75 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 76 | [global::System.Configuration.DefaultSettingValueAttribute("\r\n\r\n Fire\r\n 发射\r\n")] 79 | public global::System.Collections.Specialized.StringCollection Keywords { 80 | get { 81 | return ((global::System.Collections.Specialized.StringCollection)(this["Keywords"])); 82 | } 83 | set { 84 | this["Keywords"] = value; 85 | } 86 | } 87 | 88 | [global::System.Configuration.UserScopedSettingAttribute()] 89 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 90 | [global::System.Configuration.DefaultSettingValueAttribute("zh-CN")] 91 | public string DefaultLang { 92 | get { 93 | return ((string)(this["DefaultLang"])); 94 | } 95 | set { 96 | this["DefaultLang"] = value; 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Speech/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 100 7 | 8 | 9 | 0 10 | 11 | 12 | 13 | 14 | 15 | 9903 16 | 17 | 18 | <?xml version="1.0" encoding="utf-16"?> 19 | <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 20 | <string>Fire</string> 21 | <string>发射</string> 22 | </ArrayOfString> 23 | 24 | 25 | zh-CN 26 | 27 | 28 | -------------------------------------------------------------------------------- /Speech/Recognizer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Speech.Recognition; 4 | using Speech.Properties; 5 | 6 | namespace Speech 7 | { 8 | public delegate void SpeechRecognized(string text); 9 | 10 | public class Recognizer 11 | { 12 | private readonly SpeechRecognitionEngine m_recognizer;//语音识别引擎 13 | private readonly DictationGrammar m_grammar; //自然语法 14 | 15 | public Recognizer() 16 | { 17 | var myCIintl = new CultureInfo("en-US"); 18 | var rs = SpeechRecognitionEngine.InstalledRecognizers(); 19 | if (rs.Count > 0) 20 | { 21 | foreach (var config in rs)//获取所有语音引擎 22 | { 23 | if (config.Culture.Equals(myCIintl) && config.Id == "MS-1033-80-DESK") 24 | { 25 | m_recognizer = new SpeechRecognitionEngine(config); 26 | break; 27 | }//选择美国英语的识别引擎 28 | } 29 | if (m_recognizer == null)//如果没有适合的语音引擎,则选用第一个 30 | m_recognizer = new SpeechRecognitionEngine(rs[0]); 31 | } 32 | if (m_recognizer != null) 33 | { 34 | var kws = Settings.Default.Keywords; 35 | var fg = new string[kws.Count]; 36 | kws.CopyTo(fg, 0); 37 | InitializeSpeechRecognitionEngine(fg);//初始化语音识别引擎 38 | m_grammar = new DictationGrammar(); 39 | } 40 | else 41 | { 42 | Console.WriteLine("创建语音识别失败"); 43 | } 44 | } 45 | 46 | private void InitializeSpeechRecognitionEngine(string[] fg) 47 | { 48 | m_recognizer.SetInputToDefaultAudioDevice();//选择默认的音频输入设备 49 | var customGrammar = CreateCustomGrammar(fg); 50 | //根据关键字数组建立语法 51 | m_recognizer.UnloadAllGrammars(); 52 | m_recognizer.LoadGrammar(customGrammar); 53 | //加载语法 54 | m_recognizer.SpeechRecognized += recognizer_SpeechRecognized; 55 | //m_recognizer.SpeechHypothesized += recognizer_SpeechHypothesized; 56 | } 57 | 58 | public SpeechRecognized OnRecognized; 59 | 60 | private void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 61 | { 62 | Console.WriteLine("SpeechRecognized:" + e.Result.Text); 63 | OnRecognized?.Invoke(e.Result.Text); 64 | } 65 | 66 | private void recognizer_SpeechHypothesized(object sender, SpeechHypothesizedEventArgs e) 67 | { 68 | 69 | } 70 | 71 | /// 72 | /// 录音并识别 73 | /// 74 | public void BeginRec() 75 | { 76 | Console.WriteLine("BeginRec"); 77 | TurnSpeechRecognitionOn(); 78 | TurnDictationOn(); 79 | } 80 | 81 | private void TurnDictationOn() 82 | { 83 | if (m_recognizer != null) 84 | { 85 | m_recognizer.LoadGrammar(m_grammar); 86 | //加载自然语法 87 | } 88 | else 89 | { 90 | Console.WriteLine("创建语音识别失败"); 91 | } 92 | } 93 | 94 | private void TurnSpeechRecognitionOn()//启动语音识别函数 95 | { 96 | if (m_recognizer != null) 97 | { 98 | m_recognizer.RecognizeAsync(RecognizeMode.Multiple); 99 | //识别模式为连续识别 100 | } 101 | else 102 | { 103 | Console.WriteLine("创建语音识别失败"); 104 | } 105 | } 106 | 107 | public void EndRec()//停止语音识别引擎 108 | { 109 | Console.WriteLine("EndRec"); 110 | TurnSpeechRecognitionOff(); 111 | } 112 | 113 | private void TurnSpeechRecognitionOff()//关闭语音识别函数 114 | { 115 | if (m_recognizer != null) 116 | { 117 | m_recognizer.RecognizeAsyncStop(); 118 | TurnDictationOff(); 119 | } 120 | else 121 | { 122 | Console.WriteLine("创建语音识别失败"); 123 | } 124 | } 125 | 126 | private void TurnDictationOff() 127 | { 128 | if (m_grammar != null) 129 | { 130 | m_recognizer.UnloadGrammar(m_grammar); 131 | //卸载自然语法 132 | } 133 | else 134 | { 135 | Console.WriteLine("创建语音识别失败"); 136 | } 137 | } 138 | 139 | private Grammar CreateCustomGrammar(string[] fg) //创造自定义语法 140 | { 141 | var grammarBuilder = new GrammarBuilder(); 142 | grammarBuilder.Append(new Choices(fg)); 143 | return new Grammar(grammarBuilder); 144 | } 145 | } 146 | } -------------------------------------------------------------------------------- /Speech/Speech.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {75C5ABB7-650C-444F-9657-A4A054F67E99} 8 | Exe 9 | Properties 10 | Speech 11 | Speech 12 | v3.5 13 | 512 14 | 15 | 16 | 发布\ 17 | true 18 | Disk 19 | false 20 | Foreground 21 | 7 22 | Days 23 | false 24 | false 25 | true 26 | 0 27 | 1.0.0.%2a 28 | false 29 | false 30 | true 31 | 32 | 33 | AnyCPU 34 | true 35 | full 36 | false 37 | bin\Debug\ 38 | DEBUG;TRACE 39 | prompt 40 | 4 41 | 42 | 43 | AnyCPU 44 | pdbonly 45 | true 46 | bin\Release\ 47 | TRACE 48 | prompt 49 | 4 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Core\ByteInArg.cs 63 | 64 | 65 | Core\SocketExtra.cs 66 | 67 | 68 | 69 | 70 | 71 | 72 | True 73 | True 74 | Settings.settings 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | SettingsSingleFileGenerator 83 | Settings.Designer.cs 84 | 85 | 86 | 87 | 88 | False 89 | .NET Framework 3.5 SP1 Client Profile 90 | false 91 | 92 | 93 | False 94 | .NET Framework 3.5 SP1 95 | true 96 | 97 | 98 | 99 | 100 | copy $(TargetDir)$(TargetName).exe $(SolutionDir) 101 | copy $(TargetDir)$(TargetName).exe.config $(SolutionDir) 102 | 103 | 110 | -------------------------------------------------------------------------------- /Speech/Speech.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /Speech/Speech.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/Speech/Speech.exe -------------------------------------------------------------------------------- /Speech/Speech.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 100 12 | 13 | 14 | 0 15 | 16 | 17 | 18 | 19 | 20 | 9903 21 | 22 | 23 | 24 | 26 | Fire 27 | 发射 28 | 29 | 30 | 31 | 32 | zh-CN 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Speech/Speech.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Speech", "Speech.csproj", "{75C5ABB7-650C-444F-9657-A4A054F67E99}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {75C5ABB7-650C-444F-9657-A4A054F67E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {75C5ABB7-650C-444F-9657-A4A054F67E99}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {75C5ABB7-650C-444F-9657-A4A054F67E99}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {75C5ABB7-650C-444F-9657-A4A054F67E99}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Speech/Speech.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YiuChoi/UnityTTS/9216a536364a7974f9ea57a58014a88fa40d7557/Speech/Speech.v12.suo -------------------------------------------------------------------------------- /Speech/Speecher.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Speech.Synthesis; 3 | using Speech.Properties; 4 | 5 | namespace Speech 6 | { 7 | public class Speecher 8 | { 9 | private readonly SpeechSynthesizer m_speaker; 10 | 11 | public Speecher() 12 | { 13 | m_speaker = new SpeechSynthesizer(); 14 | var installs = m_speaker.GetInstalledVoices(); 15 | 16 | m_speaker.Volume = Settings.Default.SpeakVolume; 17 | m_speaker.Rate = Settings.Default.SpeakRate; 18 | var voice = Settings.Default.SpeakVoice; 19 | 20 | var selected = false; 21 | if (!string.IsNullOrEmpty(voice)) 22 | { 23 | if (installs.Any(install => install.VoiceInfo.Name == voice)) 24 | { 25 | m_speaker.SelectVoice(voice); 26 | selected = true; 27 | } 28 | } 29 | if (!selected) 30 | { 31 | foreach (var install in installs.Where(install => install.VoiceInfo.Culture.Name == Settings.Default.DefaultLang/*"en-US"*/)) 32 | { 33 | m_speaker.SelectVoice(install.VoiceInfo.Name); 34 | break; 35 | } 36 | } 37 | } 38 | 39 | private Prompt m_curPrompt; 40 | /// 41 | /// 读一个文本 42 | /// 43 | /// 44 | public void Speak(string msg) 45 | { 46 | if (m_curPrompt != null) 47 | m_speaker.SpeakAsyncCancel(m_curPrompt); 48 | 49 | m_curPrompt = m_speaker.SpeakAsync(msg); 50 | } 51 | 52 | public void Pause() 53 | { 54 | m_speaker.Pause(); 55 | } 56 | 57 | public void Resume() 58 | { 59 | m_speaker.Resume(); 60 | } 61 | 62 | public SynthesizerState State => m_speaker.State; 63 | } 64 | } -------------------------------------------------------------------------------- /Speech/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 100 12 | 13 | 14 | 0 15 | 16 | 17 | 18 | 19 | 20 | 9903 21 | 22 | 23 | 24 | 26 | Fire 27 | 发射 28 | 29 | 30 | 31 | 32 | zh-CN 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-time-machine --------------------------------------------------------------------------------