Speech-to-Text Controller
Controller and recorder for speech-to-text transcription in custom elements.
UaiSpeechToTextController and UaiAudioRecorder provide a frontend API for recording audio and transcribing it to text. The two classes separate concerns: the recorder captures audio from the microphone, and the controller sends it to the Management API for transcription.
Import
import {
UaiSpeechToTextController,
UaiAudioRecorder,
UaiSpeechToTextOptions,
UaiSpeechToTextResult,
UaiAudioRecorderState
} from "@umbraco-ai/core";UaiAudioRecorder
Records audio via the browser's MediaRecorder API. Extends UmbControllerBase so the recording is automatically cancelled when the host element is destroyed (for example, when navigating away).
Constructor
new UaiAudioRecorder(host: UmbControllerHost)host
UmbControllerHost
The controller host (usually this in a Lit element)
Properties
state
UaiAudioRecorderState
Current state: "idle" or "recording"
state$
Observable<UaiAudioRecorderState>
RxJS observable of state changes
Methods
start
Requests microphone access and begins recording.
stop
Stops recording and returns the captured audio as a Blob.
cancel
Stops recording and discards the captured audio.
Example
UaiSpeechToTextController
Handles transcription by sending audio to the Management API. Follows the same controller pattern as UaiChatController.
Constructor
host
UmbControllerHost
The controller host (usually this in a Lit element)
Methods
transcribe
Sends an audio blob to the Management API for transcription.
audioFile
Blob
The recorded audio blob
options
UaiSpeechToTextOptions
Optional transcription config
Returns: Promise resolving to { data?, error? }
Options
Result
Complete Example
Related
Chat Controller - Chat completions in the frontend
Speech-to-Text API - Backend Speech-to-Text service
Types - All frontend type definitions
Last updated
Was this helpful?