private void Awake()
    {
        client = gameObject.GetComponent <UnityClient>();
        client.MessageReceived += TTSMessageHandler;
        client.Disconnected    += TTSDisconnectHandler;

        ttsClient = gameObject.GetComponent <TTSClient>();

        hudCanvas.SetActive(false);
    }
    IEnumerator StartGameHandler()
    {
        TTSClient client = GameObject.FindGameObjectWithTag("Network").GetComponent <TTSClient>();

        while (!client.initSyncFinished || client.localPlayerId == 0)
        {
            yield return(new WaitForSeconds(.1f));
        }
        client.GameStart();
        GameObject.FindGameObjectWithTag("StartMenu").SetActive(false);
        hudCanvas.SetActive(true);
    }
Пример #3
0
        public void Tts(int speed = 5, int vol = 6, int person = 4)
        {
            var client = TTSClient.GetClient();

            if (person == 1)
            {
                person = 2;
            }
            else if (person == 2)
            {
                person = 0;
            }
            // 可选参数
            var option = new Dictionary <string, object>()
            {
                { "spd", speed }, // 语速
                { "vol", vol },   // 音量
                { "per", person }  // 发音人,4:情感度丫丫童声
            };
            var    result = client.Synthesis(txtMsg.Text, option);
            object obj    = new object();

            if (result.ErrorCode == 0)  // 或 result.Success
            {
                string name      = txtMsg.Text; /* + DateTime.Now.ToString("yyyyMMddHHssffff")*/;
                var    outputDic = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Output");
                if (!Directory.Exists(outputDic))
                {
                    Directory.CreateDirectory(outputDic);
                }
                var path = System.IO.Path.Combine(outputDic, $"{name}百度{DateTime.Now:yyyyMMddHHmmssffff}.mp3");
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                Thread.Sleep(1000);
                File.WriteAllBytes(path, result.Data);

                if (chkOpenDir.IsChecked == true)
                {
                    OpenDir();
                }
                else
                {
                    MessageBox.Show("生成成功");
                }
            }
        }
Пример #4
0
        public FileResult GenerateAudio(string id, int pageNumber)
        {
            var contentItem = (from c in DataSource.subscriptionItems
                               where c.Id == id
                               select c).FirstOrDefault <SubscriptionItem>();

            var provider = new PhysicalFileProvider(_hostingEnvironment.ContentRootPath);
            var fileInfo = provider.GetFileInfo($"wwwroot/{contentItem.CommentaryFileName}");

            var pageContent = PdfLib.PdfIndexParser.ReadThePage(fileInfo.PhysicalPath, pageNumber);

            var audioFilePath = fileInfo.PhysicalPath.Replace(".pdf", ".mp3");

            TTSClient.CreateSpeechFile(pageContent, audioFilePath);

            var fs = new FileStream(audioFilePath, FileMode.Open);

            return(new FileStreamResult(fs, "audio/mpeg"));
        }