Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
52 lines
1.7 KiB
Kotlin
52 lines
1.7 KiB
Kotlin
package dev.mygo
|
|
|
|
import android.speech.tts.TextToSpeech
|
|
import org.json.JSONObject
|
|
import java.util.Locale
|
|
|
|
class TTSPlugin : MyGoPlugin {
|
|
private var engine: TextToSpeech? = null
|
|
private var ready = false
|
|
private var pending: Pair<String, PluginReply>? = null
|
|
|
|
override fun call(method: String, args: JSONObject, reply: PluginReply) {
|
|
when (method) {
|
|
"speak" -> {
|
|
val text = args.optString("text").ifEmpty { return reply.failure(PluginFailure("Empty", "no text")) }
|
|
if (ready) {
|
|
engine?.speak(text, TextToSpeech.QUEUE_FLUSH, null, "openchamber")
|
|
reply.success(null)
|
|
} else {
|
|
pending = text to reply
|
|
init()
|
|
}
|
|
}
|
|
"stop" -> {
|
|
engine?.stop()
|
|
reply.success(null)
|
|
}
|
|
else -> reply.failure(PluginFailure("NoMethod", method))
|
|
}
|
|
}
|
|
|
|
private fun init() {
|
|
if (engine != null) return
|
|
engine = TextToSpeech(PluginHost.context) { status ->
|
|
if (status == TextToSpeech.SUCCESS) {
|
|
engine?.setLanguage(Locale.getDefault())
|
|
ready = true
|
|
val p = pending
|
|
pending = null
|
|
if (p != null) {
|
|
engine?.speak(p.first, TextToSpeech.QUEUE_FLUSH, null, "openchamber")
|
|
p.second.success(null)
|
|
}
|
|
} else {
|
|
val p = pending
|
|
pending = null
|
|
if (p != null) p.second.failure(PluginFailure("Init", "text-to-speech is unavailable"))
|
|
}
|
|
}
|
|
}
|
|
}
|