shadcn.io is an independent project built on shadcn/ui
Components
Free
Voice Selector for React Aria
A searchable dialog of text-to-speech voices, with a play button and the voice's gender, accent and age on each row. For React on React Aria.
On this page11 sections
Voice Selector is a dialog where people search your text-to-speech voices and pick the one the assistant speaks with. A row can carry a play button for a sample, plus the voice's gender, accent and age, so people narrow the list before they listen.
It's a Command inside a Dialog, and it plays no audio itself. For three or four voices with nothing to search, a Select takes less room.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
The trigger opens a modal dialog with focus in the search field, which takes its name from its placeholder. The dialog's title is read only by screen readers, Voice Selector unless you set title on VoiceSelectorContent. Focus stays in the field while the arrow keys move a highlight through the voices. The list is a menu of radio items, and the picked voice reports aria-checked. Gender and accent are read as words. A play button reads Play preview until you pass the voice's name as its label, which makes it Play Alloy. It sits inside its row, so its label is read as part of the voice's name, and Tab reaches it.
KeyAction
Arrow Down
Highlights the next voice, and wraps from the last one to the first.
Arrow Up
Highlights the previous voice, and wraps from the first one to the last.
Home
Highlights the first voice.
End
Highlights the last voice.
Enter
In the search field, picks the highlighted voice and closes the dialog. On a play button, plays or pauses its sample without picking the voice.
Space
On a play button, plays or pauses its sample without picking the voice.
Tab
Moves focus from the search field to the play buttons, one row at a time.
EscEscape
Clears the search field. When it's already empty, closes the dialog without a change.
Demos
Attributes
Six voices from OpenAI and ElevenLabs in two groups, with Sage picked at the start. Under each name, VoiceSelectorAttributes lines up a gender symbol, an accent flag, an age and one word on the tone, split by VoiceSelectorBullet. The search matches the voice's name only. Use it when people narrow a long list by trait before they listen.
Preview
Onyx, Alloy and Nova each have a VoiceSelectorPreview, labelled with the voice's name, that speaks a line through the browser's speech synthesis at that voice's pitch and rate. The button spins until speech starts, shows pause while it plays and never picks the voice, and closing the dialog stops the sample. Swap the synthesis for an <audio> element and a sample file per voice to play a provider's real voices.
Shortcuts
Four voices with VoiceSelectorShortcut hints from ⌥1 to ⌥4, and a key listener that picks a voice with Alt and its number while the dialog is open. The hint is only text, so the listener is yours to write, and the picked voice keeps its check beside the hint. Use shortcuts for a few voices people switch between often.
Controlled
An Assistant voice settings row holds open and value in its own state, and its Change button is the VoiceSelectorTrigger. The line under the label shows the picked voice and its description. Control open when your code also opens or closes the dialog, such as on a voice mode's first run.
AI SDK
The picked value is the voice the speech model speaks with. Send it with the text to a route that calls generateSpeech, and play the audio that comes back.
The same route can make each voice's preview. Call it once per voice with a short line and keep the files, rather than paying for a new sample on every press.
Migrating from AI SDK Elements
If you added Voice Selector from AI SDK Elements (opens in a new tab), install this one and change the import from @/components/ai-elements/voice-selector to @/components/ui/voice-selector. Every part keeps its name, and value, defaultValue, onValueChange, open, defaultOpen, onOpenChange and the preview's playing, loading and onPlay work the same. What differs:
VoiceSelectorContent's title is a string, and it takes a description for screen readers too.
VoiceSelectorAccent knows 35 accents and reads each one's name to screen readers. An accent it doesn't know shows its name as text.
The picked voice shows a check, and a preview button doesn't pick the voice with Enter or Space either.
VoiceSelectorPreview takes the voice's name as label, for Play Alloy and Pause Alloy, and keeps focus while it loads.
On React Aria, VoiceSelectorTrigger is the Button itself, VoiceSelectorItem takes id and textValue instead of value, and VoiceSelectorEmpty goes in VoiceSelectorList's renderEmptyState.
FAQ
How does the Voice Selector play button play a voice sample?
It doesn't play anything. VoiceSelectorPreview calls onPlay when pressed, and your code plays the sample, setting loading while it loads and playing while it plays, which swap the icon for a spinner or a pause sign. Presses while it loads are ignored.
Give each button the voice's name as label, so screen readers hear Play Alloy rather than the same Play preview on every row. The Preview demo speaks through the browser's speech synthesis. For a provider's real voices, play a stored sample file per voice in an <audio> element, and stop it when the open state turns false, as the demo does.
How do I get the voice someone picks in Voice Selector?
onValueChange receives the picked item's id as a string, and the dialog closes. Pass value from your state to control it, or defaultValue to start from one voice, and the picked row shows a check.
Store the value, not the label, and send it to your speech model as the voice, as the AI SDK section does.
What does the Voice Selector search match?
Each item's textValue, matched ignoring case and accents. The demos put only the name in it, so searching british finds nothing. Put any word people search by, such as the accent, in textValue after the name.
Which genders and accents can Voice Selector show?
VoiceSelectorGender draws a symbol for six values, male, female, transgender, androgyne, non-binary and intersex, and a small circle when you leave value out. Any other string, such as a provider's own Male, shows the small circle too, and screen readers still hear the word, so map your data to those six when you want the symbols.
VoiceSelectorAccent shows a flag for 35 accents, from american to vietnamese, and an accent it doesn't know as its name in text. Both read the word to screen readers, and children you pass replace the drawing and that word together.
Why do the Voice Selector accent flags show as letters on Windows?
The flags are emoji, and Windows' emoji font has no country flags, so the British flag shows as the two letters GB. macOS, iOS and Android draw the flag itself.
To show flags everywhere, pass your own children to VoiceSelectorAccent, such as a small SVG flag. Children replace the default content, the hidden accent name included, so put the name back as text that screen readers can read.
How do I open Voice Selector from my own button?
Make your button the VoiceSelectorTrigger, which is a Button, and it opens the dialog with no state of yours. To also open it from code, hold open in state and update it from onOpenChange, as the Controlled demo does. The dialog closes on Escape, a click outside or a pick, and reports that through onOpenChange.
Can Voice Selector be used with the keyboard?
Yes. The trigger opens the dialog with focus in the search field, typing filters the list, the arrow keys move through the voices, and Enter picks one and closes the dialog. Tab moves on to the play buttons, where Enter or Space plays a sample without picking the voice, and Escape first clears the search, then closes the dialog.
Is this the same as AI SDK Elements' Voice Selector?
It has the same parts and props, so most code only changes its import. The title also takes a description, the accents read their names aloud, and the picked voice shows a check. The Migrating section lists what differs on your stack.
API Reference
VoiceSelector
PropType
open?boolean
Whether the dialog is open, when controlled.
defaultOpen?boolean
Whether the dialog starts open, when uncontrolled.
Default
false
onOpenChange?(open: boolean) → void
Called when the dialog opens or closes.
Parameters
open – boolean
Returns
void
value?string
The picked voice's value, when controlled.
defaultValue?string
The voice picked at first, when uncontrolled.
onValueChange?(value: string) → void
Called with a voice's value when one is picked.
Parameters
value – string
Returns
void
children?React.ReactNode
The trigger and the content.
VoiceSelectorTrigger
data-slot="voice-selector-trigger"
PropType
children?ReactNode
The content to display in the button.
clickEffect?boolean
Apply a click effect to the button.
Default
true
download?LinkPrimitiveProps["download"]
With href, downloads the linked file instead of opening it.
href?string
When set, the button renders as a link.
isDisabled?boolean
Whether the button is disabled.
isLoading?boolean
Show a loading indicator.
Default
false
rel?string
With href, the link's relationship to the page (noreferrer, …).
target?string
With href, where the linked page opens (_blank, …).
className?string
Merged with the part's classes.
VoiceSelectorContent
data-slot="voice-selector-content"
PropType
defaultOpen?boolean
Whether the overlay is open by default (uncontrolled).
onOpenChange?(isOpen: boolean) → void
Handler that is called when the overlay's open state changes.
Parameters
isOpen – boolean
Returns
void
bottomStickOnMobile?boolean
Stick the dialog to the bottom of the screen on mobile. Ark default: true.
Default
false
description?string
The dialog's description, for screen readers.
Default
"Search for a voice and pick one."
isDismissable?boolean
Whether to close the modal when the user interacts outside it.
Default
false
isEntering?boolean
Whether the modal is currently performing an entry animation.
isExiting?boolean
Whether the modal is currently performing an exit animation.
isKeyboardDismissDisabled?boolean
Whether pressing the escape key to close the modal should be disabled.
Default
false
isOpen?boolean
Whether the overlay is open by default (controlled).
When user interacts with the argument element outside of the overlay ref,
return true if onClose should be called. This gives you a chance to filter
out interaction with elements that should not dismiss the overlay.
By default, onClose will always be called on interaction outside the overlay ref.
Parameters
element – Element
Returns
boolean
showCloseButton?boolean
Show close button at the top right corner. Ark default: true.
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit null value indicates that the local props completely override all
props received from a parent.
Type
string | null
Default
voice-selector-content
style?StyleOrFunction<T>
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the
element. A function may be provided to compute the style based on component state.
Type
StyleOrFunction<T>
title?string
The dialog's title, for screen readers.
Default
"Voice Selector"
UNSTABLE_deferUntilEntered?boolean
Whether to wait until the entry animation completes before hiding content outside the modal
and moving focus into it.
UNSTABLE_overrideFocus?boolean
Whether to override the focus() method so it does not scroll the page.
This is temporary and will be removed after fully testing all overlays.
UNSTABLE_portalContainer?Element
The container element in which the overlay portal will be placed. This may have unknown
behavior depending on where it is portalled to.
Deprecated. - Use a parent UNSAFE_PortalProvider to set your portal container instead.
Default
document.body
render?DOMRenderFunction<E, T>
Overrides the default DOM element with a custom render function.
This allows rendering existing components with built-in styles and behaviors
such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if <button> is expected, you cannot render an
<a>).
- Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop
as appropriate.
An enumerated attribute that defines what action label or icon to preset for the enter key on
virtual keyboards. See
[MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/enterkeyhint).
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the
element.
Type
{ prop?: string]: string | number }
className?string
The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
element.
VoiceSelectorList
data-slot="voice-selector-list"
PropType
className?string
Merged with the part's classes.
VoiceSelectorEmpty
data-slot="voice-selector-empty"
VoiceSelectorGroup
data-slot="voice-selector-group"
PropType
children?ReactNode | ((item: T) → ReactElement)
Static child items or a function to render children.
Type
ReactNode | ((item: T) → ReactElement)
dependencies?ReadonlyArray<any>
Values that should invalidate the item cache when using dynamic collections.
Type
ReadonlyArray<any>
heading?string
A label shown above the group's items.
id?Key
The unique id of the section.
shouldCloseOnSelect?boolean
Whether the menu should close when the menu item is selected.
style?object
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the
element.
Type
{ prop?: string]: string | number }
value?T
The object value that this section represents. When using dynamic collections, this is set
automatically.
render?DOMRenderFunction<E, T>
Overrides the default DOM element with a custom render function.
This allows rendering existing components with built-in styles and behaviors
such as router links, animation libraries, and pre-styled components.
Requirements:
- You must render the expected element type (e.g. if <button> is expected, you cannot render an
<a>).
- Only a single root DOM element can be rendered (no fragments).
- You must pass through props and ref to the underlying DOM element, merging with your own prop
as appropriate.
Type
DOMRenderFunction<E, T>
className?string
The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
element.
Default
"react-aria-MenuSection"
VoiceSelectorItem
data-slot="voice-selector-item"
PropType
className?string
Merged with the part's classes.
AttributeType
data-checked?string
Mirrors checked.
VoiceSelectorShortcut
data-slot="voice-selector-shortcut"
VoiceSelectorSeparator
data-slot="voice-selector-separator"
PropType
children?ReactNode
The children of the component.
elementType?string
The HTML element type that will be used to render the separator.
orientation?"horizontal" | "vertical"
The orientation of the separator.
Type
"horizontal" | "vertical"
Default
"horizontal"
style?object
The inline [style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) for the
element.
Type
{ prop?: string]: string | number }
className?string
The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the
element.
VoiceSelectorGender
<span>data-slot="voice-selector-gender"
PropType
value?VoiceSelectorGenderValue
The voice's gender, drawn as its symbol and read out as its name.
className?string
Merged with the part's classes.
VoiceSelectorAccent
<span>data-slot="voice-selector-accent"
PropType
value?string
The accent, such as british: shown as its country's flag.
className?string
Merged with the part's classes.
VoiceSelectorAge
<span>data-slot="voice-selector-age"
PropType
className?string
Merged with the part's classes.
VoiceSelectorName
<span>data-slot="voice-selector-name"
PropType
className?string
Merged with the part's classes.
VoiceSelectorDescription
<span>data-slot="voice-selector-description"
PropType
className?string
Merged with the part's classes.
VoiceSelectorAttributes
<div>data-slot="voice-selector-attributes"
PropType
className?string
Merged with the part's classes.
VoiceSelectorBullet
<span>data-slot="voice-selector-bullet"
PropType
className?string
Merged with the part's classes.
VoiceSelectorPreview
data-slot="voice-selector-preview"
PropType
isDisabled?boolean
Whether the button is disabled.
label?string
The voice's name, which the button's label ends with: Play Alloy,
Pause Alloy.
Default
"preview"
loading?boolean
Shows a spinner while the sample loads. The button keeps focus and
ignores presses until it's done.
onPlay?() → void
Called on press. Play or pause the sample here.
Returns
void
playing?boolean
Shows pause instead of play while the sample plays.