Exemplo n.º 1
0
    /// <summary>
    /// 播放语音
    /// </summary>
    /// <param name="audioName">语音路径</param>

    /*public static void PlayAudio(string audioName)
     * {
     *  if (!m_bInited)
     *      m_Instance.Init();
     *  if (m_Status == SpeechStatus.SS_DEFAULT)
     *  {
     *      m_Status = SpeechStatus.SS_PLAYING;
     *      SpeechAPI.PlayAudio(audioName);
     *      if (ChatInfoLogic.Instance() != null)
     *      {
     *          ChatInfoLogic.Instance().OnPlayVoiceChat();
     *      }
     *  }
     * }
     *
     * /// <summary>
     * /// 播放buffer内的语音
     * /// </summary>
     * /// <param name="audioIdx"></param>
     * public static void PlayAudio(byte[] buffer)
     * {
     *  if (!m_bInited)
     *      m_Instance.Init();
     *
     *  if (m_Status == SpeechStatus.SS_DEFAULT && buffer != null)
     *  {
     *      m_Status = SpeechStatus.SS_PLAYING;
     *      SpeechAPI.PlayAudioBuffer(buffer);
     *      if (ChatInfoLogic.Instance() != null)
     *      {
     *          ChatInfoLogic.Instance().OnPlayVoiceChat();
     *      }
     *  }
     * }*/

    public static void PlayAudio(int voiceindex, byte[] buffer, bool bForce = false)
    {
        if (!m_bInited)
        {
            m_Instance.Init();
        }

        if (buffer != null)
        {
            if (m_Status == SpeechStatus.SS_DEFAULT || bForce)
            {
                m_Status = SpeechStatus.SS_PLAYING;
                GameManager.gameManager.SoundManager.MusicDown();
                SpeechAPI.PlayAudioBuffer(buffer);
                GameManager.gameManager.PlayerDataPool.VoiceChatDownloadRecord.PlayingVoiceIndex = voiceindex;
                if (ChatInfoLogic.Instance() != null)
                {
                    ChatInfoLogic.Instance().OnPlayVoiceChat();
                }
#if UNITY_ANDROID && !UNITY_EDITOR
                SpeechEngine.Instance().InvokeRepeating("ForcePlayOver", 20.0f, 1.0f);
#endif
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 停止录音
    /// </summary>
    public static void StopRecording()
    {
        if (!m_bInited)
        {
            m_Instance.Init();
        }
        if (m_Status == SpeechStatus.SS_STARTED || m_Status == SpeechStatus.SS_READY || m_Status == SpeechStatus.SS_LISTENING)
        {
            SpeechAPI.StopRecording();
#if UNITY_ANDROID && !UNITY_EDITOR
            SpeechEngine.Instance().InvokeRepeating("StatusRecover", 11.0f, 1.0f);
#endif
        }
    }
Exemplo n.º 3
0
    //private List<SpeechUnit> m_AudioBuffers = new List<SpeechUnit>();

    // Use this for initialization
    void Start()
    {
        if (SpeechEngine.Instance() != null)
        {
            SpeechEngine.Instance().SetTextProcessHandler(ReceiveSpeechText);
            SpeechEngine.Instance().SetErrorProcessHandler(ReceiveErrorCode);
            SpeechEngine.Instance().SetRecordBeginHandler(DoRecordBegin);
            SpeechEngine.Instance().SetRecordEndHandler(DoRecordEnd);
            SpeechEngine.Instance().SetTaskCancleHandler(DoTaskCancle);
            SpeechEngine.Instance().SetTaskOverHandler(DoTaskOver);
            SpeechEngine.Instance().SetTaskStartHandler(DoTaskStart);
            SpeechEngine.Instance().SetAudioPlayOverHandler(PlayRecordOver);
        }
    }