Beispiel #1
0
 public void EnableLog_Click()
 {
     Debug.Log("EnableLog_Click");
     s_bEnableLog = !s_bEnableLog;
     s_logstr    += "\r\nlogenable:" + s_bEnableLog;
     m_voiceengine.EnableLog(s_bEnableLog);
 }
Beispiel #2
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();
        }