Documentation
¶
Overview ¶
Package google adapts Google Cloud Speech-to-Text to stt.STTProvider: v1 batch recognition with optional word-level speaker diarization, v2 regional batch recognition for Chirp 3 (ModelChirp3) and v2 StreamingRecognize for realtime transcription. It is an opt-in bring-your-own-key provider — never a SpeechKit default — and needs the user's own dedicated Speech-to-Text API key for batch requests and a service-account or Application Default Credentials for streaming.
Stability: Beta — API-checked; may change with a changelog callout.
Index ¶
- Constants
- func StreamingCredentialsPresent() bool
- type Options
- type Provider
- func (*Provider) Capabilities() []speechkit.Capability
- func (p *Provider) Health(ctx context.Context) error
- func (p *Provider) Name() string
- func (p *Provider) SetStreamingCredentialEnvs(credentialsJSONEnv, applicationCredentialsEnv string)
- func (p *Provider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
- func (p *Provider) StreamingCredentialsPresent() bool
- func (p *Provider) Transcribe(ctx context.Context, audio []byte, opts stt.TranscribeOpts) (*stt.Result, error)
Constants ¶
const ( EnvAPIKey = envGoogleSTTAPIKey EnvCloudAPIKey = envGoogleCloudSTTAPIKey EnvLegacyAPIKey = envGoogleLegacySTTAPIKey EnvCredentialsJSON = envGoogleSTTCredentialsJSON EnvApplicationCredentials = envGoogleApplicationCreds )
Credential env names a host can present to a user when streaming transcription is unavailable for lack of credentials.
const ModelChirp3 = "chirp_3"
ModelChirp3 is Google's recommended Speech-to-Text model. It runs on the v2 API only, in the "us" and "eu" multi-regions — never on v1 and never in the "global" location — so the provider routes it to a regional v2 recognizer.
Variables ¶
This section is empty.
Functions ¶
func StreamingCredentialsPresent ¶ added in v0.64.3
func StreamingCredentialsPresent() bool
StreamingCredentialsPresent reports whether service-account or ADC credentials are configured for streaming recognition under the default env names, consulting the process environment and the process-wide secret resolver. Batch transcription only needs an API key and is unaffected. Use (*Provider).StreamingCredentialsPresent to honour a per-instance resolver and custom env names.
Types ¶
type Options ¶ added in v0.74.0
type Options struct {
// APIKey is the Google API key.
APIKey string
// Model is the Speech-to-Text model. Empty selects "latest_long".
Model string
}
Options configures New.
type Provider ¶
type Provider struct {
APIKey string
Model string // "latest_long", "latest_short", or another Google STT v1 model tag
STTCredentialsJSONEnv string
ApplicationCredentialsEnv string
BaseURL string // Override for testing; defaults to googleSTTBaseURL
// Region is the v2 multi-region for models that only run regionally
// (ModelChirp3): "us" (default when empty) or "eu".
Region string
// ProjectID names the Google Cloud project for v2 requests. Empty falls
// back to the project in the service-account credentials, then
// GOOGLE_CLOUD_PROJECT.
ProjectID string
Validation netsec.ValidationOptions
// SecretResolver resolves the streaming credential env names
// (STTCredentialsJSONEnv, ApplicationCredentialsEnv, GOOGLE_CLOUD_PROJECT)
// when they are not present in the process environment. Nil falls back to
// the process environment.
SecretResolver stt.SecretResolver
// contains filtered or unexported fields
}
Provider implements stt.STTProvider for Google Cloud Speech-to-Text v1 REST API.
BaseURL is user-configurable (for testing or regional endpoints). It is validated against Validation on every request. Default Validation is strict (public https only).
func New ¶
New creates a provider for Google Cloud Speech-to-Text. Zero Options values select the provider defaults.
func (*Provider) Capabilities ¶ added in v0.64.3
func (*Provider) Capabilities() []speechkit.Capability
Capabilities reports what this provider does beyond plain transcription.
func (*Provider) SetStreamingCredentialEnvs ¶ added in v0.64.3
SetStreamingCredentialEnvs overrides the env-var names the streaming path reads the service-account JSON and the Application Default Credentials file from. Empty values keep the current names.
func (*Provider) StartSpeakerStream ¶ added in v0.64.3
func (p *Provider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
StartSpeakerStream opens a Google Cloud Speech-to-Text v2 StreamingRecognize session.
IMPORTANT: Google STT v2 does NOT support speaker diarization in streaming mode — diarization is available only in BatchRecognize/Recognize (see the Chirp-3 docs). This adapter therefore provides realtime TRANSCRIPTION only: frames carry Text without speaker labels (no Segment/Speakers). Streaming speaker diarization in the Voice Agent comes from Deepgram/AssemblyAI.
func (*Provider) StreamingCredentialsPresent ¶ added in v0.67.14
StreamingCredentialsPresent reports whether this provider can open a streaming session: it checks the provider's configured env names through its SecretResolver.
func (*Provider) Transcribe ¶ added in v0.64.3
func (p *Provider) Transcribe(ctx context.Context, audio []byte, opts stt.TranscribeOpts) (*stt.Result, error)
Transcribe sends audio to Google Cloud Speech-to-Text: the v1 REST API for every model except ModelChirp3, which only runs on the regional v2 API.