TTSPluginMain.kt 929 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright (c) Milan Jurkulák 2024.
  3. * Contact:
  4. * e: mimoccc@gmail.com
  5. * e: mj@mjdev.org
  6. * w: https://mjdev.org
  7. */
  8. package eu.mjdev.desktop.managers.artificialintelligence.tts
  9. import eu.mjdev.desktop.managers.artificialintelligence.tts.base.TTSPlugin
  10. import kotlinx.coroutines.CoroutineScope
  11. import kotlinx.coroutines.Dispatchers
  12. import kotlinx.coroutines.async
  13. import kotlinx.coroutines.launch
  14. import nl.marc_apps.tts.TextToSpeechFactory
  15. import nl.marc_apps.tts.experimental.ExperimentalDesktopTarget
  16. @OptIn(ExperimentalDesktopTarget::class)
  17. class TTSPluginMain(
  18. val scope: CoroutineScope
  19. ) : TTSPlugin {
  20. private val textToSpeech = scope.async {
  21. TextToSpeechFactory().createOrNull()
  22. }
  23. override fun talk(text: String, clearQueue: Boolean) {
  24. println("talking: $text")
  25. scope.launch(Dispatchers.IO) {
  26. textToSpeech.await()?.say(text, clearQueue)
  27. }
  28. }
  29. }