Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get a List of all voices for TTS? #327

Open
Wolfscowl opened this issue Apr 25, 2024 · 2 comments
Open

How can I get a List of all voices for TTS? #327

Wolfscowl opened this issue Apr 25, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Wolfscowl
Copy link

Description

Is there a simple way to get a List of all supported Voices?

Steps to Reproduce

My approach., but no success

        val voiceFields = Voice::class.java.declaredFields  // size 8
        val sortedVoiceFields = voiceFields.filter { it.type == Voice::class.java } // size 0

I would be very grateful for a solution.

Environment

Android Studio

@Wolfscowl
Copy link
Author

Wolfscowl commented Apr 25, 2024

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
    }

Gradle Dependeny:

dependencies {
   ...
   implementation(kotlin("reflect"))
}

@aallam
Copy link
Owner

aallam commented Apr 29, 2024

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.

@aallam aallam added the question Further information is requested label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants