public bool JoinAnchorRoom() { if (VoiceState.Inited != State) { Debug.Log("Error:GVoiceManager.JoinAnchorRoom VoiceState.Inited = " + State); if (IsInRoom) { EventDispatcher.Instance.DispatchEvent(new ShowUIHintBoard(GameUtils.GetDictionaryText(301040))); } return(false); } bool canSpeek = false; if (IsAnchor) { canSpeek = true; NetManager.Instance.StartCoroutine(AnchorEnterRoom()); } Debug.Log("GVoiceManager.JoinAnchorRoom roomName=" + AnchorRoom + " isAnchor=" + canSpeek); m_voiceengine.SetMode(GCloudVoiceMode.RealTime); if ((int)GCloudVoiceErr.GCLOUD_VOICE_SUCC != m_voiceengine.JoinNationalRoom(AnchorRoom, canSpeek ? GCloudVoiceRole.ANCHOR : GCloudVoiceRole.AUDIENCE, TimeOutMillSeconds)) { return(false); } State = VoiceState.JoiningRoom; mRoomType = RoomType.Anchor; return(true); }
private void Start() { voiceTrans = transform.Find("/Game_UI/Fixed_UI/Voices/"); micToggle = voiceTrans.transform.Find("Mic").GetComponent <Toggle>(); speakerToggle = voiceTrans.transform.Find("horn").GetComponent <Toggle>(); txt = voiceTrans.transform.Find("Text").GetComponent <Text>(); m_roomName = GameInfo.room_id + ""; if (m_voiceengine == null) { txt.text += "开始"; m_voiceengine = GCloudVoice.GetEngine(); txt.text += "调用了,设置openid"; m_voiceengine.SetAppInfo("1981614680", "829b1c3747cd948f6dad1e9b151692ef", GameInfo.OpenID); txt.text += "设置openID了,开始init"; m_voiceengine.Init(); txt.text += "init结束,设置实时语音"; m_voiceengine.SetMode(GCloudVoiceMode.RealTime); txt.text += "设置实时语音"; } micToggle.onValueChanged.AddListener( delegate(bool isOn) { OnMicToggleClick(isOn); } ); speakerToggle.onValueChanged.AddListener(delegate(bool isOn) { OnSpeakerToggleClick(isOn); }); JoinRoomBtn_Click(); }
private void button1_Click(object sender, EventArgs e) { m_voiceengine.SetMode(GCloudVoiceMode.RealTime); int ret = m_voiceengine.JoinTeamRoom("100001", 15000); Console.WriteLine("Hello,world!"); }
/// <summary> /// 加入房间,BtnJoin按钮点击调用 /// </summary> public void JoinRoom() { m_voiceengine.SetMode(GCloudVoiceMode.RealTime); int ret = m_voiceengine.JoinTeamRoom(roomName, 15000); result.text += "\nJoinRoom:" + ret; }
//初始化Team public int InitTeam(string gameId, string gameKey, string openId, int msTimeout, int type = 0) { mVoiceengine = GCloudVoice.GetEngine(); mVoiceengine.SetAppInfo(gameId, gameKey, openId); int initResult = mVoiceengine.Init(); mVoiceengine.ApplyMessageKey(msTimeout); mVoiceengine.SetMode((GCloudVoiceMode)type); return(initResult); }
public void SetModel(GCloudVoiceMode model, bool bforce = false) { if (m_voiceengine != null && (m_GCloudVoiceMode != model || bforce)) { int ret = m_voiceengine.SetMode(model); Debug.LogError("GVoiceManger -- SetMode " + model + " ret :" + ret); if (ret == 0) { m_GCloudVoiceMode = model; } } }
//初始化语音 public void Init(string gameId, string gameKey, string openId, int msTimeout) { if (mVoiceengine == null) { mVoiceengine = GCloudVoice.GetEngine(); } mVoiceengine.SetAppInfo(gameId, gameKey, openId); mVoiceengine.Init(); mVoiceengine.ApplyMessageKey(msTimeout); mVoiceengine.SetMode(GCloudVoiceMode.Messages); int ret1 = mVoiceengine.SetMaxMessageLength(60000); Debug.Log("SetMaxMessageLength ret==" + ret1); }
/// <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; } }
public override void Init() { if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { return; } m_voiceengine = GCloudVoice.GetEngine(); m_voiceengine.OnApplyMessageKeyComplete += onApplyMessageKeyComplete; m_voiceengine.OnUploadReccordFileComplete += onUploadReccordFileComplete; m_voiceengine.OnDownloadRecordFileComplete += onDownloadReccordFileComplete; m_voiceengine.OnPlayRecordFilComplete += onPlayRecordFilComplete; System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0); string strTime = System.Convert.ToInt64(ts.TotalSeconds).ToString(); m_voiceengine.SetAppInfo("932849489", "d94749efe9fce61333121de84123ef9b", strTime); m_voiceengine.Init(); m_voiceengine.SetMode(GCloudVoiceMode.Messages); base.Init(); }
public void RealTimeBtn_Click() { //Debug.Log ("realtime button click"); m_voiceengine.SetMode(GCloudVoiceMode.RealTime); Application.LoadLevel("RealTimeVoice"); }
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"; }
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(); }