Documentation
¶
Overview ¶
Package voice implements voice prompting for the rysh TUI: it records the microphone via a system recorder, transcribes the audio with a pluggable speech-to-text provider (Deepgram by default, OpenAI Whisper as an alternative), and hands the text back to the caller to drop into the prompt input field.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller wires a Recorder and a Transcriber into the simple state machine used by the TUI: Start -> Stop -> Transcribe (or Cancel).
It is safe for concurrent use: the TUI event loop drives Start/Stop/Cancel/ State while the (blocking) HTTP transcription runs on a separate goroutine.
func NewController ¶
func NewController(rec Recorder, tr Transcriber) *Controller
NewController builds a Controller from a Recorder and Transcriber.
func (*Controller) Cancel ¶
func (c *Controller) Cancel()
Cancel aborts an in-progress recording and resets to idle. It is safe to call in any state; during transcription it only resets the state flag (the HTTP request, if any, is left to finish and its result should be ignored by the caller).
func (*Controller) ProviderName ¶
func (c *Controller) ProviderName() string
ProviderName returns the transcription provider name (for diagnostics).
func (*Controller) Start ¶
func (c *Controller) Start() error
Start begins recording. It is a no-op error if not idle.
func (*Controller) State ¶
func (c *Controller) State() State
State returns the current lifecycle state.
func (*Controller) Stop ¶
func (c *Controller) Stop() (string, error)
Stop finalizes the recording and transitions to StateTranscribing. It returns the path to the captured audio file, which the caller must pass to Transcribe (Transcribe deletes the file when done). On error the state is reset to idle.
func (*Controller) Transcribe ¶
Transcribe sends the audio file to the configured provider and returns the recognized text. The audio file is always removed before returning. The controller is reset to idle on completion regardless of outcome.
type Recorder ¶
type Recorder interface {
// Start begins capturing audio. It returns an error if no recorder tool
// is available or the capture process fails to launch.
Start(ctx context.Context) error
// Stop finalizes the recording and returns the path to the audio file.
// The caller owns the file and is responsible for deleting it.
Stop() (audioPath string, err error)
// Cancel aborts an in-progress recording and removes the temp file.
Cancel()
// Recording reports whether a capture is currently in progress.
Recording() bool
}
Recorder captures microphone audio to a temporary file.
The lifecycle is: Start -> (Stop | Cancel). Start begins capture; Stop finalizes the recording and returns the path to the captured audio file; Cancel aborts and deletes any temp file. Implementations must be safe to reuse for a subsequent Start after Stop/Cancel.
func NewStaticRecorder ¶
NewStaticRecorder returns a Recorder that writes payload to a temp file on Stop. Useful for tests without a microphone.
func NewSystemRecorder ¶
NewSystemRecorder constructs a Recorder backed by a system recording tool.
- recorder selects the tool ("auto" auto-detects per OS).
- overrideCmd is an optional full command template using {output}.
- maxSeconds caps a recording (0 = no cap).
type Transcriber ¶
type Transcriber interface {
Transcribe(ctx context.Context, audioPath string) (string, error)
// Name reports the provider name (e.g. "deepgram", "whisper").
Name() string
}
Transcriber turns a recorded audio file into text.
func NewStaticTranscriber ¶
func NewStaticTranscriber(text string, err error) Transcriber
NewStaticTranscriber returns a Transcriber that always yields text (or err).
func NewTranscriber ¶
func NewTranscriber(provider, apiKey, language string) (Transcriber, error)
NewTranscriber builds a Transcriber for the configured provider. provider is matched case-insensitively: "deepgram" (default) and "whisper"/"openai" are supported. apiKey is the credential for the selected provider; language is an optional BCP-47 hint (empty = auto-detect).