fix(tts): fixed highlighting of current sentence for native tts on Android, closes #2620 (#2621)

This commit is contained in:
Huang Xin
2025-12-05 11:05:18 +08:00
committed by GitHub
parent a232a39f0e
commit b08b7de8e9
2 changed files with 15 additions and 4 deletions
@@ -383,7 +383,10 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) {
val args = invoke.parseArgs(SetVoiceArgs::class.java)
try {
val voices = textToSpeech?.voices
val targetVoice = voices?.find { it.name == args.voice }
val targetVoice = voices?.find { voice ->
val languageTag = voice.locale.toLanguageTag()
voice.name == args.voice || (languageTag.contains(voice.name) && languageTag == args.voice)
}
if (targetVoice != null) {
val result = textToSpeech?.setVoice(targetVoice)
@@ -404,10 +407,17 @@ class NativeTTSPlugin(private val activity: Activity) : Plugin(activity) {
fun get_all_voices(invoke: Invoke) {
try {
val voices = textToSpeech?.voices?.map { voice ->
val voiceName = voice.name
val language = voice.locale.toLanguageTag()
val (id, name) = if (language.contains(voiceName)) {
language to language
} else {
voiceName to voiceName
}
JSObject().apply {
put("id", voice.name)
put("name", voice.name)
put("lang", voice.locale.toLanguageTag())
put("id", id)
put("name", name)
put("lang", language)
put("disabled", false)
}
} ?: emptyList()
@@ -181,6 +181,7 @@ export class NativeTTSClient implements TTSClient {
const { marks } = parseSSMLMarks(ssml, this.#primaryLang);
for (const mark of marks) {
this.controller?.dispatchSpeakMark(mark);
for await (const ev of this.speakMark(mark, preload, signal)) {
if (signal.aborted) {
yield { code: 'error', message: 'Aborted' } as TTSMessageEvent;