Ejemplo n.º 1
0
        /// <summary>
        /// 重新上传语音消息
        /// </summary>
        /// <param name="aa"></param>
        public void UpLoadVoice(int aa)
        {
            Debug.LogWarning("____重传_____");
            HandleUpLoadVoiceErr -= UpLoadVoice;
            string fileId = DateTime.Now.ToFileTime().ToString();

            ChangeBool_isCompeletUpload();
            YunVaImSDK.instance.UploadFileRequest(filePath_1, fileId, (data1) =>
            {
                if (data1.result == 0)
                {
                    Debug.Log("重新上传成功:" + data1.fileurl);
                    SendVoiceMessage(data1.fileurl, aa, null);
                }
                else
                {
                    Debug.Log("重新上传失败:" + data1.msg);
                    MahjongCommonMethod.Instance.ShowRemindFrame("上传声音失败,请重新录制 ", true);
                }
            });
        }
Ejemplo n.º 2
0
        long fVoiceTime;//录音时长
        void RecordStop()
        {
            //停止动画
            CancelInvoke("LimitTimeEnd");

            startwatch.Stop();
            fVoiceTime = startwatch.ElapsedMilliseconds;//录音时长

            if (fVoiceTime <= 500)
            {
                // Debug.LogWarning("录音时间太短");

                MahjongCommonMethod.Instance.ShowRemindFrame("录音时间太短");
                StartCoroutine(LockButton());
                return;
            }
            Debug.LogWarning("按钮松开5");
            // Debug.LogWarning("开始上传了");
            try
            {
                isCompeletUpload = false;
                if (VoiceFlag == 1)
                {
                    //停止录音
                    int err = m_voiceengine.StopRecording();
                    if (err != 0)
                    {
                        goto Err1;
                    }
                    //上传
                    err = m_voiceengine.UploadRecordedFile(filePath_1, 5500);
                    m_voiceengine.OnUploadReccordFileComplete += (code, path, id) =>
                    {
                        if (IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_UPLOAD_RECORD_DONE == code)
                        {
                            Debug.LogWarning("文件ID:" + id);
                            Debug.Log("返回" + path);
                            Debug.LogWarning("地址:" + filePath_1);
                            byte[] bId = HexStringToByteArray(id);
                            SendVoiceMessage(filePath_1, Convert.ToInt16(fVoiceTime), bId);
                        }
                        else
                        {
                            StartCoroutine(ListWork(fVoiceTime));
                        }
                    };
                    //停止出错
                    Err1 : ErroOccur(err, () => { StartCoroutine(ListWork(fVoiceTime)); });
                }
                else
                {
                    YunVaImSDK.instance.RecordStopRequest(
                        (data1) =>
                    {
                        Debug.LogWarning("按钮松开6");
                        Debug.LogWarning(data1.strfilepath);
                        filePath_1 = data1.strfilepath;
                        StartCoroutine(ListWork(fVoiceTime));
                    },
                        (data2) =>//这里处理录音上传,上传录音网址告诉服务器
                    {
                        Debug.LogWarning("上传Result:" + data2.result);
                        if (data2.fileurl.Length <= 25)
                        {
                            Debug.LogWarning("上传语音失败,重新上传");
                            HandleUpLoadVoiceErr += UpLoadVoice;
                            HandleUpLoadVoiceErr(Convert.ToInt16(fVoiceTime));
                            return;
                        }
                        //发送语音请求
                        SendVoiceMessage(data2.fileurl, Convert.ToInt16(fVoiceTime), null);
                    },
                        (data3) =>
                    {
                        Debug.Log("识别返回:" + data3.text);
                    });
                }
            }
            catch (Exception)
            {
                Debug.LogError("上传有异常");
                throw;
            }
            //录音状态改编为非录音状态
        }