示例#1
0
文件: Chat.cs 项目: isoundy000/shmj3d
    void playVoice()
    {
        VoiceMgr vmr = VoiceMgr.GetInstance();
        RoomMgr  rm  = RoomMgr.GetInstance();

        if (_playingSeat < 0 && mVoiceQueue.Count > 0)
        {
            ChatItem vm    = mVoiceQueue.Dequeue();
            string   msg   = vm.voice.msg;
            string   file  = vm.path;
            int      si    = rm.getSeatIndexByID(vm.sender);
            int      local = rm.getLocalIndex(si);
            _playingSeat = local;

            vmr.writeVoice(file, msg);
            vmr.play(file);

            if (playing != null)
            {
                playing.SetActive(false);
                playing = null;
            }

            playing = vm.vobj;
            if (playing != null)
            {
                playing.SetActive(true);
            }

            _lastPlayTime = PUtils.getMilliSeconds() + vm.voice.time;
        }
    }
示例#2
0
    void _play_voice_pos(Vector3 pos)
    {
        EventMgr.startEvent("显示关闭按钮");

        pos = Camera.main.transform.TransformPoint(pos);
        VoiceMgr.PlayVoice("f0", pos);
        // SoundMgr.PlaySound("f0", pos);
    }
 void OnSpeakerCompleted(string text)
 {
     Debug.LogWarning("[Iflytek] OnSpeakerCompleted: " + text);
     if (VoiceMgr.isListening == false)
     {
         int code = VoiceMgr.Start();
         Debug.LogWarning("[Iflytek] Start Listening");
     }
 }
示例#4
0
    public static VoiceMgr GetInstance()
    {
        if (mInstance == null)
        {
            mInstance = new VoiceMgr();
        }

        return(mInstance);
    }
示例#5
0
    public void onPress()
    {
        bar.width   = 0;
        notice.text = "请按住说话";
        voice.SetActive(true);
        lastTouchTime = PUtils.getMilliSeconds();

        Debug.Log("onPress");

        VoiceMgr.GetInstance().prepare("record.amr");
    }
    // Use this for initialization
    void Start()
    {
        // 全局单例来维护
        VoiceMgr.Init();
        VoiceMgr.SetCallback(OnResult);
        VoiceMgr.SetSpeakerErrorCallback(OnSpeechError);
        VoiceMgr.SetFlyJsonCallback(OnFlyJsonResult);
        VoiceMgr.SetSpeakerCallback(OnSpeakerCompleted);
        //VoiceMgr.SetOnVolumeCallback (OnMicroPhoneVolumeChanged);

        VoiceMgr.SetParameter("engine_type", "cloud");
        VoiceMgr.SetParameter("audio_format", "pcm");
    }
示例#7
0
文件: Chat.cs 项目: isoundy000/shmj3d
    void playVoiceItem(ChatItem item)
    {
        _playingSeat  = -1;
        _lastPlayTime = 0;
        mVoiceQueue.Clear();

        VoiceMgr vm = VoiceMgr.GetInstance();

        vm.stop();

        mVoiceQueue.Enqueue(item);
        playVoice();
    }
    // Speech recognizer returns error, here we need to make sure everything works fine
    void OnSpeechError(string code)
    {
        Debug.LogWarning("[Iflytek] OnSpeechError: " + code);

        if (code == "10118")
        {
            // no input, if still focused, then restart listening, if not focused
            // restart listening
            if (VoiceMgr.isListening == false)
            {
                VoiceMgr.Start();
            }
        }
    }
示例#9
0
    void Awake()
    {
        PUtils ut = PUtils.GetInstance();

        Loom lm = Loom.Current;

        mNetMgr = NetMgr.GetInstance();
        mNetMgr.Init();

        mGameMgr = GameMgr.GetInstance();
        mGameMgr.Init();

        mRoomMgr = RoomMgr.GetInstance();
        mRoomMgr.Init();

        mVoiceMgr = VoiceMgr.GetInstance();
        mVoiceMgr.Init();

        mReplayMgr = ReplayMgr.GetInstance();
        mReplayMgr.Init();
    }
示例#10
0
    public void onRelease()
    {
        if (lastTouchTime == 0)
        {
            return;
        }

        if (PUtils.getMilliSeconds() - lastTouchTime < 1000)
        {
            VoiceMgr.GetInstance().cancel();
            voice.SetActive(true);
            bar.width   = 0;
            notice.text = "录制时间太短";
            voice.SetActive(false);
        }
        else
        {
            onVoiceOK();
        }

        lastTouchTime = 0;
    }
