Esempio n. 1
0
        /// <summary>
        /// Plays to file.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="text">The text.</param>
        /// <param name="playType">Type of the play.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public override bool PlayToFile(IChannel channel, string text, TTSPlayType playType, string fileName)
        {
            if (!canWork)
            {
                Logger.Warn("因TTS引擎初始化失败或其它原因造成不可用,不能进行TTS放音");
                return(false);
            }

            if (channel == null)
            {
                Logger.Warn("传入通道参数未初始化不能进行TTS放音");
                return(false);
            }

            string dir = Path.GetDirectoryName(fileName);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            string fileext = Path.GetExtension(fileName);

            lock (D160X.SyncObj)
            {
                Logger.Info(string.Format("通道 {0} 利用TTS转换文字 {1} 到语音文件 \"{2}\"", channel.ChannelID, text, fileName));
                // 根据文件扩展名转换为不同格式的语音文件
                switch (fileext.ToLower())
                {
                case ".voc":
                    TTS3.DJTTS3_CvtTextToVocFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                                                 50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                    break;

                case ".wav":
                    TTS3.DJTTS3_CvtTextToWaveFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                                                  50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                    break;

                default:
                    TTS3.DJTTS3_CvtTextToVocFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                                                 50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                    break;
                }
            }

            return(true);
        }
Esempio n. 2
0
 /// <summary>
 /// Plays to file.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="text">The text.</param>
 /// <param name="playType">Type of the play.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <returns></returns>
 public virtual bool PlayToFile(IChannel channel, string text, TTSPlayType playType, string fileName)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 3
0
 /// <summary>
 /// Plays the message.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="text">The text.</param>
 /// <param name="allowBreak">if set to <c>true</c> [allow break].</param>
 /// <param name="playType">Type of the play.</param>
 /// <returns></returns>
 public virtual SwitchStatus PlayMessage(IChannel channel, string text, bool allowBreak, TTSPlayType playType)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 4
0
 /// <summary>
 /// 通过<seealso cref="ITTSEngine"/>引擎实现从文本到语音的播放,此函数专门用于对数字进行转换和播放在相应的TTS引擎中会对此部分进行优化处理
 /// </summary>
 /// <param name="text">待播放的数字内容</param>
 /// <param name="allowBreak">放音过程中是否允许用户按键打断</param>
 /// <param name="playType">TTS放音类型,详细信息请参考<seealso cref="TTSPlayType"/></param>
 /// <returns>
 /// 播放语音的结果状态,详细信息请参考<seealso cref="PlayResult"/>
 /// </returns>
 /// <seealso cref="PlayFile"/>
 /// <seealso cref="PlayMessage"/>
 /// <seealso cref="PlayToFile"/>
 public virtual SwitchStatus PlayNumber(string text, bool allowBreak, TTSPlayType playType)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 5
0
        /// <summary>
        /// ͨ��<seealso cref="ITTSEngine"/>����ʵ�ִ��ı�������IJ��ţ��˺���ר�����ڶ����ֽ���ת���Ͳ�������Ӧ��TTS�����л�Դ˲��ֽ����Ż�����
        /// </summary>
        /// <param name="text">�����ŵ���������</param>
        /// <param name="allowBreak">����������Ƿ������û��������</param>
        /// <param name="playType">TTS�������ͣ���ϸ��Ϣ��ο�<seealso cref="TTSPlayType"/></param>
        /// <returns>
        /// ��������Ľ��״̬����ϸ��Ϣ��ο�<seealso cref="PlayResult"/>
        /// </returns>
        /// <seealso cref="PlayFile"/>
        /// <seealso cref="PlayMessage"/>
        /// <seealso cref="PlayToFile"/>
        public override SwitchStatus PlayNumber(string text, bool allowBreak, TTSPlayType playType)
        {
            if (CurrentStatus == ChannelStatus.HANGUP)
                return SwitchStatus.BREAK;

            ITTSEngine tts = CurrentTTS();

            // ��TTS����ִ�з������
            CurrentStatus = ChannelStatus.PLAY;
            return tts.PlayMessage(this as IChannel, text, allowBreak, playType);
        }
