[6.10.0][Feat]新增排队超时机制
This commit is contained in:
@@ -3,11 +3,16 @@ package com.mogo.tts.base
|
||||
data class MultiLangTtsEntity(
|
||||
private var ttsList: List<LangTtsEntity>
|
||||
) {
|
||||
companion object {
|
||||
private const val TIMEOUT_MILLIS = 60000
|
||||
}
|
||||
|
||||
private val stringBuffer by lazy {
|
||||
StringBuffer()
|
||||
}
|
||||
|
||||
private var ttsIndex = 0
|
||||
private var timeStamp: Long = 0
|
||||
|
||||
fun ttsNext(): LangTtsEntity? {
|
||||
return if (ttsIndex in ttsList.indices) {
|
||||
@@ -17,6 +22,14 @@ data class MultiLangTtsEntity(
|
||||
}
|
||||
}
|
||||
|
||||
fun markTime() {
|
||||
timeStamp = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
fun isTimeout():Boolean {
|
||||
return timeStamp > 0 && System.currentTimeMillis() - timeStamp >= TIMEOUT_MILLIS
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return stringBuffer.let {
|
||||
it.setLength(0)
|
||||
|
||||
@@ -209,9 +209,12 @@ class IFlyTekTts : IMogoTTS, InitListener {
|
||||
var index = -1
|
||||
for (i in linkedList.indices.reversed()) {
|
||||
val nodeLevel = linkedList[i].second
|
||||
// 只有高优先级才插入到前面,等于的情况下是插到后面
|
||||
if (level > nodeLevel) {
|
||||
if (linkedList[i].first.isTimeout()) {
|
||||
linkedList.removeAt(i)
|
||||
} else if (level > nodeLevel) { // 只有高优先级才插入到前面,等于的情况下是插到后面
|
||||
index = i
|
||||
} else { // 再往前元素优先级更大,直接break
|
||||
break
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
@@ -227,6 +230,7 @@ class IFlyTekTts : IMogoTTS, InitListener {
|
||||
|
||||
private fun speakMultiLangTTSWithLevel(ttsEntity: MultiLangTtsEntity, ttsLevel: Int) {
|
||||
ttsEngine?.let {
|
||||
ttsEntity.markTime()
|
||||
if (ttsLevel == curTtsLevel) {
|
||||
// 对应p3、p2级别的排队
|
||||
if (ttsLevel == 0 || ttsLevel == 1) {
|
||||
@@ -379,13 +383,29 @@ class IFlyTekTts : IMogoTTS, InitListener {
|
||||
* 语音合成下一个MultiLangTtsEntity
|
||||
*/
|
||||
private fun ttsNextMultiLangEntity() {
|
||||
if (!linkedList.isEmpty()) {
|
||||
val ttsPair = linkedList.removeFirst()
|
||||
i(TAG, "排队播放的下一条文本为:" + ttsPair.first + ",级别为:" + ttsPair.second)
|
||||
curTtsLevel = ttsPair.second
|
||||
startSpeak(ttsPair.first.ttsNext())
|
||||
var ttsPair: Pair<MultiLangTtsEntity, Int>?
|
||||
val ttsList = linkedList
|
||||
if (!ttsList.isEmpty()) {
|
||||
ttsPair = ttsList.removeFirst()
|
||||
while (ttsPair != null && ttsPair.first.isTimeout()) {
|
||||
if (!ttsList.isEmpty()) {
|
||||
ttsPair = ttsList.removeFirst()
|
||||
} else {
|
||||
ttsPair = null
|
||||
break
|
||||
}
|
||||
}
|
||||
if (ttsPair != null) {
|
||||
i(
|
||||
TAG,
|
||||
"排队播放的下一条文本为:" + ttsPair.first + ",级别为:" + ttsPair.second
|
||||
)
|
||||
speakMultiLangTTSWithLevel(ttsPair.first, ttsPair.second)
|
||||
} else {
|
||||
i(TAG, "未超时的队列为空!")
|
||||
}
|
||||
} else {
|
||||
i(TAG, "队列为空")
|
||||
i(TAG, "队列为空!")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -412,6 +412,7 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack {
|
||||
|
||||
private void speakMultiLangTTSWithLevel(MultiLangTtsEntity ttsEntity,int ttsLevel) {
|
||||
if (mEngine != null) {
|
||||
ttsEntity.markTime();
|
||||
if (ttsLevel == curTtsLevel) {
|
||||
// 对应p3、p2级别的排队
|
||||
if (ttsLevel == 0 || ttsLevel == 1) {
|
||||
@@ -472,9 +473,12 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack {
|
||||
int index = -1;
|
||||
for (int i = linkedList.size() - 1; i >= 0; i--) {
|
||||
int nodeLevel = linkedList.get(i).second;
|
||||
// 只有高优先级才插入到前面,等于的情况下是插到后面
|
||||
if (level > nodeLevel) {
|
||||
if (linkedList.get(i).first.isTimeout()) {
|
||||
linkedList.remove(i);
|
||||
} else if (level > nodeLevel) {// 只有高优先级才插入到前面,等于的情况下是插到后面
|
||||
index = i;
|
||||
} else {// 再往前元素优先级更大,直接break
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index >= 0) {
|
||||
@@ -887,12 +891,26 @@ public class PadTTS implements IMogoTTS, VoiceClient.VoiceCmdCallBack {
|
||||
}
|
||||
|
||||
private void ttsNextMultiLangEntity() {
|
||||
if (!linkedList.isEmpty()) {
|
||||
Pair<MultiLangTtsEntity, Integer> ttsPair = linkedList.removeFirst();
|
||||
CallerLogger.i(TAG, "排队播放的下一条文本为:" + ttsPair.first + ",级别为:" + ttsPair.second);
|
||||
speakMultiLangTTSWithLevel(ttsPair.first, ttsPair.second);
|
||||
Pair<MultiLangTtsEntity, Integer> ttsPair;
|
||||
LinkedList<Pair<MultiLangTtsEntity, Integer>> ttsList = linkedList;
|
||||
if (!ttsList.isEmpty()) {
|
||||
ttsPair = ttsList.removeFirst();
|
||||
while (ttsPair != null && ttsPair.first.isTimeout()) {
|
||||
if (!ttsList.isEmpty()) {
|
||||
ttsPair = ttsList.removeFirst();
|
||||
} else {
|
||||
ttsPair = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ttsPair != null) {
|
||||
CallerLogger.i(TAG, "排队播放的下一条文本为:" + ttsPair.first + ",级别为:" + ttsPair.second);
|
||||
speakMultiLangTTSWithLevel(ttsPair.first, ttsPair.second);
|
||||
} else {
|
||||
CallerLogger.i(TAG, "未超时的队列为空!");
|
||||
}
|
||||
} else {
|
||||
CallerLogger.i(TAG, "队列为空");
|
||||
CallerLogger.i(TAG, "队列为空!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user