using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Text;
|
using UnityEngine;
|
|
[XLua.LuaCallCSharp]
|
public class VoiceHttpRequest : SingletonMonobehaviour<VoiceHttpRequest>
|
|
{
|
const string uploadUrl = "http://{0}.voice.2460web.com:53001/voice/upload";
|
const string downloadUrl = "http://{0}.voice.2460web.com:53001/voice/download";
|
|
|
public Queue<VoiceHttp> speechs = new Queue<VoiceHttp>();
|
public Queue<VoiceDecodec> decodecSamples = new Queue<VoiceDecodec>();
|
|
public event Action<VoiceDecodec> samplesDecodecComplete;
|
|
private bool onceSuccessRemind = false;
|
|
private void Awake()
|
{
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
StageLoad.Instance.onStageLoadFinish += OnStageLoadFinish;
|
}
|
|
private void OnStageLoadFinish()
|
{
|
if (StageLoad.Instance.currentStage is LoginStage)
|
{
|
speechs.Clear();
|
}
|
}
|
|
private void OnBeforePlayerDataInitialize()
|
{
|
speechs.Clear();
|
}
|
|
public void Enqueue(byte[] _encode, long _tick, int _playerId)
|
{
|
speechs.Enqueue(new VoiceHttp()
|
{
|
encode = _encode,
|
tick = _tick,
|
playerId = _playerId
|
});
|
onceSuccessRemind = false;
|
}
|
|
private void LateUpdate()
|
{
|
if (speechs.Count > 0)
|
{
|
if (!onceSuccessRemind)
|
{
|
SysNotifyMgr.Instance.ShowTip("VoiceSendSuccess");
|
onceSuccessRemind = true;
|
}
|
var _data = speechs.Dequeue();
|
|
var content = Convert.ToBase64String(_data.encode);
|
content = content.Replace("+", "%2B");
|
|
Dictionary<string, string> dict = new Dictionary<string, string>();
|
dict.Add("voiceID", _data.tick.ToString());
|
dict.Add("playerID", _data.playerId.ToString());
|
dict.Add("appid", VersionConfig.Get().appId);
|
dict.Add("content", content);
|
var url = string.Format(uploadUrl, VersionConfig.Get().appId);
|
HttpRequest.Instance.RequestHttpPost(url, dict, HttpRequest.defaultHttpContentType);
|
}
|
if (decodecSamples.Count > 0)
|
{
|
samplesDecodecComplete(decodecSamples.Dequeue());
|
}
|
}
|
|
public void Enqueue(float[] _samples, long _tick, int _playerId)
|
{
|
decodecSamples.Enqueue(new VoiceDecodec()
|
{
|
tick = _tick,
|
samples = _samples,
|
playerId = _playerId,
|
});
|
}
|
|
public struct VoiceHttp
|
{
|
public byte[] encode;
|
public long tick;
|
public int playerId;
|
}
|
|
public struct VoiceDecodec
|
{
|
public long tick;
|
public int playerId;
|
public float[] samples;
|
}
|
}
|