Esempio n. 6
0
        /// <summary>
        /// Plays to file.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="text">The text.</param>
        /// <param name="playType">Type of the play.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <returns></returns>
        public override bool PlayToFile(IChannel channel, string text, TTSPlayType playType, string fileName)
        {
            if (!canWork)
            {
                Logger.Warn("��TTS�����ʼ��ʧ�ܻ�����ԭ����ɲ����ã����ܽ���TTS����");
                return false;
            }

            if (channel == null)
            {
                Logger.Warn("����ͨ������δ��ʼ�����ܽ���TTS����");
                return false;
            }

            string dir = Path.GetDirectoryName(fileName);
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            string fileext = Path.GetExtension(fileName);
            lock (D160X.SyncObj)
            {
                Logger.Info(string.Format("ͨ�� {0} ����TTSת������ {1} �������ļ� \"{2}\"", channel.ChannelID, text, fileName));
                // �����ļ���չ��ת��Ϊ��ͬ��ʽ�������ļ�
                switch (fileext.ToLower())
                {
                    case ".voc":
                        TTS3.DJTTS3_CvtTextToVocFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                            50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                        break;

                    case ".wav":
                        TTS3.DJTTS3_CvtTextToWaveFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                            50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                        break;

                    default:
                        TTS3.DJTTS3_CvtTextToVocFile(Encoding.UTF8.GetBytes(text), 50, Encoding.UTF8.GetBytes(fileName), channel.ChannelID,
                            50, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                        break;
                }

            }

            return true;
        }
Esempio n. 7
0
        /// <summary>
        /// Plays the message.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="text">The text.</param>
        /// <param name="allowBreak">if set to <c>true</c> [allow break].</param>
        /// <param name="playType">Type of the play.</param>
        /// <returns></returns>
        public override SwitchStatus PlayMessage(IChannel channel, string text, bool allowBreak, TTSPlayType playType)
        {
            if (!canWork)
            {
                Logger.Warn("��TTS�����ʼ��ʧ�ܻ�����ԭ����ɲ����ã����ܽ���TTS����");
                return SwitchStatus.FAILURE;
            }

            if (channel == null)
            {
                Logger.Warn("����ͨ������δ��ʼ�����ܽ���TTS����");
                return SwitchStatus.FAILURE;
            }

            lock (D160X.SyncObj)
            {
                Logger.Info(string.Format("ͨ�� {0} ׼��TTS�������������Ϊ��{1}", channel.ChannelID, text));
                Int32 Playflag = TTS3.DJTTS3_StartPlayText(channel.ChannelID, Encoding.UTF8.GetBytes(text), TTS3.INFO_TEXT_BUFFER,
                    0, 45, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                Logger.Debug("TTS��������" + Playflag.ToString());
                D160X.InitDtmfBuf(channel.ChannelID);
            }

            // �ڷ�����Ҫ���ϵļ�����Ƿ��Ѿ��������
            Int32 Playend = TTS3.INFO_PLAY_NOT_COMPLATE;
            while(Playend == TTS3.INFO_PLAY_NOT_COMPLATE)
            {
                lock (D160X.SyncObj)
                {
                    D160X.PUSH_PLAY();
                }
                System.Threading.Thread.Sleep(Defaultdelay);

                bool dtmfHited = false;
                lock (D160X.SyncObj)
                {
                    dtmfHited = D160X.DtmfHit(channel.ChannelID);
                }
                if (allowBreak && dtmfHited)
                {
                    lock (D160X.SyncObj)
                    {
                        TTS3.DJTTS3_StopPlayText(channel.ChannelID);
                    }
                    Logger.Info(string.Format("ͨ�� {0} TTS������̱��Է������ж�", channel.ChannelID));
                    return SwitchStatus.BREAK;
                }

                if (channel.HangUpDetect())
                {
                    lock (D160X.SyncObj)
                    {
                        TTS3.DJTTS3_StopPlayText(channel.ChannelID);
                    }
                    Logger.Info(string.Format("ͨ�� {0} TTS������̱��Է��һ��ж�", channel.ChannelID));
                    channel.ResetChannel();
                    return SwitchStatus.BREAK;
                }

                lock (D160X.SyncObj)
                {
                    Playend = TTS3.DJTTS3_CheckPlayTextEnd(channel.ChannelID);
                }
            }

            lock (D160X.SyncObj)
            {
                TTS3.DJTTS3_StopPlayText(channel.ChannelID);
            }
            Logger.Info(string.Format("ͨ�� {0} TTS�������", channel.ChannelID));
            return SwitchStatus.SUCCESS;
        }
Esempio n. 8
0
        /// <summary>
        /// Plays the message.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="text">The text.</param>
        /// <param name="allowBreak">if set to <c>true</c> [allow break].</param>
        /// <param name="playType">Type of the play.</param>
        /// <returns></returns>
        public override SwitchStatus PlayMessage(IChannel channel, string text, bool allowBreak, TTSPlayType playType)
        {
            if (!canWork)
            {
                Logger.Warn("因TTS引擎初始化失败或其它原因造成不可用,不能进行TTS放音");
                return(SwitchStatus.FAILURE);
            }

            if (channel == null)
            {
                Logger.Warn("传入通道参数未初始化不能进行TTS放音");
                return(SwitchStatus.FAILURE);
            }

            lock (D160X.SyncObj)
            {
                Logger.Info(string.Format("通道 {0} 准备TTS放音,放音内容为:{1}", channel.ChannelID, text));
                Int32 Playflag = TTS3.DJTTS3_StartPlayText(channel.ChannelID, Encoding.UTF8.GetBytes(text), TTS3.INFO_TEXT_BUFFER,
                                                           0, 45, 50, XmlTag ? TTS3.INFO_USE_LABLE : TTS3.INFO_NOTUSE_LABLE);
                Logger.Debug("TTS放音结果为:" + Playflag.ToString());
                D160X.InitDtmfBuf(channel.ChannelID);
            }

            // 在放音后就要不断的检查其是否已经播放完毕
            Int32 Playend = TTS3.INFO_PLAY_NOT_COMPLATE;

            while (Playend == TTS3.INFO_PLAY_NOT_COMPLATE)
            {
                lock (D160X.SyncObj)
                {
                    D160X.PUSH_PLAY();
                }
                System.Threading.Thread.Sleep(Defaultdelay);

                bool dtmfHited = false;
                lock (D160X.SyncObj)
                {
                    dtmfHited = D160X.DtmfHit(channel.ChannelID);
                }
                if (allowBreak && dtmfHited)
                {
                    lock (D160X.SyncObj)
                    {
                        TTS3.DJTTS3_StopPlayText(channel.ChannelID);
                    }
                    Logger.Info(string.Format("通道 {0} TTS放音过程被对方按键中断", channel.ChannelID));
                    return(SwitchStatus.BREAK);
                }

                if (channel.HangUpDetect())
                {
                    lock (D160X.SyncObj)
                    {
                        TTS3.DJTTS3_StopPlayText(channel.ChannelID);
                    }
                    Logger.Info(string.Format("通道 {0} TTS放音过程被对方挂机中断", channel.ChannelID));
                    channel.ResetChannel();
                    return(SwitchStatus.BREAK);
                }

                lock (D160X.SyncObj)
                {
                    Playend = TTS3.DJTTS3_CheckPlayTextEnd(channel.ChannelID);
                }
            }

            lock (D160X.SyncObj)
            {
                TTS3.DJTTS3_StopPlayText(channel.ChannelID);
            }
            Logger.Info(string.Format("通道 {0} TTS放音结束", channel.ChannelID));
            return(SwitchStatus.SUCCESS);
        }
Esempio n. 9
0
 /// <summary>
 /// ͨ��<seealso cref="ITTSEngine"/>����ʵ�ִ��ı�������IJ��ţ��˺���ר�����ڶ����ֽ���ת���Ͳ�������Ӧ��TTS�����л�Դ˲��ֽ����Ż�����
 /// </summary>
 /// <param name="text">�����ŵ���������</param>
 /// <param name="allowBreak">����������Ƿ������û��������</param>
 /// <param name="playType">TTS�������ͣ���ϸ��Ϣ��ο�<seealso cref="TTSPlayType"/></param>
 /// <returns>
 /// ��������Ľ��״̬����ϸ��Ϣ��ο�<seealso cref="PlayResult"/>
 /// </returns>
 /// <seealso cref="PlayFile"/>
 /// <seealso cref="PlayMessage"/>
 /// <seealso cref="PlayToFile"/>
 public virtual SwitchStatus PlayNumber(string text, bool allowBreak, TTSPlayType playType)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 10
0
 /// <summary>
 /// Plays the message.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="text">The text.</param>
 /// <param name="allowBreak">if set to <c>true</c> [allow break].</param>
 /// <param name="playType">Type of the play.</param>
 /// <returns></returns>
 public virtual SwitchStatus PlayMessage(IChannel channel, string text, bool allowBreak, TTSPlayType playType)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Esempio n. 11
0
 /// <summary>
 /// Plays to file.
 /// </summary>
 /// <param name="channel">The channel.</param>
 /// <param name="text">The text.</param>
 /// <param name="playType">Type of the play.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <returns></returns>
 public virtual bool PlayToFile(IChannel channel, string text, TTSPlayType playType, string fileName)
 {
     throw new Exception("The method or operation is not implemented.");
 }