feat: 添加 TTS 中文语音测试(调试模式触发)
设置页快速点击头像6次触发 TTS 测试,验证设备是否支持中文语音合成。 测试结果通过 Toast 和 Logcat 反馈,为后续任务语音播报功能做可行性验证。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import com.xiaoqu.watch.ui.punch.PunchResult
|
|||||||
import com.xiaoqu.watch.ui.punch.PunchViewModel
|
import com.xiaoqu.watch.ui.punch.PunchViewModel
|
||||||
import com.xiaoqu.watch.ui.widget.StatusBarView
|
import com.xiaoqu.watch.ui.widget.StatusBarView
|
||||||
import com.xiaoqu.watch.util.DateUtil
|
import com.xiaoqu.watch.util.DateUtil
|
||||||
|
import android.speech.tts.TextToSpeech
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
@@ -83,6 +84,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
private var debugTapCount = 0
|
private var debugTapCount = 0
|
||||||
private var lastTapTime = 0L
|
private var lastTapTime = 0L
|
||||||
|
|
||||||
|
// ===== TTS 语音测试 =====
|
||||||
|
private var tts: TextToSpeech? = null
|
||||||
|
|
||||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentHomeBinding {
|
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentHomeBinding {
|
||||||
return FragmentHomeBinding.inflate(inflater, container, false)
|
return FragmentHomeBinding.inflate(inflater, container, false)
|
||||||
}
|
}
|
||||||
@@ -179,6 +183,9 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
it.onBackKeyPressed = null
|
it.onBackKeyPressed = null
|
||||||
it.notificationBanner.onClick = null
|
it.notificationBanner.onClick = null
|
||||||
}
|
}
|
||||||
|
// 释放 TTS 资源
|
||||||
|
tts?.shutdown()
|
||||||
|
tts = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===== 打卡面板 =====
|
// ===== 打卡面板 =====
|
||||||
@@ -548,8 +555,48 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
|
|||||||
|
|
||||||
if (debugTapCount >= 6) {
|
if (debugTapCount >= 6) {
|
||||||
debugTapCount = 0
|
debugTapCount = 0
|
||||||
Timber.d("调试模式已开启")
|
Timber.d("TTS 语音测试开始")
|
||||||
Toast.makeText(requireContext(), "调试模式已开启", Toast.LENGTH_SHORT).show()
|
testTts()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTS 语音测试:验证设备是否支持中文语音合成
|
||||||
|
* 测试内容:初始化 TTS → 设置中文 → 播放测试语音
|
||||||
|
* 结果通过 Logcat 和 Toast 反馈
|
||||||
|
*/
|
||||||
|
private fun testTts() {
|
||||||
|
tts?.shutdown()
|
||||||
|
tts = TextToSpeech(requireContext()) { status ->
|
||||||
|
if (status == TextToSpeech.SUCCESS) {
|
||||||
|
val result = tts?.setLanguage(java.util.Locale.CHINESE)
|
||||||
|
when {
|
||||||
|
result == TextToSpeech.LANG_MISSING_DATA -> {
|
||||||
|
Timber.w("TTS: 中文语音包缺失")
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
Toast.makeText(requireContext(), "TTS: 中文语音包缺失", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result == TextToSpeech.LANG_NOT_SUPPORTED -> {
|
||||||
|
Timber.w("TTS: 不支持中文")
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
Toast.makeText(requireContext(), "TTS: 不支持中文", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Timber.d("TTS: 中文语音可用,开始播放测试")
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
Toast.makeText(requireContext(), "TTS 测试播放中...", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
tts?.speak("您有3条新任务待处理", TextToSpeech.QUEUE_FLUSH, null, "tts_test")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.e("TTS: 初始化失败, status=$status")
|
||||||
|
activity?.runOnUiThread {
|
||||||
|
Toast.makeText(requireContext(), "TTS: 初始化失败", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user