示例#11
0
    void onVoiceOK()
    {
        VoiceMgr vm = VoiceMgr.GetInstance();

        if (lastTouchTime > 0)
        {
            vm.release();

            long   t   = (long)((Time.time - lastTouchTime) * 1000);
            string msg = vm.getVoiceData("record.amr");

            if (msg != null && msg.Length > 0)
            {
                JsonObject ob = new JsonObject();
                ob ["msg"]  = msg;
                ob ["time"] = t;

                NetMgr.GetInstance().send("voice_msg", ob);
            }
        }

        voice.SetActive(false);
    }
示例#12
0
 // Start is called before the first frame update
 void Start()
 {
     instance = this;
 }
示例#13
0
    void enter(TOUCH_STATE state)
    {
        VoiceMgr vm = VoiceMgr.GetInstance();

        Debug.Log("enter " + state);

        switch (state)
        {
        case TOUCH_STATE.START:
            vm.prepare("record.amr");
            lastTouchTime = Time.time;

            voice.SetActive(true);
            mic.SetActive(true);
            volume.SetActive(true);
            cancel.SetActive(false);
            warning.SetActive(false);

            time.transform.localScale = new Vector2(0, 1);
            notice.text = "滑动手指,取消发送";
            break;

        case TOUCH_STATE.MOVE_OUT:
            if (lastTouchTime > 0)
            {
                mic.SetActive(false);
                volume.SetActive(false);
                cancel.SetActive(true);
                warning.SetActive(false);

                notice.text = "松开手指,取消发送";
            }

            break;

        case TOUCH_STATE.MOVE_IN:
            if (lastTouchTime > 0)
            {
                mic.SetActive(true);
                volume.SetActive(true);
                cancel.SetActive(false);
                warning.SetActive(false);

                notice.text = "滑动手指,取消发送";
            }

            break;

        case TOUCH_STATE.CANCEL:
            if (lastTouchTime > 0)
            {
                vm.cancel();
                lastTouchTime = 0;
                voice.SetActive(false);
            }

            break;

        case TOUCH_STATE.END:
            if (lastTouchTime > 0)
            {
                if (Time.time - lastTouchTime < 1.0f)
                {
                    vm.cancel();

                    voice.SetActive(true);
                    mic.SetActive(false);
                    volume.SetActive(false);
                    cancel.SetActive(false);
                    warning.SetActive(true);
                    time.transform.localScale = new Vector2(0, 1);
                    notice.text = "录制时间太短";

                    PUtils.setTimeout(() => {
                        voice.SetActive(false);
                    }, 1.0f);
                }
                else
                {
                    onVoiceOK();
                }

                lastTouchTime = 0;
            }

            break;

        default:
            break;
        }
    }
示例#14
0
    void Update()
    {
        VoiceMgr vm  = VoiceMgr.GetInstance();
        float    now = Time.time;

        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                GameObject ob = hit.collider.gameObject;

                if (ob.Equals(button))
                {
                    enter(TOUCH_STATE.START);
                    inButton = true;
                    draging  = true;
                }
            }
        }

        if (draging)
        {
            bool       found = false;
            Ray        ray   = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                GameObject ob = hit.collider.gameObject;

                if (ob.Equals(button))
                {
                    found = true;
                }
            }

            if (Input.GetMouseButtonUp(0))
            {
                enter(found ? TOUCH_STATE.END : TOUCH_STATE.CANCEL);

                draging = false;
            }
            else if (draging)
            {
                if (found != inButton)
                {
                    enter(found ? TOUCH_STATE.MOVE_IN : TOUCH_STATE.MOVE_OUT);

                    inButton = found;
                }
            }
        }

        if (voice.activeSelf && volume.activeSelf)
        {
            if (now - lastCheckTime > 0.3f)
            {
                int v = vm.getVoiceLevel(5);

                for (int i = 0; i < volumes.Length; i++)
                {
                    volumes [i].SetActive(v > i);
                }

                lastCheckTime = now;
            }
        }

        if (lastTouchTime > 0)
        {
            long t = (long)((Time.time - lastTouchTime) * 1000);

            if (t >= MAXTIME)
            {
                onVoiceOK();
                lastTouchTime = 0;
            }
            else
            {
                time.transform.localScale = new Vector2((float)t / MAXTIME, 1);
            }
        }
    }
示例#15
0
 public static VoiceMgr GetInstance()
 {
     if (instance == null)
         instance = new VoiceMgr();
     return instance;
 }
示例#16
0
 public override void start()
 {
     VoiceMgr.PlayVoice(audioFile, Vector3.zero);
     isEnd = true;
 }
示例#17
0
	public void Init()
	{
		instance = null;
	}
 public void f**k()
 {
     Debug.Log("Button Clicked. TestClick.");
     VoiceMgr.SpeakText("我草拟马币");
 }