You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found a solution to read out all voices from the voice class with their names as a map:
Voice class
@Serializable
@JvmInline
public value class Voice(public val value: String) {
public companion object {
public val Alloy: Voice = Voice("alloy")
public val Echo: Voice = Voice("echo")
public val Fable: Voice = Voice("fable")
public val Onyx: Voice = Voice("onyx")
public val Nova: Voice = Voice("nova")
public val Shimmer: Voice = Voice("shimmer")
}
}
Function:
fun getAvailableVoices(): Map<String,Voice> {
val voices = mutableMapOf<String, Voice>()
val properties = Voice.Companion::class.memberProperties
properties.forEach {
if (it.returnType.classifier == Voice::class) {
val name = it.name
val voice = it.call(Voice::class.companionObjectInstance) as Voice
voices[name] = voice
}
}
return voices
}
There is no list because the list of voices can change, necessitating updates to the library each time a new voice is added.
I suggest manually creating and maintaining the list.
This approach applies to other APIs, such as the models list, etc.
Description
Is there a simple way to get a List of all supported Voices?
Steps to Reproduce
My approach., but no success
I would be very grateful for a solution.
Environment
Android Studio
The text was updated successfully, but these errors were encountered: