Speech
Text-to-Speech
assistant-ui supports text-to-speech via the SpeechSynthesisAdapter interface.
Sample Text to Speech
Try submitting a message, then clicking on the speech icon in the assistant message.
SpeechSynthesisAdapter
Currently, the following speech synthesis adapters are supported:
WebSpeechSynthesisAdapter: Uses the browser'sWeb Speech APIAPI
Support for other speech synthesis adapters is planned for the future.
Passing a SpeechSynthesisAdapter to the EdgeRuntime will enable text-to-speech support.
UI
By default, a Read aloud button will be shown in the assistant message action bar.
This is implemented using AssistantActionBar.SpeechControl which is a wrapper around AssistantActionBar.Speak and AssistantActionBar.StopSpeaking.
The underlying primitives are ActionBarPrimitive.Speak and ActionBarPrimitive.StopSpeaking.
Example
The following example uses the WebSpeechSynthesisAdapter.
import { WebSpeechSynthesisAdapter } from "@assistant-ui/react";
const runtime = useChatRuntime({
api: "/api/chat",
adapters: {
speech: new WebSpeechSynthesisAdapter(),
},
});