google

package
v0.77.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
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

func New(opts Options) *Provider

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) Health added in v0.64.3

func (p *Provider) Health(ctx context.Context) error

Health checks if the Google Speech API is reachable.

func (*Provider) Name added in v0.64.3

func (p *Provider) Name() string

Name returns the provider identifier.

func (*Provider) SetStreamingCredentialEnvs added in v0.64.3

func (p *Provider) SetStreamingCredentialEnvs(credentialsJSONEnv, applicationCredentialsEnv string)

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

func (p *Provider) StreamingCredentialsPresent() bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL