void ISpeaker.PlayAudioAsync(string voiceText, SpeechPriority priority, Action callback) { PlayAudioAsync(voiceText, priority); // mTextToSpeech.Speak(voiceText, QueueMode.Add, null); if (callback != null) { callback(); } }
/// <summary> /// 延时2秒播报语音 /// </summary> /// <param name="voiceFile"></param> /// <param name="priority"></param> protected void PlayAudioAsync(string voiceFile, SpeechPriority priority) { Task.Run(() => { if (IsFirst) { //第一次报档位多延迟3秒,避免和项目语音连起来 IsFirst = false; Thread.Sleep(3000); } int delay = Convert.ToInt32(DelayTime * 1000); Thread.Sleep(delay); Speaker.PlayAudioAsync(voiceFile, priority); }); }
/// <summary> /// 播放语音存在前面的一两个字吐字不清晰的问题,可以前面加上逗号或者顿号。 /// 这个问题已经通过升级MCU 解决。 /// </summary> /// <param name="voiceText"></param> /// <param name="priority"></param> public void PlayAudioAsync(string voiceText, SpeechPriority priority = SpeechPriority.Normal) { try { if (string.IsNullOrEmpty(voiceText)) { return; } voiceText = ",," + voiceText; // voiceText = voiceText; if (priority == SpeechPriority.High) { HighSpeechQueque.Enqueue(voiceText); } else if (priority == SpeechPriority.Normal) { NormalSpeechQueque.Enqueue(voiceText); } //表示高优先级的队列有语音需要播放则优先取出高优先级的 //if (HighSpeechQueque.Count > 0) //{ //voiceText = HighSpeechQueque.Dequeue(); //} //else //{ //voiceText = NormalSpeechQueque.Dequeue(); //} //把这个东西加入一个队列里面,然后每次取出里面的按优先级排列 //mTextToSpeech.Speak(voiceText, QueueMode.Add, null); //mTextToSpeech.Speak(voiceText, QueueMode.Add, null); //Task.Run( // () => // { // mTextToSpeech.Speak(voiceText, QueueMode.Add, null); // //下面这种写法android版本低了可能不支持 // // mTextToSpeech.Speak(voiceText, QueueMode.Add, null, string.Empty); // }); } //记录错误日志 catch (Exception ex) { LogManager.WriteSystemLog(ex.Message); } }