# Deepgram STT

> Configure Deepgram Nova for low-latency, high-accuracy speech recognition in your voice agent.

Source: https://edesy.in/docs/voice-agent/providers/deepgram

Deepgram is our recommended STT provider for English-language voice agents due to its industry-leading latency and accuracy.

## Why Deepgram?

- **Lowest Latency**: very fast streaming transcription
- **High Accuracy**: Nova-3 achieves <5% WER on clean audio
- **Interim Results**: Real-time partial transcriptions
- **Cost Effective**: included in the Edesy per-minute price

## Configuration

### Environment Variables

```bash
DEEPGRAM_API_KEY=your_deepgram_api_key
```

### Agent Configuration

```json
{
  "sttProvider": "deepgram",
  "sttConfig": {
    "model": "nova-3",
    "language": "en",
    "endpointing": 200,
    "utterance_end_ms": 1000,
    "interim_results": true,
    "smart_format": true,
    "punctuate": true,
    "diarize": false
  }
}
```

## Model Options

| Model | Accuracy | Cost | Best For |
|-------|----------|------|----------|
| `nova-3` | Highest | $$$ | Production |
| `nova-2` | High | $$ | Cost-sensitive |
| `nova` | Good | $ | Basic use |
| `enhanced` | Good | $ | General |
| `base` | Basic | $ | Development |

## Endpointing Settings

Fine-tune when Deepgram determines the user has finished speaking:

```go
type DeepgramConfig struct {
    Endpointing    int  `json:"endpointing"`     // Silence before final (ms)
    UtteranceEndMs int  `json:"utterance_end_ms"` // Max mid-utterance silence
    InterimResults bool `json:"interim_results"`  // Enable partial results
}
```

### Recommended Settings

**For conversational agents (faster response):**
```json
{
  "endpointing": 200,
  "utterance_end_ms": 1000,
  "interim_results": true
}
```

**For dictation/longer utterances:**
```json
{
  "endpointing": 500,
  "utterance_end_ms": 2000,
  "interim_results": true
}
```

## Streaming Implementation

Our implementation uses WebSocket streaming for lowest latency:

```go
// Simplified streaming flow
func (d *DeepgramSTT) StreamTranscribe(ctx context.Context, audioChan <-chan []byte) <-chan string {
    resultChan := make(chan string)

    go func() {
        // Connect to Deepgram WebSocket
        conn := d.connect(ctx)

        // Send audio chunks
        go func() {
            for audio := range audioChan {
                conn.WriteMessage(websocket.BinaryMessage, audio)
            }
        }()

        // Receive transcriptions
        for {
            _, msg, err := conn.ReadMessage()
            if err != nil {
                break
            }

            var result DeepgramResult
            json.Unmarshal(msg, &result)

            if result.IsFinal {
                resultChan <- result.Transcript
            }
        }
    }()

    return resultChan
}
```

## Interim Results

Interim results allow the LLM to start generating responses before the user finishes speaking:

```
Timeline:
──────────────────────────────────────────────────▶

User speaking: "What is my order status for twelve thirty four"
                    │           │               │
Interim 1:     "What is"        │               │
Interim 2:          "What is my order"          │
Interim 3:                      "What is my order status for"
Final:                                    "What is my order status for 1234"
                                                │
LLM starts:                            ────────▶ [Can start early!]
```

## Smart Formatting

Enable smart formatting for better transcription quality:

```json
{
  "smart_format": true,
  "punctuate": true,
  "numerals": true
}
```

**Before smart format:** "one two three four"
**After smart format:** "1234"

## Language Support

| Language | Code | Model Support |
|----------|------|---------------|
| English | `en`, `en-US`, `en-GB` | All models |
| Spanish | `es` | Nova-2, Nova-3 |
| French | `fr` | Nova-2, Nova-3 |
| German | `de` | Nova-2, Nova-3 |
| Hindi | `hi` | Limited |

## Troubleshooting

### High Word Error Rate

1. Check audio quality (sample rate, encoding)
2. Enable noise reduction on client side
3. Use `nova-3` model for best accuracy

### Delayed Transcription

1. Reduce `endpointing` value
2. Enable `interim_results`
3. Check network latency to Deepgram

### Missing Words

1. Check for audio clipping
2. Verify VAD isn't cutting off speech
3. Increase `utterance_end_ms`

## Pricing

Deepgram STT is included in the Edesy per-minute price (from ₹4/min; PAYG ₹6/min). If you bring your own Deepgram key, Deepgram bills you directly.

## Next Steps

- [Google Chirp](https://edesy.in/docs/voice-agent/stt/google) - Multi-language alternative
- [TTS Providers](https://edesy.in/docs/voice-agent/tts) - Text-to-Speech options
- [Latency Optimization](https://edesy.in/docs/voice-agent/advanced/latency) - Further improvements
