Exemple #1
0
 public static TTSRealize GetInitialize()
 {
     if (tTSRealize == null)
     {
         lock (lockObj)
         {
             if (tTSRealize == null)
             {
                 tTSRealize = new TTSRealize();
             }
         }
     }
     return(tTSRealize);
 }
Exemple #2
0
        /// <summary>
        /// 获取合成的音频
        /// </summary>
        /// <param name="sessionID">会话id</param>
        /// <param name="audioLen">合成的音频字节长度</param>
        /// <param name="synthStatus">合成音频状态,可能的值如下:1:音频还没取完,还有后继的音频;2:音频已经取完</param>
        /// <param name="errorCode">返回的错误码</param>
        /// <returns></returns>
        public byte[] TTSAudioGet(string sessionID, ref uint audioLen, ref int synthStatus, ref int errorCode)
        {
            byte[] result = null;
            var    head   = TTSRealize.GetInitialize().GetWavHead(); //音频头

            try
            {
                do
                {
                    var intPtr = TTS_DLL.QTTSAudioGet(sessionID, ref audioLen, ref synthStatus, ref errorCode);
                    if (errorCode != 0)
                    {
                        break;                  //错误时,跳出循环
                    }
                    if (intPtr != null && intPtr != IntPtr.Zero)
                    {
                        head.DATA_Size += (int)audioLen;
                        var source = ConvertHelper.IntPtrToBytes(intPtr, (int)audioLen);
                        if (result == null)
                        {
                            result = new byte[audioLen];
                            source.CopyTo(result, 0);
                        }
                        else
                        {
                            var tempBytes = result;
                            result = new byte[tempBytes.Length + audioLen];
                            tempBytes.CopyTo(result, 0);
                            source.CopyTo(result, tempBytes.Length);
                        }
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(0.5));
                }while (synthStatus != 2);
                head.File_Size += head.DATA_Size + (Marshal.SizeOf(head) - 8);
                if (result != null)
                {
                    var    tempBytes = result;
                    byte[] headBytes = ConvertHelper.StructToBytes(head);
                    result = new byte[headBytes.Length + tempBytes.Length];
                    headBytes.CopyTo(result, 0);
                    tempBytes.CopyTo(result, headBytes.Length);
                }
            }
            catch (Exception ex)
            {
            }
            return(result);
        }