Ejemplo n.º 1
0
 public void InitGVoice(string appID, string appKey, string openID, string udpUrl)
 {
     if (m_voiceengine == null)
     {
         m_voiceengine = GCloudVoice.GetEngine();
         m_voiceengine.SetAppInfo(appID, appKey, openID);
         m_voiceengine.SetServerInfo(udpUrl);
         m_voiceengine.Init();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 录音初始化
        /// </summary>
        public void VoiceInit()
        {
            int a = 0;

            if (VoiceFlag == 1)
            {
                voiceInitCount++;
                a = m_voiceengine.SetAppInfo(MahjongLobby_AH.LobbyContants.GvoiceAPP_ID,
                                             MahjongLobby_AH.LobbyContants.GvoiceAPP_Key,
                                             GameData.Instance.PlayerNodeDef.iUserId.ToString());
                if (a != 0)
                {
                    goto Err3;
                }
                a = m_voiceengine.SetServerInfo("udp://cn.voice.gcloudcs.com:10001");
                if (a != 0)
                {
                    goto Err3;
                }
                a = m_voiceengine.Init();
                if (0 != a)
                {
                    goto Err3;
                }
                ///设置模式
                a = m_voiceengine.SetMode(GCloudVoiceMode.Messages);
                if (0 != a)
                {
                    goto Err3;
                }
                ApplyKey();
                Err3 : ErroOccur(a, () => { VoiceInit(); });
            }
            else
            {
                IEVoiceInit();
            }
            if (voiceInitCount >= 4)
            {
                MahjongCommonMethod.Instance.ShowRemindFrame("错误:" + a + "请检查你的网络设置");
                voiceInitCount = 0;
            }
        }
Ejemplo n.º 3
0
    void Awake()
    {
        if (m_voiceengine == null && Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
        {
            m_voiceengine = GCloudVoice.GetEngine();
            System.TimeSpan ts      = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            string          strTime = System.Convert.ToInt64(ts.TotalSeconds).ToString();
            //m_voiceengine.SetAppInfo("932849489","d94749efe9fce61333121de84123ef9b",strTime);
            var info = m_voiceengine.SetAppInfo("1753605946", "445aec6d7d557ace513bc45ec3adc77e", strTime);
            m_voiceengine.SetServerInfo("udp://cn.voice.gcloudcs.com:10001");

            m_voiceengine.Init();
            m_voiceengine.SetMode(GCloudVoiceMode.Messages);
            m_voiceengine.OnApplyMessageKeyComplete += (IGCloudVoice.GCloudVoiceCompleteCode code) =>
            {
                PlayLog("OnApplyMessageKeyComplete c# callback");
                if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_MESSAGE_KEY_APPLIED_SUCC)
                {
                    PlayLog("OnApplyMessageKeyComplete succ11");
                }
                else
                {
                    PlayLog("OnApplyMessageKeyComplete error");
                }
            };
            m_voiceengine.OnUploadReccordFileComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath, string fileid) =>
            {
                PlayLog("OnUploadReccordFileComplete c# callback");
                if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_UPLOAD_RECORD_DONE)
                {
                    m_fileid = fileid;
                    if (upLoadScuccessCall != null)
                    {
                        upLoadScuccessCall(m_fileid);
                    }
                    //UserTalk talk = new UserTalk();
                    //talk.type = 2;
                    //talk.msg = m_fileid;
                    //talk.subtype = 1;
                    //SocketClient.Instance.AddSendMessageQueue(new C2GMessage
                    //{
                    //    msgid = MessageId.C2G_UserTalk,
                    //    UserTalk = talk

                    //});
                    PlayLog("发送语音消息");
                    PlayLog("OnUploadReccordFileComplete succ, filepath:" + filepath + " fileid len=" + fileid.Length + " fileid:" + fileid + " fileid len=" + fileid.Length);
                }
                else
                {
                    PlayLog("OnUploadReccordFileComplete error");
                }
            };
            m_voiceengine.OnDownloadRecordFileComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath, string fileid) =>
            {
                PlayLog("OnDownloadRecordFileComplete c# callback");
                if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_DOWNLOAD_RECORD_DONE)
                {
                    PlayLog("OnDownloadRecordFileComplete succ, filepath:" + filepath + " fileid:" + fileid);
                    if (downCall != null)
                    {
                        downCall();
                        downCall = null;
                    }
                    Click_btnPlayReocrdFile();
                }
                else
                {
                    PlayLog("OnDownloadRecordFileComplete error");
                }
            };
            m_voiceengine.OnPlayRecordFilComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath) =>
            {
                PlayLog("OnPlayRecordFilComplete c# callback");
                if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_PLAYFILE_DONE)
                {
                    PlayLog("OnPlayRecordFilComplete succ, filepath:" + filepath);
                    if (playCall != null)
                    {
                        playCall();
                        playCall = null;
                    }
                }
                else
                {
                    PlayLog("OnPlayRecordFilComplete error");
                }
            };
        }
        m_recordpath   = Application.persistentDataPath + "/" + "recording.dat";
        m_downloadpath = Application.persistentDataPath + "/" + "download.dat";
    }
