Skip to content

Feedback: guides-v2_to_v3_migration

Original URL: https://www.assemblyai.com/docs/guides/v2_to_v3_migration
Category: guides
Generated: 05/08/2025, 4:34:24 pm


Generated: 05/08/2025, 4:34:23 pm

Technical Documentation Analysis & Improvement Recommendations

Section titled “Technical Documentation Analysis & Improvement Recommendations”

This migration guide is comprehensive but suffers from structural issues, missing critical information, and potential user friction points. Here’s my detailed analysis:

Problem: The complete v3 code is presented first, overwhelming users before they understand what needs to change.

Solution: Restructure as follows:

# Migrating from Streaming v2 to Streaming v3 (Python)
## Quick Start
- [Prerequisites](#prerequisites)
- [Migration Checklist](#migration-checklist)
- [Step-by-Step Guide](#step-by-step-guide)
- [Complete Example](#complete-example)
- [Troubleshooting](#troubleshooting)
## What's New in v3
[Brief overview of key changes and benefits]
## Prerequisites
[Requirements and setup]
## Migration Checklist
[High-level action items]
## Step-by-Step Guide
[Detailed migration steps]
## Complete Working Example
[Full v3 implementation]

Problem: Users don’t know what they need before starting.

Add:

## Prerequisites
### Required Dependencies
```bash
pip install pyaudio websocket-client
  • Python 3.7+
  • Valid AssemblyAI API key with streaming access
  • Audio input device (microphone)
  • Backup your existing v2 implementation
  • Test your API key has v3 streaming access
  • Verify microphone permissions
### 3. **Inadequate Error Scenarios Coverage**
**Problem**: Limited troubleshooting information for common migration issues.
**Add comprehensive troubleshooting section**:
```markdown
## Troubleshooting
### Connection Issues
| Error | Cause | Solution |
|-------|-------|----------|
| `401 Unauthorized` | Invalid API key | Verify key format: no "Bearer" prefix needed |
| `Connection refused` | Wrong endpoint | Ensure using `streaming.assemblyai.com` |
| `Unsupported sample rate` | Invalid audio config | Use supported rates: 8000, 16000, 22050, 44100 |
### Audio Issues
- **No audio detected**: Check microphone permissions and device availability
- **Poor transcription quality**: Verify sample rate matches your audio source
- **High latency**: Reduce FRAMES_PER_BUFFER (minimum 160 frames)
### Code Migration Issues
- **Import errors**: Run `pip install -r requirements.txt`
- **Thread issues**: Ensure Python 3.7+ for proper threading support

Add critical timing information:

## Migration Timeline
- **v2 Deprecation**: [DATE]
- **v2 End-of-life**: [DATE]
- **Recommended migration completion**: [DATE]
> ⚠️ **Important**: v2 will stop working on [DATE]. Plan your migration accordingly.
## Pricing Changes
- v3 billing is based on session duration, not audio duration
- Sessions auto-expire after [TIME] if not properly terminated
- **Action Required**: Implement proper session termination to avoid unexpected charges
## v2 vs v3 Feature Comparison
| Feature | v2 | v3 | Migration Impact |
|---------|----|----|------------------|
| Latency | ~200ms | ~50ms | Update buffer size |
| Message Types | 3 types | 3 types (renamed) | Update parsing logic |
| Error Handling | Basic | Enhanced | Add new error handlers |
| Session Management | Auto | Manual | Add termination logic |
| Supported Languages | [LIST] | [LIST] | Check compatibility |

For each migration step, show before/after more clearly:

### Step 1: Update Connection Parameters
#### v2 Implementation
```python
# Simple connection string
endpoint = f'wss://api.assemblyai.com/v2/realtime/ws?sample_rate={SAMPLE_RATE}'
# Structured parameters with additional options
CONNECTION_PARAMS = {
"sample_rate": 16000,
"format_turns": True, # New: Enhanced formatting
# "enable_extra_session_information": True, # Optional
}
endpoint = f"wss://streaming.assemblyai.com/v3/ws?{urlencode(CONNECTION_PARAMS)}"
  • More flexible configuration options
  • Better parameter validation
  • Support for future feature flags
### 2. **Add Minimal Migration Example**
```markdown
## Quick Migration (Minimal Changes)
If you need a quick migration with minimal code changes:
```python
# 1. Change endpoint
OLD_ENDPOINT = 'wss://api.assemblyai.com/v2/realtime/ws?sample_rate=16000'
NEW_ENDPOINT = 'wss://streaming.assemblyai.com/v3/ws?sample_rate=16000'
# 2. Update message handling
def on_message(ws, message):
data = json.loads(message)
msg_type = data.get('type') # Changed from 'message_type'
if msg_type == "Begin": # Changed from "SessionBegins"
print(f"Session: {data.get('id')}") # Changed from 'session_id'
elif msg_type == "Turn": # Replaces both Partial and Final
print(data.get('transcript', '')) # Changed from 'text'
# 3. Add termination handling (REQUIRED for proper billing)
def send_termination():
terminate_msg = {"type": "Terminate"}
ws.send(json.dumps(terminate_msg))

⚠️ Note: This minimal example lacks proper error handling. Use the complete example for production.

## 🎯 User Experience Improvements
### 1. **Add Progress Indicators**
```markdown
## Migration Progress Tracker
**Estimated time**: 30-45 minutes
- [ ] **Step 1** (5 min): Update endpoints and dependencies
- [ ] **Step 2** (10 min): Modify message handling
- [ ] **Step 3** (15 min): Implement proper resource management
- [ ] **Step 4** (10 min): Add termination handling
- [ ] **Step 5** (5 min): Test and validate
**Checkpoint**: After each step, test basic connectivity before proceeding.
## Validate Your Migration
### Test Script
```python
# Quick validation script
def validate_v3_connection():
"""Test v3 connectivity without full implementation"""
# ... validation code ...
if __name__ == "__main__":
validate_v3_connection()
  • Connection success: “Session began: ID=…”
  • Audio processing: Real-time transcript updates
  • Clean shutdown: “Session Terminated: …”
## ⚡ Performance & Security Notes
### Add Missing Sections:
```markdown
## Performance Considerations
- **Buffer Size**: Start with 800 frames (50ms), adjust based on your latency requirements
- **Threading**: v3 requires proper thread management for optimal performance
- **Memory Usage**: Implement proper cleanup to prevent memory leaks
## Security Best Practices
- **API Key Storage**: Use environment variables, never hardcode keys
- **Error Logging**: Avoid logging sensitive audio data or API keys
- **Network Security**: Consider implementing retry logic with exponential backoff
  1. Restructure the entire document with user-friendly navigation
  2. Add prerequisite and setup sections before diving into code
  3. Include cost/billing implications prominently
  4. Provide both minimal and complete migration paths 5