Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (dictationRecogniser != null &&
            this.Status == SpeechStatus.Speeking &&
            dictationRecogniser.Status == SpeechSystemStatus.Running)
        {
            float time = Time.time;
            if (time > lastWordSaid + silenceTreshold)
            {
                if (this.Status != SpeechStatus.Silence)
                {
                    this.Status = SpeechStatus.Silence;
                    this.Statistics.BreaksCount++;
                }
            }
        }

        if (dictationRecogniser != null &&
            (this.Status == SpeechStatus.Speeking || this.Status == SpeechStatus.Silence) &&
            dictationRecogniser.Status == SpeechSystemStatus.Stopped)
        {
            Status = SpeechStatus.Stopped;

            if (AllowRestartAttempt)
            {
                Debug.Log("Dictation restart attempt ...");
                dictationRecogniser.Start();
                Status = SpeechStatus.Speeking;
            }
        }
    }
Пример #2
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
            }
        }
    }
Пример #3
0
 /// <summary>
 /// 错误回调函数
 /// </summary>
 /// <param name="errorCode">错误代码</param>
 private void ProcessErrorCode(string errorCode)
 {
     if (/*!errorCode.Equals("0") && */ m_ErrorHandler != null)
     {
         m_ErrorHandler(SpeechAPI.GetErrorCodeDesc(errorCode));
     }
     m_Status = SpeechStatus.SS_DEFAULT;
 }
Пример #4
0
        /// <summary>
        /// Sends the speech status to the engine service user when Stt engine notifies the change of the speech status.
        /// </summary>
        /// <feature>
        /// http://tizen.org/feature/speech.recognition
        /// http://tizen.org/feature/microphone
        /// </feature>
        /// <remarks>
        /// This API is invoked when Stt engine wants to notify the change of the speech status anytime. NOTE that this API can be invoked for recognizing the speech.
        /// </remarks>
        /// <param name="status">SpeechStatus</param>
        /// <exception cref="UnauthorizedAccessException">Thrown in case of Permission denied</exception>
        /// <exception cref="NotSupportedException">Thrown in case of Not supported</exception>
        /// <exception cref="InvalidOperationException">thrown in case of Operation failure</exception>
        /// <precondition>
        /// Main function should be invoked before this function is called. Start() and SetRecordingData() will invoke this function.
        /// </precondition>
        /// <since_tizen> 4 </since_tizen>
        public void SendSpeechStatus(SpeechStatus status)
        {
            Error error = STTESendSpeechStatus(status, IntPtr.Zero);

            if (error != Error.None)
            {
                Log.Error(LogTag, "SendSpeechStatus Failed with error " + error);
                throw ExceptionFactory.CreateException((ErrorCode)error);
            }
        }
Пример #5
0
        public Speech(Sentence[] _sentence, AnswerCondition[] _conditions)
        {
            sentences    = _sentence;
            condition    = _conditions;
            types        = new SentenceType[0];
            requirements = new AnswerRequirements[0];

            status = SpeechStatus.Waiting;
            index  = 0;
        }
Пример #6
0
        public Speech(Sentence[] _sentences, SentenceType[] _types, AnswerRequirements[] _requirements, AnswerCondition[] _condition)
        {
            sentences    = _sentences;
            types        = _types;
            requirements = _requirements;
            condition    = _condition;

            status = SpeechStatus.Waiting;
            index  = 0;
        }
Пример #7
0
    public void StartSpeech()
    {
        dictationRecogniser.Start();
        Statistics = new SpeechStatistics {
            StartTime = Time.time
        };
        Status = SpeechStatus.Speeking;

        lastWordSaid = Time.time;
    }
Пример #8
0
 void Awake()
 {
     if (null != m_Instance)
     {
         Destroy(this.gameObject);
     }
     m_Instance = this;
     m_Status   = SpeechStatus.SS_DEFAULT;
     m_Instance.Init();
     DontDestroyOnLoad(this.gameObject);
 }
Пример #9
0
        public Sentence Read()
        {
            Sentence result = new Sentence();

            result = sentences[index];
            index++;

            if (index == sentences.Length)
            {
                status = SpeechStatus.Said;
                index  = 0;
            }

            return(result);
        }
Пример #10
0
 internal static extern Error STTESendSpeechStatus(SpeechStatus status, IntPtr userData);
Пример #11
0
    /// <summary>
    /// 事件处理回调
    /// </summary>
    /// <param name="evt">事件类型</param>
    private void ProcessEvent(SpeechEventType evt)
    {
        switch (evt)
        {
        case SpeechEventType.SET_CANCLE:
            if (m_Status != SpeechStatus.SS_DEFAULT)
            {
                m_Status = SpeechStatus.SS_CANCELING;
                OnTaskCancle();
            }
            break;

        case SpeechEventType.SET_SPEECH_BEGIN:
            if (m_Status == SpeechStatus.SS_STARTED || m_Status == SpeechStatus.SS_READY)
            {
                m_Status = SpeechStatus.SS_LISTENING;
                OnRecordBegin();
            }
            break;

        case SpeechEventType.SET_SPEECH_END:
            if (m_Status == SpeechStatus.SS_READY || m_Status == SpeechStatus.SS_LISTENING || m_Status == SpeechStatus.SS_STARTED)
            {
                m_Status = SpeechStatus.SS_RECOGNIZING;
                OnRecordEnd();
            }

            break;

        case SpeechEventType.SET_SPEECH_READY:
            if (m_Status == SpeechStatus.SS_STARTED)
            {
                m_Status = SpeechStatus.SS_READY;
                OnRecordReady();
            }

            break;

        case SpeechEventType.SET_TASK_START:
            if (m_Status == SpeechStatus.SS_DEFAULT)
            {
                m_Status = SpeechStatus.SS_STARTED;
                OnTaskStart();
            }

            break;

        case SpeechEventType.SET_TASK_OVER:
            if (m_Status != SpeechStatus.SS_DEFAULT)
            {
                m_Status = SpeechStatus.SS_DEFAULT;
#if UNITY_ANDROID && !UNITY_EDITOR
                CancelInvoke("StatusRecover");
#endif
                OnTaskOver();
            }
            break;

        case SpeechEventType.SET_AUDIO_PLAYOVER:
            if (m_Status != SpeechStatus.SS_DEFAULT)
            {
                m_Status = SpeechStatus.SS_DEFAULT;
#if UNITY_ANDROID && !UNITY_EDITOR
                CancelInvoke("ForcePlayOver");
#endif
                OnAudioPlayOver();
            }
            break;

        case SpeechEventType.SET_AUDIO_DECODEERROR:
            OnAudioDecodeError();
            m_Status = SpeechStatus.SS_DEFAULT;
            break;

        default:
            break;
        }
    }
Пример #12
0
 void ForcePlayOver()
 {
     m_Status = SpeechStatus.SS_DEFAULT;
     OnAudioPlayOver();
     CancelInvoke("ForcePlayOver");
 }
Пример #13
0
 private void DictationRecogniser_DictationError(string error, int hresult)
 {
     Debug.LogWarningFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
     Status = SpeechStatus.Stopped;
 }
Пример #14
0
 private void DictationRecogniser_DictationHypothesis(string text)
 {
     this.Status  = SpeechStatus.Speeking;
     lastWordSaid = Time.time;
 }
Пример #15
0
 public void StopSpeech()
 {
     dictationRecogniser.Stop();
     Status = SpeechStatus.Stopped;
 }