Ejemplo n.º 4
0
        public void Init()
        {
            if (!mIsStart)
            {
                mIsStart = true;

                try
                {
                    mVoiceEngine = GCloudVoice.GetEngine();
                }
                catch (Exception e)
                {
                    GameDebug.Log(e.Message);
                    return;
                }

                System.TimeSpan ts      = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                string          strTime = System.Convert.ToInt64(ts.TotalSeconds).ToString();
#if !TEST_HOST && !CMPT_RELEASE
                if (Const.Region == RegionType.CHINA)
                {
                    mVoiceEngine.SetAppInfo("1075242022", "b24dbcfef34b73475b81f47df5edc172", strTime);
                    mVoiceEngine.SetServerInfo("udp://cn.voice.gcloudcs.com:10001");
                }
                else if (Const.Region == RegionType.HKTW)
                {
                    mVoiceEngine.SetAppInfo("1529889908", "f4655f1fb599ef6b9ac2fe52e49c9ef2", strTime);
                    mVoiceEngine.SetServerInfo("udp://hk.voice.gcloudcs.com:10013");
                }
                else if (Const.Region == RegionType.KOREA)
                {
                    mVoiceEngine.SetAppInfo("1614396342", "3fc91371164d69fdb3c9bfc911aec845", strTime);
                    mVoiceEngine.SetServerInfo("udp://kr.voice.gcloudcs.com:8700");
                }
                else if (Const.Region == RegionType.SEASIA)
                {
                    mVoiceEngine.SetAppInfo("1338975937", "e293bba813c9d4782b67695da54c75af", strTime);
                    mVoiceEngine.SetServerInfo("udp://sg.voice.gcloudcs.com:8700");
                }
#else
                mVoiceEngine.SetAppInfo("gcloud.test", "test_key", strTime);
#endif
                mVoiceEngine.Init();
                int setModedRet = mVoiceEngine.SetMode(GCloudVoiceMode.Translation);
                GameDebug.Log("setModedRet =" + setModedRet);
                mVoiceEngine.EnableLog(true);
                mVoiceEngine.OnApplyMessageKeyComplete += (IGCloudVoice.GCloudVoiceCompleteCode code) =>
                {
                    //Debug.LogError("OnApplyMessageKeyComplete c# callback code = " + code);
                    if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_MESSAGE_KEY_APPLIED_SUCC)
                    {
                        //GameDebug.Log("OnApplyMessageKeyComplete succ");
                    }
                    else
                    {
                        //GameDebug.Log("OnApplyMessageKeyComplete error");
                        VoiceManager.Instance.ReqAuthKey();
                    }
                };
                mVoiceEngine.OnUploadReccordFileComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath, string fileid) =>
                {
                    //Debug.LogError("OnUploadReccordFileComplete c# callback");
                    if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_UPLOAD_RECORD_DONE)
                    {
                        //Debug.LogError("OnUploadReccordFileComplete succ, filepath:" + filepath + " fileid len=" + fileid.Length + " fileid:" + fileid + " fileid len=" + fileid.Length);

                        FileInfo file_info = new FileInfo(filepath);
                        var      path      = GenFilePathByFileId(fileid);
                        if (!File.Exists(path))
                        {
                            file_info.CopyTo(path);
                        }

                        mUploadReccordFileId = fileid;
                        if (Const.Region == RegionType.CHINA)
                        {
                            VoiceManager.Instance.SpeechToText(fileid);
                        }
                        else
                        {
                            uint second = VoiceManager.Instance.GetRecFileSecond(fileid);
                            ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_GVOICE_SPEECH_TO_TEXT_COMPLETE, new CEventGVoiceArgs(fileid, "", second));
                            IsUnloading = false;
                        }
                    }
                    else
                    {
                        IsUnloading = false;
                        Debug.LogError("OnUploadReccordFileComplete error");
                    }
                };
                mVoiceEngine.OnDownloadRecordFileComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath, string fileid) =>
                {
                    //Debug.LogError("OnDownloadRecordFileComplete c# callback");
                    if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_DOWNLOAD_RECORD_DONE)
                    {
                        //Debug.LogError("OnDownloadRecordFileComplete succ, filepath:" + filepath + " fileid:" + fileid);

                        FileInfo file_info = new FileInfo(filepath);
                        var      path      = GenFilePathByFileId(fileid);
                        if (!File.Exists(path))
                        {
                            file_info.CopyTo(path);
                        }

                        OnlyPlayRecordFile(fileid);
                    }
                    else
                    {
                        Debug.LogError("OnDownloadRecordFileComplete error");
                    }
                };
                mVoiceEngine.OnPlayRecordFilComplete += (IGCloudVoice.GCloudVoiceCompleteCode code, string filepath) =>
                {
                    //Debug.LogError("OnPlayRecordFilComplete c# callback");
                    string file_id;
                    if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_PLAYFILE_DONE && VoiceManager.Instance.FilePathToFileId.TryGetValue(filepath, out file_id))
                    {
                    }
                    else
                    {
                        Debug.LogError("OnPlayRecordFilComplete error");
                    }

                    if (mPlayingFileQueue.Count > 0)
                    {
                        ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_GVOICE_RECORD_PLAY_DONE, new CEventGVoiceArgs(mPlayingFileQueue[0], "", 0));
                        mPlayingFileQueue.RemoveAt(0);
                    }

                    if (mPlayingFileQueue.Count == 0) // 最后一个播放完毕才重新播放背景音乐
                    {
                        AudioManager.Instance.SetMusicVolume(GlobalSettings.Instance.MusicVolume);
                        AudioManager.Instance.SetSFXVolume(GlobalSettings.Instance.SFXVolume);
                    }
                    else
                    {
                        PlayOrDownload(mPlayingFileQueue[0]);
                    }
                };
                mVoiceEngine.OnSpeechToText += (IGCloudVoice.GCloudVoiceCompleteCode code, string fileID, string result) =>
                {
                    //Debug.LogError("OnSpeechToText c# callback");
                    if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_STT_SUCC)
                    {
                        //Debug.LogError("OnSpeechToText succ, result:" + result);
                        uint second = VoiceManager.Instance.GetRecFileSecond(fileID);
                        ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_GVOICE_SPEECH_TO_TEXT_COMPLETE, new CEventGVoiceArgs(fileID, result, second));
                    }
                    else if (code == IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_STT_TIMEOUT)
                    {
                        Debug.LogError("OnSpeechToText error," + code);

                        if (mUploadReccordFileId.Length > 0)
                        {
                            uint second = VoiceManager.Instance.GetRecFileSecond(mUploadReccordFileId);
                            ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_GVOICE_SPEECH_TO_TEXT_COMPLETE, new CEventGVoiceArgs(mUploadReccordFileId, result, second));
                        }
                    }
                    else
                    {
                        Debug.LogError("OnSpeechToText error," + code);

                        Init();//重现初始化,尝试清除上一次翻译失败
                    }
                    IsUnloading = false;
                };
                if (Directory.Exists(mSaveDir))
                {
                    Directory.Delete(mSaveDir, true);
                }

                Directory.CreateDirectory(mSaveDir);

                mRecordPath   = mSaveDir + "/recording.dat";
                mDownloadPath = mSaveDir + "/download.dat";
            }

            IsUnloading          = false;
            IsCanSendByGameLogic = false;
            mStartUploadingTime  = 0;
            mUploadReccordFileId = "";
            mPlayingFileQueue.Clear();

            VoiceManager.Instance.ReqAuthKey();
        }