deepgram-go-speech-to-text
Use ao escrever ou revisar código Go neste repositório que transcreve áudio pré-gravado com Listen v1 REST ou transmite áudio ao vivo com Listen v1 WebSockets.
npx skills add https://github.com/deepgram/deepgram-go-sdk --skill deepgram-go-speech-to-textUsing Deepgram Speech-to-Text from the Go SDK
When to use this product
Use this skill for pkg/client/listen work:
- prerecorded transcription with
FromURL,FromFile, orFromStream - live transcription with
pkg/client/listen/v1/websocket - channel-based or callback-based streaming flows
Use a different skill when:
- you need TTS output (
deepgram-go-text-to-speech) - you need text analysis on plain text (
deepgram-go-text-intelligence) - you need analytics overlays like summaries, topics, or sentiments (
deepgram-go-audio-intelligence) - you need Flux / conversational STT v2 (
deepgram-go-conversational-stt)
Authentication
Set DEEPGRAM_API_KEY before constructing clients.
export DEEPGRAM_API_KEY="your_api_key"
This SDK reads env-backed defaults via the client option layer. Prefer API key or token auth supported by the repo's client options; do not hardcode credentials.
Quick start
Prerecorded REST:
package main
import (
"context"
"fmt"
"log"
api "github.com/deepgram/deepgram-go-sdk/v3/pkg/api/listen/v1/rest"
listen "github.com/deepgram/deepgram-go-sdk/v3/pkg/client/listen"
interfaces "github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx := context.Background()
client := listen.NewRESTWithDefaults()
dg := api.New(client)
resp, err := dg.FromURL(
ctx,
"https://dpgr.am/spacewalk.wav",
&interfaces.PreRecordedTranscriptionOptions{
Model: "nova-3",
SmartFormat: true,
Punctuate: true,
},
)
if err != nil {
return err
}
fmt.Println(resp.Results.Channels[0].Alternatives[0].Transcript)
return nil
}
Live WebSocket with channel fan-out:
package main
import (
"context"
"fmt"
"log"
listenws "github.com/deepgram/deepgram-go-sdk/v3/pkg/api/listen/v1/websocket"
listen "github.com/deepgram/deepgram-go-sdk/v3/pkg/client/listen"
interfaces "github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx := context.Background()
handler := listenws.NewDefaultChanHandler()
conn, err := listen.NewWSUsingChanWithDefaults(
ctx,
&interfaces.LiveTranscriptionOptions{Model: "nova-3", InterimResults: true},
handler,
)
if err != nil {
return err
}
defer conn.Stop()
if ok := conn.Connect(); !ok {
return fmt.Errorf("connect failed")
}
conn.Start()
// The handler receives Open/Message/Metadata/UtteranceEnd events.
// In a real app, stream PCM/audio chunks from your mic or file reader here.
// For example (pseudo-code):
// for chunk := range audioChunks {
// if err := conn.WriteBinary(chunk); err != nil { return err }
// }
//
// When the input stream ends, flush any trailing audio and close cleanly:
// if err := conn.Finalize(); err != nil { return err }
return nil
}
Key parameters
interfaces.PreRecordedTranscriptionOptions- common fields:
Model,Language,Punctuate,SmartFormat,Diarize,DiarizeModel(batch diarization version:latest/v1/v2),Redact,Utterances - use with
pkg/api/listen/v1/rest:api.New(client).FromURL,FromFile,FromStream
- common fields:
interfaces.LiveTranscriptionOptions- common fields:
Model,Language,Encoding,SampleRate,Channels,InterimResults,Endpointing
- common fields:
- constructor families
- REST:
listen.NewRESTWithDefaults(),listen.NewREST(apiKey, options) - WS callbacks:
listen.NewWSUsingCallback... - WS channels:
listen.NewWSUsingChan...
- REST:
- lifecycle
Connect()returnsbool; callStart(), stream/write audio,KeepAlive()as needed,Finalize(), thendefer conn.Stop()
API reference (layered)
- In-repo reference
README.mddocs.gopkg/client/listen/client.gopkg/client/listen/v1/rest/client.gopkg/client/listen/v1/websocket/client_callback.gopkg/client/listen/v1/websocket/client_channel.gopkg/client/interfaces/v1/types-prerecorded.gopkg/client/interfaces/v1/types-stream.go
- OpenAPI
https://developers.deepgram.com/openapi.yaml
- AsyncAPI
https://developers.deepgram.com/asyncapi.yaml
- Context7
/llmstxt/developers_deepgram_llms_txt
- Product docs
https://developers.deepgram.com/reference/speech-to-text/listen-pre-recordedhttps://developers.deepgram.com/reference/speech-to-text/listen-streaminghttps://developers.deepgram.com/docs/speech-to-text
Gotchas
- This repo uses
listenpackage names for STT v1, nottranscription. - Streaming code is split into callback and channel variants; copy the style that matches the surrounding package.
- For WebSockets, pass a handler into
NewWSUsingChan..., keepdefer conn.Stop()near construction, and finalize before shutdown. - Live and prerecorded option structs are different; do not assume analytics-only prerecorded fields exist in live mode.
- Use
context.Contextand returnerror; do not translate examples into exception-style control flow.
Example files in this repo
examples/speech-to-text/rest/url/main.goexamples/speech-to-text/rest/file/main.goexamples/speech-to-text/websocket/microphone_channel/main.goexamples/speech-to-text/websocket/microphone_callback/main.gotests/edge_cases/keepalive/main.gotests/edge_cases/reconnect_client/main.go
Central product skills
For cross-language Deepgram product knowledge — the consolidated API reference, documentation finder, focused runnable recipes, third-party integration examples, and MCP setup — install the central skills:
npx skills add deepgram/skills
This SDK ships language-idiomatic code skills; deepgram/skills ships cross-language product knowledge (see api, docs, recipes, examples, starters, setup-mcp).