/// <summary> /// 接收消息中的语音 (消息含有CQ码 "record" 的消息) /// </summary> /// <param name="format">所需的目标语音的音频格式</param> /// <returns>返回语音文件位于本地服务器的绝对路径</returns> public string ReceiveRecord(CQAudioFormat format) { if (!this.IsRegexMessage) { CQCode record = (from code in this.CQCodes where code.Function == CQFunction.Record select code).First(); return(this.CQApi.ReceiveRecord(record.Items["file"], format)); } else { #if DEBUG throw new MethodAccessException("无法在正则事件中调用 ToSendString, 因为正则事件获取的消息无法用于发送"); #else return(null); #endif } }
/// <summary> /// 接收消息中的语音 (消息含有CQ码 "record" 的消息) /// </summary> /// <param name="format">所需的目标语音的音频格式</param> /// <exception cref="ArithmeticException">当前实例属于正则消息时 (仅 Debug 生效)</exception> /// <returns>返回语音文件位于本地服务器的绝对路径</returns> public string ReceiveRecord(CQAudioFormat format) { if (this.IsRegexMessage) { #if DEBUG throw new ArithmeticException("无法解析原始消息. 原因: 当前消息属于正则消息"); #endif } if (this.IsRecordMessage) { return(this.CQApi.ReceiveRecord(this.CQCodes[0].Items["file"], format)); } return(null); }
/// <summary> /// 接收消息中的语音 (消息含有CQ码 "record" 的消息) /// </summary> /// <param name="fileName">文件名, [CQ:record...] 中的文件名部分</param> /// <param name="format">所需的目标语音的音频格式</param> /// <exception cref="ArgumentException">参数: fileName 是空字符串或为 null</exception> /// <returns>返回语音文件位于本地服务器的绝对路径</returns> public string ReceiveRecord(string fileName, CQAudioFormat format) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentException("文件名不可为空", "fileName"); } GCHandle fileNameHandler = fileName.GetStringGCHandle(CQApi.DefaultEncoding); GCHandle formatHandler = format.GetDescription().GetStringGCHandle(CQApi.DefaultEncoding); try { return(CQP.CQ_getRecordV2(this.AppInfo.AuthCode, fileNameHandler.AddrOfPinnedObject(), formatHandler.AddrOfPinnedObject()).ToString(CQApi.DefaultEncoding)); } finally { fileNameHandler.Free(); formatHandler.Free(); } }