
browserMain.nl.marc_apps.tts.TextToSpeechFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tts Show documentation
Show all versions of tts Show documentation
Kotlin Multiplatform Text-to-Speech library for Android and browser (Kotlin/JS & Kotlin/Wasm). This library will enable you to use Text-to-Speech in multiplatform Kotlin projects.
package nl.marc_apps.tts
import js_interop.Window
import js_interop.isSpeechSynthesisSupported
import js_interop.window
import nl.marc_apps.tts.errors.TextToSpeechNotSupportedError
/**
* Factory class to create a Text-to-Speech instance.
*/
actual class TextToSpeechFactory(
private val context: Window = window
) {
actual val isSupported = isSpeechSynthesisSupported
actual val canChangeVolume = true
actual suspend fun create(): Result {
return if (isSupported) {
Result.success(TextToSpeechBrowser(context))
} else {
Result.failure(TextToSpeechNotSupportedError())
}
}
@Throws(RuntimeException::class)
actual suspend fun createOrThrow(): TextToSpeechInstance {
return create().getOrThrow()
}
actual suspend fun createOrNull(): TextToSpeechInstance? {
return create().getOrNull()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy